Coverage Report

Created: 2025-07-08 11:15

/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
29
#define STRING_SIZE_SIZE 4
364
365
35.9M
#define DOT_DEBUG ".debug"
366
35.8M
#define DOT_ZDEBUG  ".zdebug"
367
5.03M
#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
368
5.03M
#define GNU_LINKONCE_WT ".gnu.linkonce.wt."
369
92
#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
7.22M
{
411
7.22M
  bfd_coff_long_section_names (abfd) = enable;
412
7.22M
  return true;
413
7.22M
}
pei-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
302k
{
411
302k
  bfd_coff_long_section_names (abfd) = enable;
412
302k
  return true;
413
302k
}
pe-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
646k
{
411
646k
  bfd_coff_long_section_names (abfd) = enable;
412
646k
  return true;
413
646k
}
pei-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
290k
{
411
290k
  bfd_coff_long_section_names (abfd) = enable;
412
290k
  return true;
413
290k
}
pe-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
198k
{
411
198k
  bfd_coff_long_section_names (abfd) = enable;
412
198k
  return true;
413
198k
}
pei-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
258k
{
411
258k
  bfd_coff_long_section_names (abfd) = enable;
412
258k
  return true;
413
258k
}
pei-ia64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
231k
{
411
231k
  bfd_coff_long_section_names (abfd) = enable;
412
231k
  return true;
413
231k
}
pei-loongarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
230k
{
411
230k
  bfd_coff_long_section_names (abfd) = enable;
412
230k
  return true;
413
230k
}
pei-riscv64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
211k
{
411
211k
  bfd_coff_long_section_names (abfd) = enable;
412
211k
  return true;
413
211k
}
coff-go32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
2.88M
{
411
2.88M
  bfd_coff_long_section_names (abfd) = enable;
412
2.88M
  return true;
413
2.88M
}
coff-stgo32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
515k
{
411
515k
  bfd_coff_long_section_names (abfd) = enable;
412
515k
  return true;
413
515k
}
pe-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
58.1k
{
411
58.1k
  bfd_coff_long_section_names (abfd) = enable;
412
58.1k
  return true;
413
58.1k
}
pe-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
58.1k
{
411
58.1k
  bfd_coff_long_section_names (abfd) = enable;
412
58.1k
  return true;
413
58.1k
}
pe-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
141k
{
411
141k
  bfd_coff_long_section_names (abfd) = enable;
412
141k
  return true;
413
141k
}
pe-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
170k
{
411
170k
  bfd_coff_long_section_names (abfd) = enable;
412
170k
  return true;
413
170k
}
pe-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
120k
{
411
120k
  bfd_coff_long_section_names (abfd) = enable;
412
120k
  return true;
413
120k
}
pei-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
210k
{
411
210k
  bfd_coff_long_section_names (abfd) = enable;
412
210k
  return true;
413
210k
}
pei-arm.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-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
200k
{
411
200k
  bfd_coff_long_section_names (abfd) = enable;
412
200k
  return true;
413
200k
}
pei-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
220k
{
411
220k
  bfd_coff_long_section_names (abfd) = enable;
412
220k
  return true;
413
220k
}
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
77.5M
{
419
77.5M
  return false;
420
77.5M
}
coff-x86_64.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
10.9M
{
419
10.9M
  return false;
420
10.9M
}
coff64-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
2.00M
{
419
2.00M
  return false;
420
2.00M
}
cf-i386lynx.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
4.37M
{
419
4.37M
  return false;
420
4.37M
}
coff-i386.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
3.87M
{
419
3.87M
  return false;
420
3.87M
}
coff-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
22.3M
{
419
22.3M
  return false;
420
22.3M
}
coff-sh.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
6.73M
{
419
6.73M
  return false;
420
6.73M
}
coff-tic30.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
4.73M
{
419
4.73M
  return false;
420
4.73M
}
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
7.89M
{
419
7.89M
  return false;
420
7.89M
}
coff-z80.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
1.20M
{
419
1.20M
  return false;
420
1.20M
}
coff-z8k.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
13.4M
{
419
13.4M
  return false;
420
13.4M
}
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
3
{
447
3
  long styp_flags = 0;
448
449
3
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
3
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
3
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
#ifdef _COMMENT
461
    }
462
3
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
#endif /* _COMMENT */
466
#ifdef _LIB
467
    }
468
3
  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
3
  else if (startswith (sec_name, DOT_DEBUG)
480
3
     || 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
3
  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
1
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
1
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
1
  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
1
  else if (sec_flags & SEC_LOAD)
554
0
    {
555
0
      styp_flags = STYP_TEXT;
556
0
    }
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
3
#ifdef STYP_NOLOAD
573
3
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
3
#endif
576
577
3
  return styp_flags;
578
3
}
coff-x86_64.c:sec_to_styp_flags
Line
Count
Source
446
3
{
447
3
  long styp_flags = 0;
448
449
3
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
3
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
3
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
0
#ifdef _COMMENT
461
0
    }
462
3
  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
3
  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
3
  else if (startswith (sec_name, DOT_DEBUG)
480
3
     || 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
3
  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
1
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
1
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
1
  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
1
  else if (sec_flags & SEC_LOAD)
554
0
    {
555
0
      styp_flags = STYP_TEXT;
556
0
    }
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
3
#ifdef STYP_NOLOAD
573
3
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
3
#endif
576
577
3
  return styp_flags;
578
3
}
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
92
{
591
92
  long styp_flags = 0;
592
92
  bool is_dbg = false;
593
594
92
  if (startswith (sec_name, DOT_DEBUG)
595
92
      || startswith (sec_name, DOT_ZDEBUG)
596
92
#ifdef COFF_LONG_SECTION_NAMES
597
92
      || startswith (sec_name, GNU_LINKONCE_WI)
598
92
      || startswith (sec_name, GNU_LINKONCE_WT)
599
92
#endif
600
92
      || startswith (sec_name, ".stab"))
601
24
    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
92
  if (is_dbg)
613
24
    {
614
24
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
24
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
24
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
24
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
24
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
92
  if ((sec_flags & SEC_CODE) != 0)
624
6
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
92
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
68
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
92
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
5
    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
92
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
26
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
92
  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
92
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
75
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
92
  if ((sec_flags & SEC_READONLY) == 0)
663
19
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
92
  if (sec_flags & SEC_CODE)
665
6
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
92
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
92
  return styp_flags;
670
92
}
pei-i386.c:sec_to_styp_flags
Line
Count
Source
590
40
{
591
40
  long styp_flags = 0;
592
40
  bool is_dbg = false;
593
594
40
  if (startswith (sec_name, DOT_DEBUG)
595
40
      || startswith (sec_name, DOT_ZDEBUG)
596
40
#ifdef COFF_LONG_SECTION_NAMES
597
40
      || startswith (sec_name, GNU_LINKONCE_WI)
598
40
      || startswith (sec_name, GNU_LINKONCE_WT)
599
40
#endif
600
40
      || 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
40
  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
40
  if ((sec_flags & SEC_CODE) != 0)
624
3
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
40
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
27
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
40
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
3
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
40
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
4
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
40
  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
40
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
31
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
40
  if ((sec_flags & SEC_READONLY) == 0)
663
13
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
40
  if (sec_flags & SEC_CODE)
665
3
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
40
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
40
  return styp_flags;
670
40
}
Unexecuted instantiation: pe-x86_64.c:sec_to_styp_flags
pei-x86_64.c:sec_to_styp_flags
Line
Count
Source
590
34
{
591
34
  long styp_flags = 0;
592
34
  bool is_dbg = false;
593
594
34
  if (startswith (sec_name, DOT_DEBUG)
595
34
      || startswith (sec_name, DOT_ZDEBUG)
596
34
#ifdef COFF_LONG_SECTION_NAMES
597
34
      || startswith (sec_name, GNU_LINKONCE_WI)
598
34
      || startswith (sec_name, GNU_LINKONCE_WT)
599
34
#endif
600
34
      || startswith (sec_name, ".stab"))
601
12
    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
34
  if (is_dbg)
613
12
    {
614
12
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
12
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
12
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
12
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
12
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
34
  if ((sec_flags & SEC_CODE) != 0)
624
3
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
34
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
31
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
34
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
2
    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
34
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
12
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
34
  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
34
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
34
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
34
  if ((sec_flags & SEC_READONLY) == 0)
663
6
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
34
  if (sec_flags & SEC_CODE)
665
3
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
34
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
34
  return styp_flags;
670
34
}
Unexecuted instantiation: pe-aarch64.c:sec_to_styp_flags
Unexecuted instantiation: pei-aarch64.c:sec_to_styp_flags
Unexecuted instantiation: pei-ia64.c:sec_to_styp_flags
pei-loongarch64.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
}
pei-riscv64.c:sec_to_styp_flags
Line
Count
Source
590
14
{
591
14
  long styp_flags = 0;
592
14
  bool is_dbg = false;
593
594
14
  if (startswith (sec_name, DOT_DEBUG)
595
14
      || startswith (sec_name, DOT_ZDEBUG)
596
14
#ifdef COFF_LONG_SECTION_NAMES
597
14
      || startswith (sec_name, GNU_LINKONCE_WI)
598
14
      || startswith (sec_name, GNU_LINKONCE_WT)
599
14
#endif
600
14
      || startswith (sec_name, ".stab"))
601
6
    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
14
  if (is_dbg)
613
6
    {
614
6
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
6
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
6
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
6
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
6
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
14
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
14
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
6
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
14
  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
14
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
6
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
14
  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
14
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
6
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
14
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
14
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
14
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
14
  return styp_flags;
670
14
}
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
pei-arm-wince.c:sec_to_styp_flags
Line
Count
Source
590
2
{
591
2
  long styp_flags = 0;
592
2
  bool is_dbg = false;
593
594
2
  if (startswith (sec_name, DOT_DEBUG)
595
2
      || startswith (sec_name, DOT_ZDEBUG)
596
2
#ifdef COFF_LONG_SECTION_NAMES
597
2
      || startswith (sec_name, GNU_LINKONCE_WI)
598
2
      || startswith (sec_name, GNU_LINKONCE_WT)
599
2
#endif
600
2
      || startswith (sec_name, ".stab"))
601
2
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
2
  if (is_dbg)
613
2
    {
614
2
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
2
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
2
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
2
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
2
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
2
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
2
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
2
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
2
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
2
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
2
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
2
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
2
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
2
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
2
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
2
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
2
  return styp_flags;
670
2
}
Unexecuted instantiation: pei-arm.c:sec_to_styp_flags
Unexecuted instantiation: pei-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pei-sh.c:sec_to_styp_flags
671
672
#endif /* COFF_WITH_PE */
673
674
/* Return a word with SEC_* flags set to represent the incoming STYP_*
675
   flags (from scnhdr.s_flags).  The inverse of this function is
676
   sec_to_styp_flags().  NOTE: If you add to/change this routine, you
677
   should probably mirror the changes in sec_to_styp_flags().  */
678
679
#ifndef COFF_WITH_PE
680
681
static bool
682
styp_to_sec_flags (bfd *abfd,
683
       void * hdr,
684
       const char *name,
685
       asection *section ATTRIBUTE_UNUSED,
686
       flagword *flags_ptr)
687
80.8M
{
688
80.8M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
80.8M
  unsigned long styp_flags = internal_s->s_flags;
690
80.8M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
7.89M
  if (styp_flags & STYP_BLOCK)
694
2.31M
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
7.89M
  if (styp_flags & STYP_CLINK)
699
2.44M
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
80.8M
#ifdef STYP_NOLOAD
703
80.8M
  if (styp_flags & STYP_NOLOAD)
704
24.3M
    sec_flags |= SEC_NEVER_LOAD;
705
80.8M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
80.8M
  if (styp_flags & STYP_TEXT)
710
29.9M
    {
711
29.9M
      if (sec_flags & SEC_NEVER_LOAD)
712
15.9M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
14.0M
      else
714
14.0M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
29.9M
    }
716
50.8M
  else if (styp_flags & STYP_DATA)
717
6.57M
    {
718
6.57M
      if (sec_flags & SEC_NEVER_LOAD)
719
3.60M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
2.96M
      else
721
2.96M
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
6.57M
    }
723
44.2M
  else if (styp_flags & STYP_BSS)
724
2.80M
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
864k
      if (sec_flags & SEC_NEVER_LOAD)
727
334k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
529k
      else
729
529k
#endif
730
2.47M
  sec_flags |= SEC_ALLOC;
731
2.80M
    }
732
41.4M
  else if (styp_flags & STYP_INFO)
733
5.54M
    {
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
1.69M
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
5.54M
    }
744
35.9M
  else if (styp_flags & STYP_PAD)
745
1.97M
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
10.5M
  else if (styp_flags & STYP_TDATA)
748
582k
    {
749
582k
      if (sec_flags & SEC_NEVER_LOAD)
750
51.5k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
530k
      else
752
530k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
582k
    }
754
9.95M
  else if (styp_flags & STYP_TBSS)
755
242k
    {
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
242k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
242k
    }
763
9.71M
  else if (styp_flags & STYP_EXCEPT)
764
442k
    sec_flags |= SEC_LOAD;
765
9.26M
  else if (styp_flags & STYP_LOADER)
766
126k
    sec_flags |= SEC_LOAD;
767
9.14M
  else if (styp_flags & STYP_TYPCHK)
768
58.2k
    sec_flags |= SEC_LOAD;
769
9.08M
  else if (styp_flags & STYP_DWARF)
770
90.7k
    sec_flags |= SEC_DEBUGGING;
771
8.99M
#endif
772
32.4M
  else if (strcmp (name, _TEXT) == 0)
773
77.4k
    {
774
77.4k
      if (sec_flags & SEC_NEVER_LOAD)
775
25.9k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
51.5k
      else
777
51.5k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
77.4k
    }
779
32.3M
  else if (strcmp (name, _DATA) == 0)
780
119k
    {
781
119k
      if (sec_flags & SEC_NEVER_LOAD)
782
25.7k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
93.6k
      else
784
93.6k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
119k
    }
786
32.2M
  else if (strcmp (name, _BSS) == 0)
787
57.2k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
21.4k
      if (sec_flags & SEC_NEVER_LOAD)
790
7.51k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
13.9k
      else
792
13.9k
#endif
793
49.7k
  sec_flags |= SEC_ALLOC;
794
57.2k
    }
795
32.1M
  else if (startswith (name, DOT_DEBUG)
796
32.1M
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
19.9M
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
1.36M
     || startswith (name, GNU_LINKONCE_WI)
802
1.36M
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
32.1M
     || startswith (name, ".stab"))
805
232k
    {
806
#ifdef COFF_PAGE_SIZE
807
76.0k
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
232k
    }
810
#ifdef _LIB
811
19.9M
  else if (strcmp (name, _LIB) == 0)
812
20.2k
    ;
813
19.8M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
19.8M
  else
819
31.9M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
80.8M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
80.8M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
8.54M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
80.8M
#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
80.8M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
80.8M
      && (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
3.36M
  if (startswith (name, ".gnu.linkonce"))
844
2.06k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
80.8M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
80.8M
  * flags_ptr = sec_flags;
851
80.8M
  return true;
852
80.8M
}
coff-x86_64.c:styp_to_sec_flags
Line
Count
Source
687
10.9M
{
688
10.9M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
10.9M
  unsigned long styp_flags = internal_s->s_flags;
690
10.9M
  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.9M
#ifdef STYP_NOLOAD
703
10.9M
  if (styp_flags & STYP_NOLOAD)
704
3.35M
    sec_flags |= SEC_NEVER_LOAD;
705
10.9M
#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.9M
  if (styp_flags & STYP_TEXT)
710
3.92M
    {
711
3.92M
      if (sec_flags & SEC_NEVER_LOAD)
712
2.18M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.74M
      else
714
1.74M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.92M
    }
716
6.97M
  else if (styp_flags & STYP_DATA)
717
822k
    {
718
822k
      if (sec_flags & SEC_NEVER_LOAD)
719
430k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
391k
      else
721
391k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
822k
    }
723
6.14M
  else if (styp_flags & STYP_BSS)
724
387k
    {
725
387k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
387k
      if (sec_flags & SEC_NEVER_LOAD)
727
149k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
237k
      else
729
237k
#endif
730
237k
  sec_flags |= SEC_ALLOC;
731
387k
    }
732
5.76M
  else if (styp_flags & STYP_INFO)
733
819k
    {
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
819k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
819k
      sec_flags |= SEC_DEBUGGING;
742
819k
#endif
743
819k
    }
744
4.94M
  else if (styp_flags & STYP_PAD)
745
340k
    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.60M
  else if (strcmp (name, _TEXT) == 0)
773
9.60k
    {
774
9.60k
      if (sec_flags & SEC_NEVER_LOAD)
775
4.70k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.89k
      else
777
4.89k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
9.60k
    }
779
4.59M
  else if (strcmp (name, _DATA) == 0)
780
13.9k
    {
781
13.9k
      if (sec_flags & SEC_NEVER_LOAD)
782
3.51k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
10.3k
      else
784
10.3k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
13.9k
    }
786
4.57M
  else if (strcmp (name, _BSS) == 0)
787
11.2k
    {
788
11.2k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
11.2k
      if (sec_flags & SEC_NEVER_LOAD)
790
4.22k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
7.00k
      else
792
7.00k
#endif
793
7.00k
  sec_flags |= SEC_ALLOC;
794
11.2k
    }
795
4.56M
  else if (startswith (name, DOT_DEBUG)
796
4.56M
     || startswith (name, DOT_ZDEBUG)
797
4.56M
#ifdef _COMMENT
798
4.56M
     || strcmp (name, _COMMENT) == 0
799
4.56M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
4.56M
     || startswith (name, ".stab"))
805
33.4k
    {
806
33.4k
#ifdef COFF_PAGE_SIZE
807
33.4k
      sec_flags |= SEC_DEBUGGING;
808
33.4k
#endif
809
33.4k
    }
810
4.53M
#ifdef _LIB
811
4.53M
  else if (strcmp (name, _LIB) == 0)
812
4.04k
    ;
813
4.52M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
4.52M
  else
819
4.52M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
10.9M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
10.9M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.05M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
10.9M
#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.9M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
10.9M
      && (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.9M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
10.9M
  * flags_ptr = sec_flags;
851
10.9M
  return true;
852
10.9M
}
coff64-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
2.00M
{
688
2.00M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
2.00M
  unsigned long styp_flags = internal_s->s_flags;
690
2.00M
  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
2.00M
#ifdef STYP_NOLOAD
703
2.00M
  if (styp_flags & STYP_NOLOAD)
704
617k
    sec_flags |= SEC_NEVER_LOAD;
705
2.00M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
2.00M
  if (styp_flags & STYP_TEXT)
710
704k
    {
711
704k
      if (sec_flags & SEC_NEVER_LOAD)
712
403k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
301k
      else
714
301k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
704k
    }
716
1.30M
  else if (styp_flags & STYP_DATA)
717
150k
    {
718
150k
      if (sec_flags & SEC_NEVER_LOAD)
719
89.3k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
60.8k
      else
721
60.8k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
150k
    }
723
1.15M
  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.08M
  else if (styp_flags & STYP_INFO)
733
129k
    {
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
129k
    }
744
954k
  else if (styp_flags & STYP_PAD)
745
62.6k
    sec_flags = 0;
746
891k
#ifdef RS6000COFF_C
747
891k
  else if (styp_flags & STYP_TDATA)
748
59.2k
    {
749
59.2k
      if (sec_flags & SEC_NEVER_LOAD)
750
8.59k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
50.6k
      else
752
50.6k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
59.2k
    }
754
832k
  else if (styp_flags & STYP_TBSS)
755
27.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
27.6k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
27.6k
    }
763
804k
  else if (styp_flags & STYP_EXCEPT)
764
48.7k
    sec_flags |= SEC_LOAD;
765
755k
  else if (styp_flags & STYP_LOADER)
766
15.9k
    sec_flags |= SEC_LOAD;
767
739k
  else if (styp_flags & STYP_TYPCHK)
768
8.02k
    sec_flags |= SEC_LOAD;
769
731k
  else if (styp_flags & STYP_DWARF)
770
10.4k
    sec_flags |= SEC_DEBUGGING;
771
721k
#endif
772
721k
  else if (strcmp (name, _TEXT) == 0)
773
4.05k
    {
774
4.05k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.08k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.96k
      else
777
2.96k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.05k
    }
779
717k
  else if (strcmp (name, _DATA) == 0)
780
6.94k
    {
781
6.94k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.10k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.83k
      else
784
4.83k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
6.94k
    }
786
710k
  else if (strcmp (name, _BSS) == 0)
787
3.00k
    {
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
3.00k
  sec_flags |= SEC_ALLOC;
794
3.00k
    }
795
707k
  else if (startswith (name, DOT_DEBUG)
796
707k
     || 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
707k
     || startswith (name, ".stab"))
805
10.6k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
10.6k
    }
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
696k
  else
819
696k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
2.00M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
2.00M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
230k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
2.00M
#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
2.00M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
2.00M
      && (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
2.00M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
2.00M
  * flags_ptr = sec_flags;
851
2.00M
  return true;
852
2.00M
}
cf-i386lynx.c:styp_to_sec_flags
Line
Count
Source
687
4.37M
{
688
4.37M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
4.37M
  unsigned long styp_flags = internal_s->s_flags;
690
4.37M
  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
4.37M
#ifdef STYP_NOLOAD
703
4.37M
  if (styp_flags & STYP_NOLOAD)
704
1.30M
    sec_flags |= SEC_NEVER_LOAD;
705
4.37M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
4.37M
  if (styp_flags & STYP_TEXT)
710
1.56M
    {
711
1.56M
      if (sec_flags & SEC_NEVER_LOAD)
712
826k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
740k
      else
714
740k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.56M
    }
716
2.80M
  else if (styp_flags & STYP_DATA)
717
393k
    {
718
393k
      if (sec_flags & SEC_NEVER_LOAD)
719
192k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
201k
      else
721
201k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
393k
    }
723
2.41M
  else if (styp_flags & STYP_BSS)
724
182k
    {
725
182k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
182k
      if (sec_flags & SEC_NEVER_LOAD)
727
72.0k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
110k
      else
729
110k
#endif
730
110k
  sec_flags |= SEC_ALLOC;
731
182k
    }
732
2.23M
  else if (styp_flags & STYP_INFO)
733
329k
    {
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
329k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
329k
      sec_flags |= SEC_DEBUGGING;
742
329k
#endif
743
329k
    }
744
1.90M
  else if (styp_flags & STYP_PAD)
745
111k
    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
1.78M
  else if (strcmp (name, _TEXT) == 0)
773
3.60k
    {
774
3.60k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.07k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.53k
      else
777
2.53k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
3.60k
    }
779
1.78M
  else if (strcmp (name, _DATA) == 0)
780
6.92k
    {
781
6.92k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.46k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
5.45k
      else
784
5.45k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
6.92k
    }
786
1.77M
  else if (strcmp (name, _BSS) == 0)
787
3.58k
    {
788
3.58k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3.58k
      if (sec_flags & SEC_NEVER_LOAD)
790
1.18k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2.40k
      else
792
2.40k
#endif
793
2.40k
  sec_flags |= SEC_ALLOC;
794
3.58k
    }
795
1.77M
  else if (startswith (name, DOT_DEBUG)
796
1.77M
     || startswith (name, DOT_ZDEBUG)
797
1.77M
#ifdef _COMMENT
798
1.77M
     || strcmp (name, _COMMENT) == 0
799
1.77M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
1.77M
     || startswith (name, ".stab"))
805
15.0k
    {
806
15.0k
#ifdef COFF_PAGE_SIZE
807
15.0k
      sec_flags |= SEC_DEBUGGING;
808
15.0k
#endif
809
15.0k
    }
810
1.76M
#ifdef _LIB
811
1.76M
  else if (strcmp (name, _LIB) == 0)
812
1.25k
    ;
813
1.75M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.75M
  else
819
1.75M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
4.37M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
4.37M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
467k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
4.37M
#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
4.37M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
4.37M
      && (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
4.37M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
4.37M
  * flags_ptr = sec_flags;
851
4.37M
  return true;
852
4.37M
}
coff-go32.c:styp_to_sec_flags
Line
Count
Source
687
2.85M
{
688
2.85M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
2.85M
  unsigned long styp_flags = internal_s->s_flags;
690
2.85M
  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
2.85M
#ifdef STYP_NOLOAD
703
2.85M
  if (styp_flags & STYP_NOLOAD)
704
811k
    sec_flags |= SEC_NEVER_LOAD;
705
2.85M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
2.85M
  if (styp_flags & STYP_TEXT)
710
986k
    {
711
986k
      if (sec_flags & SEC_NEVER_LOAD)
712
516k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
470k
      else
714
470k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
986k
    }
716
1.86M
  else if (styp_flags & STYP_DATA)
717
239k
    {
718
239k
      if (sec_flags & SEC_NEVER_LOAD)
719
114k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
124k
      else
721
124k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
239k
    }
723
1.62M
  else if (styp_flags & STYP_BSS)
724
111k
    {
725
111k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
111k
      if (sec_flags & SEC_NEVER_LOAD)
727
40.7k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
70.4k
      else
729
70.4k
#endif
730
70.4k
  sec_flags |= SEC_ALLOC;
731
111k
    }
732
1.51M
  else if (styp_flags & STYP_INFO)
733
212k
    {
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
212k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
212k
      sec_flags |= SEC_DEBUGGING;
742
212k
#endif
743
212k
    }
744
1.30M
  else if (styp_flags & STYP_PAD)
745
74.3k
    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
1.22M
  else if (strcmp (name, _TEXT) == 0)
773
2.64k
    {
774
2.64k
      if (sec_flags & SEC_NEVER_LOAD)
775
897
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
1.74k
      else
777
1.74k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
2.64k
    }
779
1.22M
  else if (strcmp (name, _DATA) == 0)
780
4.32k
    {
781
4.32k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.16k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
3.16k
      else
784
3.16k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
4.32k
    }
786
1.21M
  else if (strcmp (name, _BSS) == 0)
787
3.10k
    {
788
3.10k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3.10k
      if (sec_flags & SEC_NEVER_LOAD)
790
932
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2.16k
      else
792
2.16k
#endif
793
2.16k
  sec_flags |= SEC_ALLOC;
794
3.10k
    }
795
1.21M
  else if (startswith (name, DOT_DEBUG)
796
1.21M
     || startswith (name, DOT_ZDEBUG)
797
1.21M
#ifdef _COMMENT
798
1.21M
     || strcmp (name, _COMMENT) == 0
799
1.21M
#endif
800
1.21M
#ifdef COFF_LONG_SECTION_NAMES
801
1.21M
     || startswith (name, GNU_LINKONCE_WI)
802
1.21M
     || startswith (name, GNU_LINKONCE_WT)
803
1.21M
#endif
804
1.21M
     || startswith (name, ".stab"))
805
12.3k
    {
806
12.3k
#ifdef COFF_PAGE_SIZE
807
12.3k
      sec_flags |= SEC_DEBUGGING;
808
12.3k
#endif
809
12.3k
    }
810
1.20M
#ifdef _LIB
811
1.20M
  else if (strcmp (name, _LIB) == 0)
812
1.08k
    ;
813
1.20M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.20M
  else
819
1.20M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
2.85M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
2.85M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
277k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
2.85M
#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
2.85M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
2.85M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
2.85M
#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
2.85M
  if (startswith (name, ".gnu.linkonce"))
844
1.94k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
2.85M
#endif
846
847
2.85M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
2.85M
  * flags_ptr = sec_flags;
851
2.85M
  return true;
852
2.85M
}
coff-i386.c:styp_to_sec_flags
Line
Count
Source
687
3.87M
{
688
3.87M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
3.87M
  unsigned long styp_flags = internal_s->s_flags;
690
3.87M
  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.87M
#ifdef STYP_NOLOAD
703
3.87M
  if (styp_flags & STYP_NOLOAD)
704
1.12M
    sec_flags |= SEC_NEVER_LOAD;
705
3.87M
#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.87M
  if (styp_flags & STYP_TEXT)
710
1.37M
    {
711
1.37M
      if (sec_flags & SEC_NEVER_LOAD)
712
727k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
645k
      else
714
645k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.37M
    }
716
2.50M
  else if (styp_flags & STYP_DATA)
717
325k
    {
718
325k
      if (sec_flags & SEC_NEVER_LOAD)
719
158k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
167k
      else
721
167k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
325k
    }
723
2.17M
  else if (styp_flags & STYP_BSS)
724
147k
    {
725
147k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
147k
      if (sec_flags & SEC_NEVER_LOAD)
727
56.8k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
90.9k
      else
729
90.9k
#endif
730
90.9k
  sec_flags |= SEC_ALLOC;
731
147k
    }
732
2.03M
  else if (styp_flags & STYP_INFO)
733
294k
    {
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
294k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
294k
      sec_flags |= SEC_DEBUGGING;
742
294k
#endif
743
294k
    }
744
1.73M
  else if (styp_flags & STYP_PAD)
745
96.2k
    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
1.64M
  else if (strcmp (name, _TEXT) == 0)
773
2.97k
    {
774
2.97k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.00k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
1.96k
      else
777
1.96k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
2.97k
    }
779
1.63M
  else if (strcmp (name, _DATA) == 0)
780
6.33k
    {
781
6.33k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.39k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.93k
      else
784
4.93k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
6.33k
    }
786
1.63M
  else if (strcmp (name, _BSS) == 0)
787
3.43k
    {
788
3.43k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3.43k
      if (sec_flags & SEC_NEVER_LOAD)
790
1.14k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2.29k
      else
792
2.29k
#endif
793
2.29k
  sec_flags |= SEC_ALLOC;
794
3.43k
    }
795
1.62M
  else if (startswith (name, DOT_DEBUG)
796
1.62M
     || startswith (name, DOT_ZDEBUG)
797
1.62M
#ifdef _COMMENT
798
1.62M
     || strcmp (name, _COMMENT) == 0
799
1.62M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
1.62M
     || startswith (name, ".stab"))
805
12.9k
    {
806
12.9k
#ifdef COFF_PAGE_SIZE
807
12.9k
      sec_flags |= SEC_DEBUGGING;
808
12.9k
#endif
809
12.9k
    }
810
1.61M
#ifdef _LIB
811
1.61M
  else if (strcmp (name, _LIB) == 0)
812
1.09k
    ;
813
1.61M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.61M
  else
819
1.61M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
3.87M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
3.87M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
386k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
3.87M
#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.87M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
3.87M
      && (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.87M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
3.87M
  * flags_ptr = sec_flags;
851
3.87M
  return true;
852
3.87M
}
coff-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
22.3M
{
688
22.3M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
22.3M
  unsigned long styp_flags = internal_s->s_flags;
690
22.3M
  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
22.3M
#ifdef STYP_NOLOAD
703
22.3M
  if (styp_flags & STYP_NOLOAD)
704
6.57M
    sec_flags |= SEC_NEVER_LOAD;
705
22.3M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
22.3M
  if (styp_flags & STYP_TEXT)
710
8.16M
    {
711
8.16M
      if (sec_flags & SEC_NEVER_LOAD)
712
4.25M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
3.91M
      else
714
3.91M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
8.16M
    }
716
14.2M
  else if (styp_flags & STYP_DATA)
717
1.87M
    {
718
1.87M
      if (sec_flags & SEC_NEVER_LOAD)
719
1.07M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
798k
      else
721
798k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.87M
    }
723
12.3M
  else if (styp_flags & STYP_BSS)
724
808k
    {
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
808k
  sec_flags |= SEC_ALLOC;
731
808k
    }
732
11.5M
  else if (styp_flags & STYP_INFO)
733
1.39M
    {
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.39M
    }
744
10.1M
  else if (styp_flags & STYP_PAD)
745
486k
    sec_flags = 0;
746
9.64M
#ifdef RS6000COFF_C
747
9.64M
  else if (styp_flags & STYP_TDATA)
748
523k
    {
749
523k
      if (sec_flags & SEC_NEVER_LOAD)
750
42.9k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
480k
      else
752
480k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
523k
    }
754
9.12M
  else if (styp_flags & STYP_TBSS)
755
214k
    {
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
214k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
214k
    }
763
8.90M
  else if (styp_flags & STYP_EXCEPT)
764
393k
    sec_flags |= SEC_LOAD;
765
8.51M
  else if (styp_flags & STYP_LOADER)
766
110k
    sec_flags |= SEC_LOAD;
767
8.40M
  else if (styp_flags & STYP_TYPCHK)
768
50.2k
    sec_flags |= SEC_LOAD;
769
8.35M
  else if (styp_flags & STYP_DWARF)
770
80.3k
    sec_flags |= SEC_DEBUGGING;
771
8.27M
#endif
772
8.27M
  else if (strcmp (name, _TEXT) == 0)
773
17.0k
    {
774
17.0k
      if (sec_flags & SEC_NEVER_LOAD)
775
5.67k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
11.3k
      else
777
11.3k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
17.0k
    }
779
8.25M
  else if (strcmp (name, _DATA) == 0)
780
29.6k
    {
781
29.6k
      if (sec_flags & SEC_NEVER_LOAD)
782
4.93k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
24.7k
      else
784
24.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
29.6k
    }
786
8.22M
  else if (strcmp (name, _BSS) == 0)
787
12.0k
    {
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
12.0k
  sec_flags |= SEC_ALLOC;
794
12.0k
    }
795
8.21M
  else if (startswith (name, DOT_DEBUG)
796
8.21M
     || 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
8.21M
     || startswith (name, ".stab"))
805
30.2k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
30.2k
    }
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
8.18M
  else
819
8.18M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
22.3M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
22.3M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
2.29M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
22.3M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
22.3M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
22.3M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
22.3M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
22.3M
  * flags_ptr = sec_flags;
851
22.3M
  return true;
852
22.3M
}
coff-sh.c:styp_to_sec_flags
Line
Count
Source
687
6.73M
{
688
6.73M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
6.73M
  unsigned long styp_flags = internal_s->s_flags;
690
6.73M
  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.73M
#ifdef STYP_NOLOAD
703
6.73M
  if (styp_flags & STYP_NOLOAD)
704
1.77M
    sec_flags |= SEC_NEVER_LOAD;
705
6.73M
#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.73M
  if (styp_flags & STYP_TEXT)
710
2.36M
    {
711
2.36M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.18M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.17M
      else
714
1.17M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.36M
    }
716
4.37M
  else if (styp_flags & STYP_DATA)
717
436k
    {
718
436k
      if (sec_flags & SEC_NEVER_LOAD)
719
220k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
216k
      else
721
216k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
436k
    }
723
3.93M
  else if (styp_flags & STYP_BSS)
724
197k
    {
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
197k
  sec_flags |= SEC_ALLOC;
731
197k
    }
732
3.73M
  else if (styp_flags & STYP_INFO)
733
500k
    {
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
500k
    }
744
3.23M
  else if (styp_flags & STYP_PAD)
745
166k
    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.06M
  else if (strcmp (name, _TEXT) == 0)
773
7.16k
    {
774
7.16k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.16k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
5.00k
      else
777
5.00k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
7.16k
    }
779
3.06M
  else if (strcmp (name, _DATA) == 0)
780
5.26k
    {
781
5.26k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.69k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
3.57k
      else
784
3.57k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
5.26k
    }
786
3.05M
  else if (strcmp (name, _BSS) == 0)
787
3.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
3.79k
  sec_flags |= SEC_ALLOC;
794
3.79k
    }
795
3.05M
  else if (startswith (name, DOT_DEBUG)
796
3.05M
     || startswith (name, DOT_ZDEBUG)
797
3.05M
#ifdef _COMMENT
798
3.05M
     || strcmp (name, _COMMENT) == 0
799
3.05M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.05M
     || startswith (name, ".stab"))
805
18.3k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
18.3k
    }
810
3.03M
#ifdef _LIB
811
3.03M
  else if (strcmp (name, _LIB) == 0)
812
3.47k
    ;
813
3.03M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.03M
  else
819
3.03M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
6.73M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
6.73M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
694k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
6.73M
#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.73M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
6.73M
      && (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.73M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
6.73M
  * flags_ptr = sec_flags;
851
6.73M
  return true;
852
6.73M
}
coff-stgo32.c:styp_to_sec_flags
Line
Count
Source
687
513k
{
688
513k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
513k
  unsigned long styp_flags = internal_s->s_flags;
690
513k
  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
513k
#ifdef STYP_NOLOAD
703
513k
  if (styp_flags & STYP_NOLOAD)
704
181k
    sec_flags |= SEC_NEVER_LOAD;
705
513k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
513k
  if (styp_flags & STYP_TEXT)
710
200k
    {
711
200k
      if (sec_flags & SEC_NEVER_LOAD)
712
101k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
98.2k
      else
714
98.2k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
200k
    }
716
313k
  else if (styp_flags & STYP_DATA)
717
68.9k
    {
718
68.9k
      if (sec_flags & SEC_NEVER_LOAD)
719
34.3k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
34.6k
      else
721
34.6k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
68.9k
    }
723
244k
  else if (styp_flags & STYP_BSS)
724
35.7k
    {
725
35.7k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
35.7k
      if (sec_flags & SEC_NEVER_LOAD)
727
15.4k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
20.2k
      else
729
20.2k
#endif
730
20.2k
  sec_flags |= SEC_ALLOC;
731
35.7k
    }
732
208k
  else if (styp_flags & STYP_INFO)
733
36.4k
    {
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
36.4k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
36.4k
      sec_flags |= SEC_DEBUGGING;
742
36.4k
#endif
743
36.4k
    }
744
172k
  else if (styp_flags & STYP_PAD)
745
15.4k
    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
156k
  else if (strcmp (name, _TEXT) == 0)
773
636
    {
774
636
      if (sec_flags & SEC_NEVER_LOAD)
775
61
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
575
      else
777
575
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
636
    }
779
155k
  else if (strcmp (name, _DATA) == 0)
780
613
    {
781
613
      if (sec_flags & SEC_NEVER_LOAD)
782
69
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
544
      else
784
544
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
613
    }
786
155k
  else if (strcmp (name, _BSS) == 0)
787
153
    {
788
153
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
153
      if (sec_flags & SEC_NEVER_LOAD)
790
41
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
112
      else
792
112
#endif
793
112
  sec_flags |= SEC_ALLOC;
794
153
    }
795
155k
  else if (startswith (name, DOT_DEBUG)
796
155k
     || startswith (name, DOT_ZDEBUG)
797
155k
#ifdef _COMMENT
798
155k
     || strcmp (name, _COMMENT) == 0
799
155k
#endif
800
155k
#ifdef COFF_LONG_SECTION_NAMES
801
155k
     || startswith (name, GNU_LINKONCE_WI)
802
155k
     || startswith (name, GNU_LINKONCE_WT)
803
155k
#endif
804
155k
     || startswith (name, ".stab"))
805
2.22k
    {
806
2.22k
#ifdef COFF_PAGE_SIZE
807
2.22k
      sec_flags |= SEC_DEBUGGING;
808
2.22k
#endif
809
2.22k
    }
810
152k
#ifdef _LIB
811
152k
  else if (strcmp (name, _LIB) == 0)
812
162
    ;
813
152k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
152k
  else
819
152k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
513k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
513k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
82.3k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
513k
#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
513k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
513k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
513k
#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
513k
  if (startswith (name, ".gnu.linkonce"))
844
116
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
513k
#endif
846
847
513k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
513k
  * flags_ptr = sec_flags;
851
513k
  return true;
852
513k
}
coff-tic30.c:styp_to_sec_flags
Line
Count
Source
687
4.73M
{
688
4.73M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
4.73M
  unsigned long styp_flags = internal_s->s_flags;
690
4.73M
  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
4.73M
#ifdef STYP_NOLOAD
703
4.73M
  if (styp_flags & STYP_NOLOAD)
704
1.31M
    sec_flags |= SEC_NEVER_LOAD;
705
4.73M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
4.73M
  if (styp_flags & STYP_TEXT)
710
1.68M
    {
711
1.68M
      if (sec_flags & SEC_NEVER_LOAD)
712
879k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
807k
      else
714
807k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.68M
    }
716
3.04M
  else if (styp_flags & STYP_DATA)
717
349k
    {
718
349k
      if (sec_flags & SEC_NEVER_LOAD)
719
174k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
174k
      else
721
174k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
349k
    }
723
2.69M
  else if (styp_flags & STYP_BSS)
724
159k
    {
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
159k
  sec_flags |= SEC_ALLOC;
731
159k
    }
732
2.53M
  else if (styp_flags & STYP_INFO)
733
317k
    {
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
317k
    }
744
2.21M
  else if (styp_flags & STYP_PAD)
745
104k
    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.11M
  else if (strcmp (name, _TEXT) == 0)
773
8.43k
    {
774
8.43k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.60k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
5.83k
      else
777
5.83k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
8.43k
    }
779
2.10M
  else if (strcmp (name, _DATA) == 0)
780
9.92k
    {
781
9.92k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.95k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
6.97k
      else
784
6.97k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
9.92k
    }
786
2.09M
  else if (strcmp (name, _BSS) == 0)
787
3.69k
    {
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
3.69k
  sec_flags |= SEC_ALLOC;
794
3.69k
    }
795
2.09M
  else if (startswith (name, DOT_DEBUG)
796
2.09M
     || startswith (name, DOT_ZDEBUG)
797
2.09M
#ifdef _COMMENT
798
2.09M
     || strcmp (name, _COMMENT) == 0
799
2.09M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.09M
     || startswith (name, ".stab"))
805
22.4k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
22.4k
    }
810
2.06M
#ifdef _LIB
811
2.06M
  else if (strcmp (name, _LIB) == 0)
812
3.43k
    ;
813
2.06M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.06M
  else
819
2.06M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
4.73M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
4.73M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
470k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
4.73M
#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
4.73M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
4.73M
      && (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
4.73M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
4.73M
  * flags_ptr = sec_flags;
851
4.73M
  return true;
852
4.73M
}
Unexecuted instantiation: coff-tic4x.c:styp_to_sec_flags
coff-tic54x.c:styp_to_sec_flags
Line
Count
Source
687
7.89M
{
688
7.89M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
7.89M
  unsigned long styp_flags = internal_s->s_flags;
690
7.89M
  flagword sec_flags = 0;
691
692
7.89M
#ifdef STYP_BLOCK
693
7.89M
  if (styp_flags & STYP_BLOCK)
694
2.31M
    sec_flags |= SEC_TIC54X_BLOCK;
695
7.89M
#endif
696
697
7.89M
#ifdef STYP_CLINK
698
7.89M
  if (styp_flags & STYP_CLINK)
699
2.44M
    sec_flags |= SEC_TIC54X_CLINK;
700
7.89M
#endif
701
702
7.89M
#ifdef STYP_NOLOAD
703
7.89M
  if (styp_flags & STYP_NOLOAD)
704
2.39M
    sec_flags |= SEC_NEVER_LOAD;
705
7.89M
#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.89M
  if (styp_flags & STYP_TEXT)
710
3.17M
    {
711
3.17M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.63M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.53M
      else
714
1.53M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.17M
    }
716
4.72M
  else if (styp_flags & STYP_DATA)
717
614k
    {
718
614k
      if (sec_flags & SEC_NEVER_LOAD)
719
358k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
255k
      else
721
255k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
614k
    }
723
4.10M
  else if (styp_flags & STYP_BSS)
724
236k
    {
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
236k
  sec_flags |= SEC_ALLOC;
731
236k
    }
732
3.87M
  else if (styp_flags & STYP_INFO)
733
523k
    {
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
523k
    }
744
3.34M
  else if (styp_flags & STYP_PAD)
745
145k
    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.20M
  else if (strcmp (name, _TEXT) == 0)
773
10.0k
    {
774
10.0k
      if (sec_flags & SEC_NEVER_LOAD)
775
3.54k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
6.54k
      else
777
6.54k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
10.0k
    }
779
3.19M
  else if (strcmp (name, _DATA) == 0)
780
13.2k
    {
781
13.2k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.25k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
10.9k
      else
784
10.9k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
13.2k
    }
786
3.17M
  else if (strcmp (name, _BSS) == 0)
787
5.01k
    {
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.01k
  sec_flags |= SEC_ALLOC;
794
5.01k
    }
795
3.17M
  else if (startswith (name, DOT_DEBUG)
796
3.17M
     || 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
3.17M
     || startswith (name, ".stab"))
805
25.4k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
25.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
3.14M
  else
819
3.14M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
7.89M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
7.89M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
799k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
7.89M
#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.89M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
7.89M
      && (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.89M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
7.89M
  * flags_ptr = sec_flags;
851
7.89M
  return true;
852
7.89M
}
coff-z80.c:styp_to_sec_flags
Line
Count
Source
687
1.20M
{
688
1.20M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
1.20M
  unsigned long styp_flags = internal_s->s_flags;
690
1.20M
  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.20M
#ifdef STYP_NOLOAD
703
1.20M
  if (styp_flags & STYP_NOLOAD)
704
377k
    sec_flags |= SEC_NEVER_LOAD;
705
1.20M
#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.20M
  if (styp_flags & STYP_TEXT)
710
433k
    {
711
433k
      if (sec_flags & SEC_NEVER_LOAD)
712
237k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
196k
      else
714
196k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
433k
    }
716
769k
  else if (styp_flags & STYP_DATA)
717
104k
    {
718
104k
      if (sec_flags & SEC_NEVER_LOAD)
719
60.8k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
43.6k
      else
721
43.6k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
104k
    }
723
664k
  else if (styp_flags & STYP_BSS)
724
39.5k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
39.5k
  sec_flags |= SEC_ALLOC;
731
39.5k
    }
732
625k
  else if (styp_flags & STYP_INFO)
733
90.5k
    {
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
90.5k
    }
744
534k
  else if (styp_flags & STYP_PAD)
745
29.2k
    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
505k
  else if (strcmp (name, _TEXT) == 0)
773
4.38k
    {
774
4.38k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.12k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3.26k
      else
777
3.26k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.38k
    }
779
501k
  else if (strcmp (name, _DATA) == 0)
780
3.90k
    {
781
3.90k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.32k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
2.57k
      else
784
2.57k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
3.90k
    }
786
497k
  else if (strcmp (name, _BSS) == 0)
787
2.66k
    {
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.66k
  sec_flags |= SEC_ALLOC;
794
2.66k
    }
795
494k
  else if (startswith (name, DOT_DEBUG)
796
494k
     || startswith (name, DOT_ZDEBUG)
797
494k
#ifdef _COMMENT
798
494k
     || strcmp (name, _COMMENT) == 0
799
494k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
494k
     || startswith (name, ".stab"))
805
16.3k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
16.3k
    }
810
478k
#ifdef _LIB
811
478k
  else if (strcmp (name, _LIB) == 0)
812
1.04k
    ;
813
477k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
477k
  else
819
477k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
1.20M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
1.20M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
122k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
1.20M
#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.20M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
1.20M
      && (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.20M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
1.20M
  * flags_ptr = sec_flags;
851
1.20M
  return true;
852
1.20M
}
coff-z8k.c:styp_to_sec_flags
Line
Count
Source
687
13.4M
{
688
13.4M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
13.4M
  unsigned long styp_flags = internal_s->s_flags;
690
13.4M
  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
13.4M
#ifdef STYP_NOLOAD
703
13.4M
  if (styp_flags & STYP_NOLOAD)
704
4.51M
    sec_flags |= SEC_NEVER_LOAD;
705
13.4M
#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.4M
  if (styp_flags & STYP_TEXT)
710
5.41M
    {
711
5.41M
      if (sec_flags & SEC_NEVER_LOAD)
712
3.04M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
2.36M
      else
714
2.36M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
5.41M
    }
716
7.99M
  else if (styp_flags & STYP_DATA)
717
1.19M
    {
718
1.19M
      if (sec_flags & SEC_NEVER_LOAD)
719
696k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
500k
      else
721
500k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.19M
    }
723
6.80M
  else if (styp_flags & STYP_BSS)
724
431k
    {
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
431k
  sec_flags |= SEC_ALLOC;
731
431k
    }
732
6.36M
  else if (styp_flags & STYP_INFO)
733
900k
    {
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
900k
    }
744
5.46M
  else if (styp_flags & STYP_PAD)
745
347k
    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.12M
  else if (strcmp (name, _TEXT) == 0)
773
6.90k
    {
774
6.90k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.05k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.85k
      else
777
4.85k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
6.90k
    }
779
5.11M
  else if (strcmp (name, _DATA) == 0)
780
18.2k
    {
781
18.2k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.83k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
15.4k
      else
784
15.4k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
18.2k
    }
786
5.09M
  else if (strcmp (name, _BSS) == 0)
787
5.53k
    {
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.53k
  sec_flags |= SEC_ALLOC;
794
5.53k
    }
795
5.09M
  else if (startswith (name, DOT_DEBUG)
796
5.09M
     || startswith (name, DOT_ZDEBUG)
797
5.09M
#ifdef _COMMENT
798
5.09M
     || strcmp (name, _COMMENT) == 0
799
5.09M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
5.09M
     || startswith (name, ".stab"))
805
32.5k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
32.5k
    }
810
5.05M
#ifdef _LIB
811
5.05M
  else if (strcmp (name, _LIB) == 0)
812
4.66k
    ;
813
5.05M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
5.05M
  else
819
5.05M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
13.4M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
13.4M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.65M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
13.4M
#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.4M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
13.4M
      && (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.4M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
13.4M
  * flags_ptr = sec_flags;
851
13.4M
  return true;
852
13.4M
}
853
854
#else /* COFF_WITH_PE */
855
856
static hashval_t
857
comdat_hashf (const void *entry)
858
12.5M
{
859
12.5M
  const struct comdat_hash_entry *fe = entry;
860
12.5M
  return fe->target_index;
861
12.5M
}
pei-i386.c:comdat_hashf
Line
Count
Source
858
595k
{
859
595k
  const struct comdat_hash_entry *fe = entry;
860
595k
  return fe->target_index;
861
595k
}
pe-x86_64.c:comdat_hashf
Line
Count
Source
858
2.77M
{
859
2.77M
  const struct comdat_hash_entry *fe = entry;
860
2.77M
  return fe->target_index;
861
2.77M
}
pei-x86_64.c:comdat_hashf
Line
Count
Source
858
1.57M
{
859
1.57M
  const struct comdat_hash_entry *fe = entry;
860
1.57M
  return fe->target_index;
861
1.57M
}
pe-aarch64.c:comdat_hashf
Line
Count
Source
858
206k
{
859
206k
  const struct comdat_hash_entry *fe = entry;
860
206k
  return fe->target_index;
861
206k
}
pei-aarch64.c:comdat_hashf
Line
Count
Source
858
1.42M
{
859
1.42M
  const struct comdat_hash_entry *fe = entry;
860
1.42M
  return fe->target_index;
861
1.42M
}
pei-ia64.c:comdat_hashf
Line
Count
Source
858
1.24M
{
859
1.24M
  const struct comdat_hash_entry *fe = entry;
860
1.24M
  return fe->target_index;
861
1.24M
}
pei-loongarch64.c:comdat_hashf
Line
Count
Source
858
409k
{
859
409k
  const struct comdat_hash_entry *fe = entry;
860
409k
  return fe->target_index;
861
409k
}
pei-riscv64.c:comdat_hashf
Line
Count
Source
858
1.07M
{
859
1.07M
  const struct comdat_hash_entry *fe = entry;
860
1.07M
  return fe->target_index;
861
1.07M
}
pe-arm-wince.c:comdat_hashf
Line
Count
Source
858
250k
{
859
250k
  const struct comdat_hash_entry *fe = entry;
860
250k
  return fe->target_index;
861
250k
}
pe-arm.c:comdat_hashf
Line
Count
Source
858
250k
{
859
250k
  const struct comdat_hash_entry *fe = entry;
860
250k
  return fe->target_index;
861
250k
}
pe-i386.c:comdat_hashf
Line
Count
Source
858
377k
{
859
377k
  const struct comdat_hash_entry *fe = entry;
860
377k
  return fe->target_index;
861
377k
}
pe-mcore.c:comdat_hashf
Line
Count
Source
858
174k
{
859
174k
  const struct comdat_hash_entry *fe = entry;
860
174k
  return fe->target_index;
861
174k
}
pe-sh.c:comdat_hashf
Line
Count
Source
858
355k
{
859
355k
  const struct comdat_hash_entry *fe = entry;
860
355k
  return fe->target_index;
861
355k
}
pei-arm-wince.c:comdat_hashf
Line
Count
Source
858
567k
{
859
567k
  const struct comdat_hash_entry *fe = entry;
860
567k
  return fe->target_index;
861
567k
}
pei-arm.c:comdat_hashf
Line
Count
Source
858
653k
{
859
653k
  const struct comdat_hash_entry *fe = entry;
860
653k
  return fe->target_index;
861
653k
}
pei-mcore.c:comdat_hashf
Line
Count
Source
858
262k
{
859
262k
  const struct comdat_hash_entry *fe = entry;
860
262k
  return fe->target_index;
861
262k
}
pei-sh.c:comdat_hashf
Line
Count
Source
858
368k
{
859
368k
  const struct comdat_hash_entry *fe = entry;
860
368k
  return fe->target_index;
861
368k
}
862
863
static int
864
comdat_eqf (const void *e1, const void *e2)
865
9.78M
{
866
9.78M
  const struct comdat_hash_entry *fe1 = e1;
867
9.78M
  const struct comdat_hash_entry *fe2 = e2;
868
9.78M
  return fe1->target_index == fe2->target_index;
869
9.78M
}
pei-i386.c:comdat_eqf
Line
Count
Source
865
414k
{
866
414k
  const struct comdat_hash_entry *fe1 = e1;
867
414k
  const struct comdat_hash_entry *fe2 = e2;
868
414k
  return fe1->target_index == fe2->target_index;
869
414k
}
pe-x86_64.c:comdat_eqf
Line
Count
Source
865
2.36M
{
866
2.36M
  const struct comdat_hash_entry *fe1 = e1;
867
2.36M
  const struct comdat_hash_entry *fe2 = e2;
868
2.36M
  return fe1->target_index == fe2->target_index;
869
2.36M
}
pei-x86_64.c:comdat_eqf
Line
Count
Source
865
1.48M
{
866
1.48M
  const struct comdat_hash_entry *fe1 = e1;
867
1.48M
  const struct comdat_hash_entry *fe2 = e2;
868
1.48M
  return fe1->target_index == fe2->target_index;
869
1.48M
}
pe-aarch64.c:comdat_eqf
Line
Count
Source
865
132k
{
866
132k
  const struct comdat_hash_entry *fe1 = e1;
867
132k
  const struct comdat_hash_entry *fe2 = e2;
868
132k
  return fe1->target_index == fe2->target_index;
869
132k
}
pei-aarch64.c:comdat_eqf
Line
Count
Source
865
1.10M
{
866
1.10M
  const struct comdat_hash_entry *fe1 = e1;
867
1.10M
  const struct comdat_hash_entry *fe2 = e2;
868
1.10M
  return fe1->target_index == fe2->target_index;
869
1.10M
}
pei-ia64.c:comdat_eqf
Line
Count
Source
865
925k
{
866
925k
  const struct comdat_hash_entry *fe1 = e1;
867
925k
  const struct comdat_hash_entry *fe2 = e2;
868
925k
  return fe1->target_index == fe2->target_index;
869
925k
}
pei-loongarch64.c:comdat_eqf
Line
Count
Source
865
263k
{
866
263k
  const struct comdat_hash_entry *fe1 = e1;
867
263k
  const struct comdat_hash_entry *fe2 = e2;
868
263k
  return fe1->target_index == fe2->target_index;
869
263k
}
pei-riscv64.c:comdat_eqf
Line
Count
Source
865
858k
{
866
858k
  const struct comdat_hash_entry *fe1 = e1;
867
858k
  const struct comdat_hash_entry *fe2 = e2;
868
858k
  return fe1->target_index == fe2->target_index;
869
858k
}
pe-arm-wince.c:comdat_eqf
Line
Count
Source
865
165k
{
866
165k
  const struct comdat_hash_entry *fe1 = e1;
867
165k
  const struct comdat_hash_entry *fe2 = e2;
868
165k
  return fe1->target_index == fe2->target_index;
869
165k
}
pe-arm.c:comdat_eqf
Line
Count
Source
865
165k
{
866
165k
  const struct comdat_hash_entry *fe1 = e1;
867
165k
  const struct comdat_hash_entry *fe2 = e2;
868
165k
  return fe1->target_index == fe2->target_index;
869
165k
}
pe-i386.c:comdat_eqf
Line
Count
Source
865
258k
{
866
258k
  const struct comdat_hash_entry *fe1 = e1;
867
258k
  const struct comdat_hash_entry *fe2 = e2;
868
258k
  return fe1->target_index == fe2->target_index;
869
258k
}
pe-mcore.c:comdat_eqf
Line
Count
Source
865
96.9k
{
866
96.9k
  const struct comdat_hash_entry *fe1 = e1;
867
96.9k
  const struct comdat_hash_entry *fe2 = e2;
868
96.9k
  return fe1->target_index == fe2->target_index;
869
96.9k
}
pe-sh.c:comdat_eqf
Line
Count
Source
865
268k
{
866
268k
  const struct comdat_hash_entry *fe1 = e1;
867
268k
  const struct comdat_hash_entry *fe2 = e2;
868
268k
  return fe1->target_index == fe2->target_index;
869
268k
}
pei-arm-wince.c:comdat_eqf
Line
Count
Source
865
399k
{
866
399k
  const struct comdat_hash_entry *fe1 = e1;
867
399k
  const struct comdat_hash_entry *fe2 = e2;
868
399k
  return fe1->target_index == fe2->target_index;
869
399k
}
pei-arm.c:comdat_eqf
Line
Count
Source
865
459k
{
866
459k
  const struct comdat_hash_entry *fe1 = e1;
867
459k
  const struct comdat_hash_entry *fe2 = e2;
868
459k
  return fe1->target_index == fe2->target_index;
869
459k
}
pei-mcore.c:comdat_eqf
Line
Count
Source
865
166k
{
866
166k
  const struct comdat_hash_entry *fe1 = e1;
867
166k
  const struct comdat_hash_entry *fe2 = e2;
868
166k
  return fe1->target_index == fe2->target_index;
869
166k
}
pei-sh.c:comdat_eqf
Line
Count
Source
865
255k
{
866
255k
  const struct comdat_hash_entry *fe1 = e1;
867
255k
  const struct comdat_hash_entry *fe2 = e2;
868
255k
  return fe1->target_index == fe2->target_index;
869
255k
}
870
871
static void
872
comdat_delf (void *ent)
873
2.79M
{
874
2.79M
  struct comdat_hash_entry *e = ent;
875
2.79M
  free (e->comdat_name);
876
2.79M
  free (e->symname);
877
2.79M
  free (e);
878
2.79M
}
pei-i386.c:comdat_delf
Line
Count
Source
873
177k
{
874
177k
  struct comdat_hash_entry *e = ent;
875
177k
  free (e->comdat_name);
876
177k
  free (e->symname);
877
177k
  free (e);
878
177k
}
pe-x86_64.c:comdat_delf
Line
Count
Source
873
407k
{
874
407k
  struct comdat_hash_entry *e = ent;
875
407k
  free (e->comdat_name);
876
407k
  free (e->symname);
877
407k
  free (e);
878
407k
}
pei-x86_64.c:comdat_delf
Line
Count
Source
873
260k
{
874
260k
  struct comdat_hash_entry *e = ent;
875
260k
  free (e->comdat_name);
876
260k
  free (e->symname);
877
260k
  free (e);
878
260k
}
pe-aarch64.c:comdat_delf
Line
Count
Source
873
55.5k
{
874
55.5k
  struct comdat_hash_entry *e = ent;
875
55.5k
  free (e->comdat_name);
876
55.5k
  free (e->symname);
877
55.5k
  free (e);
878
55.5k
}
pei-aarch64.c:comdat_delf
Line
Count
Source
873
289k
{
874
289k
  struct comdat_hash_entry *e = ent;
875
289k
  free (e->comdat_name);
876
289k
  free (e->symname);
877
289k
  free (e);
878
289k
}
pei-ia64.c:comdat_delf
Line
Count
Source
873
332k
{
874
332k
  struct comdat_hash_entry *e = ent;
875
332k
  free (e->comdat_name);
876
332k
  free (e->symname);
877
332k
  free (e);
878
332k
}
pei-loongarch64.c:comdat_delf
Line
Count
Source
873
144k
{
874
144k
  struct comdat_hash_entry *e = ent;
875
144k
  free (e->comdat_name);
876
144k
  free (e->symname);
877
144k
  free (e);
878
144k
}
pei-riscv64.c:comdat_delf
Line
Count
Source
873
246k
{
874
246k
  struct comdat_hash_entry *e = ent;
875
246k
  free (e->comdat_name);
876
246k
  free (e->symname);
877
246k
  free (e);
878
246k
}
pe-arm-wince.c:comdat_delf
Line
Count
Source
873
70.5k
{
874
70.5k
  struct comdat_hash_entry *e = ent;
875
70.5k
  free (e->comdat_name);
876
70.5k
  free (e->symname);
877
70.5k
  free (e);
878
70.5k
}
pe-arm.c:comdat_delf
Line
Count
Source
873
70.5k
{
874
70.5k
  struct comdat_hash_entry *e = ent;
875
70.5k
  free (e->comdat_name);
876
70.5k
  free (e->symname);
877
70.5k
  free (e);
878
70.5k
}
pe-i386.c:comdat_delf
Line
Count
Source
873
101k
{
874
101k
  struct comdat_hash_entry *e = ent;
875
101k
  free (e->comdat_name);
876
101k
  free (e->symname);
877
101k
  free (e);
878
101k
}
pe-mcore.c:comdat_delf
Line
Count
Source
873
51.3k
{
874
51.3k
  struct comdat_hash_entry *e = ent;
875
51.3k
  free (e->comdat_name);
876
51.3k
  free (e->symname);
877
51.3k
  free (e);
878
51.3k
}
pe-sh.c:comdat_delf
Line
Count
Source
873
76.7k
{
874
76.7k
  struct comdat_hash_entry *e = ent;
875
76.7k
  free (e->comdat_name);
876
76.7k
  free (e->symname);
877
76.7k
  free (e);
878
76.7k
}
pei-arm-wince.c:comdat_delf
Line
Count
Source
873
154k
{
874
154k
  struct comdat_hash_entry *e = ent;
875
154k
  free (e->comdat_name);
876
154k
  free (e->symname);
877
154k
  free (e);
878
154k
}
pei-arm.c:comdat_delf
Line
Count
Source
873
174k
{
874
174k
  struct comdat_hash_entry *e = ent;
875
174k
  free (e->comdat_name);
876
174k
  free (e->symname);
877
174k
  free (e);
878
174k
}
pei-mcore.c:comdat_delf
Line
Count
Source
873
83.5k
{
874
83.5k
  struct comdat_hash_entry *e = ent;
875
83.5k
  free (e->comdat_name);
876
83.5k
  free (e->symname);
877
83.5k
  free (e);
878
83.5k
}
pei-sh.c:comdat_delf
Line
Count
Source
873
102k
{
874
102k
  struct comdat_hash_entry *e = ent;
875
102k
  free (e->comdat_name);
876
102k
  free (e->symname);
877
102k
  free (e);
878
102k
}
879
880
static struct comdat_hash_entry *
881
find_flags (htab_t comdat_hash, int target_index)
882
1.02M
{
883
1.02M
  struct comdat_hash_entry needle;
884
1.02M
  needle.target_index = target_index;
885
886
1.02M
  return htab_find (comdat_hash, &needle);
887
1.02M
}
pei-i386.c:find_flags
Line
Count
Source
882
76.4k
{
883
76.4k
  struct comdat_hash_entry needle;
884
76.4k
  needle.target_index = target_index;
885
886
76.4k
  return htab_find (comdat_hash, &needle);
887
76.4k
}
pe-x86_64.c:find_flags
Line
Count
Source
882
127k
{
883
127k
  struct comdat_hash_entry needle;
884
127k
  needle.target_index = target_index;
885
886
127k
  return htab_find (comdat_hash, &needle);
887
127k
}
pei-x86_64.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
}
pe-aarch64.c:find_flags
Line
Count
Source
882
38.7k
{
883
38.7k
  struct comdat_hash_entry needle;
884
38.7k
  needle.target_index = target_index;
885
886
38.7k
  return htab_find (comdat_hash, &needle);
887
38.7k
}
pei-aarch64.c:find_flags
Line
Count
Source
882
66.3k
{
883
66.3k
  struct comdat_hash_entry needle;
884
66.3k
  needle.target_index = target_index;
885
886
66.3k
  return htab_find (comdat_hash, &needle);
887
66.3k
}
pei-ia64.c:find_flags
Line
Count
Source
882
66.5k
{
883
66.5k
  struct comdat_hash_entry needle;
884
66.5k
  needle.target_index = target_index;
885
886
66.5k
  return htab_find (comdat_hash, &needle);
887
66.5k
}
pei-loongarch64.c:find_flags
Line
Count
Source
882
58.1k
{
883
58.1k
  struct comdat_hash_entry needle;
884
58.1k
  needle.target_index = target_index;
885
886
58.1k
  return htab_find (comdat_hash, &needle);
887
58.1k
}
pei-riscv64.c:find_flags
Line
Count
Source
882
54.0k
{
883
54.0k
  struct comdat_hash_entry needle;
884
54.0k
  needle.target_index = target_index;
885
886
54.0k
  return htab_find (comdat_hash, &needle);
887
54.0k
}
pe-arm-wince.c:find_flags
Line
Count
Source
882
24.3k
{
883
24.3k
  struct comdat_hash_entry needle;
884
24.3k
  needle.target_index = target_index;
885
886
24.3k
  return htab_find (comdat_hash, &needle);
887
24.3k
}
pe-arm.c:find_flags
Line
Count
Source
882
24.3k
{
883
24.3k
  struct comdat_hash_entry needle;
884
24.3k
  needle.target_index = target_index;
885
886
24.3k
  return htab_find (comdat_hash, &needle);
887
24.3k
}
pe-i386.c:find_flags
Line
Count
Source
882
43.2k
{
883
43.2k
  struct comdat_hash_entry needle;
884
43.2k
  needle.target_index = target_index;
885
886
43.2k
  return htab_find (comdat_hash, &needle);
887
43.2k
}
pe-mcore.c:find_flags
Line
Count
Source
882
49.8k
{
883
49.8k
  struct comdat_hash_entry needle;
884
49.8k
  needle.target_index = target_index;
885
886
49.8k
  return htab_find (comdat_hash, &needle);
887
49.8k
}
pe-sh.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
}
pei-arm-wince.c:find_flags
Line
Count
Source
882
70.8k
{
883
70.8k
  struct comdat_hash_entry needle;
884
70.8k
  needle.target_index = target_index;
885
886
70.8k
  return htab_find (comdat_hash, &needle);
887
70.8k
}
pei-arm.c:find_flags
Line
Count
Source
882
81.6k
{
883
81.6k
  struct comdat_hash_entry needle;
884
81.6k
  needle.target_index = target_index;
885
886
81.6k
  return htab_find (comdat_hash, &needle);
887
81.6k
}
pei-mcore.c:find_flags
Line
Count
Source
882
57.0k
{
883
57.0k
  struct comdat_hash_entry needle;
884
57.0k
  needle.target_index = target_index;
885
886
57.0k
  return htab_find (comdat_hash, &needle);
887
57.0k
}
pei-sh.c:find_flags
Line
Count
Source
882
67.7k
{
883
67.7k
  struct comdat_hash_entry needle;
884
67.7k
  needle.target_index = target_index;
885
886
67.7k
  return htab_find (comdat_hash, &needle);
887
67.7k
}
888
889
static bool
890
fill_comdat_hash (bfd *abfd)
891
850k
{
892
850k
  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
850k
  if (! _bfd_coff_get_external_symbols (abfd))
910
309k
    return true;
911
912
540k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
540k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
540k
  for (struct internal_syment isym;
916
13.6M
       esym < esymend;
917
13.1M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
13.1M
    {
919
13.1M
      char buf[SYMNMLEN + 1];
920
13.1M
      const char *symname;
921
13.1M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
13.1M
      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
13.1M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
13.1M
      if (symname == NULL)
950
3.50M
  {
951
3.50M
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
3.50M
            abfd);
953
3.50M
    continue;
954
3.50M
  }
955
956
9.62M
      union internal_auxent aux;
957
958
9.62M
      struct comdat_hash_entry needle;
959
9.62M
      needle.target_index = isym.n_scnum;
960
961
9.62M
      void **slot
962
9.62M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
9.62M
      if (slot == NULL)
964
0
  return false;
965
966
9.62M
      if (*slot == NULL)
967
2.81M
  {
968
2.81M
    if (isym.n_numaux != 1)
969
2.41M
      aux.x_scn.x_comdat = 0;
970
397k
    else
971
397k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
397k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
17.4k
    {
975
      /* xgettext:c-format */
976
17.4k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
17.4k
          " section '%s' found"),
978
17.4k
              abfd, symname);
979
17.4k
      continue;
980
17.4k
    }
981
380k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
380k
            isym.n_type, isym.n_sclass, 0,
983
380k
            isym.n_numaux, &aux);
984
380k
      }
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
2.79M
    switch (aux.x_scn.x_comdat)
999
2.79M
      {
1000
24.3k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
24.3k
        sec_flags &= ~SEC_LINK_ONCE;
1005
24.3k
#endif
1006
24.3k
        break;
1007
1008
2.32k
      case IMAGE_COMDAT_SELECT_ANY:
1009
2.32k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
2.32k
        break;
1011
1012
798
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
798
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
798
        break;
1015
1016
15.5k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
15.5k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
15.5k
        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.38k
      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.38k
        sec_flags &= ~SEC_LINK_ONCE;
1032
2.38k
#endif
1033
2.38k
        break;
1034
1035
2.75M
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
2.75M
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
2.75M
        break;
1039
2.79M
      }
1040
1041
2.79M
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
2.79M
    if (*slot == NULL)
1043
0
      return false;
1044
2.79M
    struct comdat_hash_entry *newentry = *slot;
1045
2.79M
    newentry->sec_flags = sec_flags;
1046
2.79M
    newentry->symname = bfd_strdup (symname);
1047
2.79M
    newentry->target_index = isym.n_scnum;
1048
2.79M
    newentry->isym = isym;
1049
2.79M
    newentry->comdat_symbol = -1;
1050
2.79M
  }
1051
6.81M
      else
1052
6.81M
  {
1053
6.81M
    struct comdat_hash_entry *entry = *slot;
1054
1055
6.81M
    if (entry->comdat_symbol != -1)
1056
6.07M
      continue;
1057
1058
737k
    char *target_name = strchr (entry->symname, '$');
1059
737k
    if (target_name != NULL)
1060
206k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
206k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
69.0k
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
206k
        if (strcmp (target_name,
1069
206k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
179k
    {
1071
      /* Not the name we're looking for */
1072
179k
      continue;
1073
179k
    }
1074
206k
      }
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
557k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
557k
    entry->comdat_name = bfd_strdup (symname);
1083
557k
  }
1084
9.62M
    }
1085
1086
540k
  return true;
1087
540k
}
pei-i386.c:fill_comdat_hash
Line
Count
Source
891
52.1k
{
892
52.1k
  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
52.1k
  if (! _bfd_coff_get_external_symbols (abfd))
910
15.8k
    return true;
911
912
36.2k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
36.2k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
36.2k
  for (struct internal_syment isym;
916
610k
       esym < esymend;
917
574k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
574k
    {
919
574k
      char buf[SYMNMLEN + 1];
920
574k
      const char *symname;
921
574k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
574k
      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
574k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
574k
      if (symname == NULL)
950
176k
  {
951
176k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
176k
            abfd);
953
176k
    continue;
954
176k
  }
955
956
397k
      union internal_auxent aux;
957
958
397k
      struct comdat_hash_entry needle;
959
397k
      needle.target_index = isym.n_scnum;
960
961
397k
      void **slot
962
397k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
397k
      if (slot == NULL)
964
0
  return false;
965
966
397k
      if (*slot == NULL)
967
179k
  {
968
179k
    if (isym.n_numaux != 1)
969
158k
      aux.x_scn.x_comdat = 0;
970
20.1k
    else
971
20.1k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
20.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
2.07k
    {
975
      /* xgettext:c-format */
976
2.07k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
2.07k
          " section '%s' found"),
978
2.07k
              abfd, symname);
979
2.07k
      continue;
980
2.07k
    }
981
18.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
18.1k
            isym.n_type, isym.n_sclass, 0,
983
18.1k
            isym.n_numaux, &aux);
984
18.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
177k
    switch (aux.x_scn.x_comdat)
999
177k
      {
1000
2.15k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.15k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.15k
#endif
1006
2.15k
        break;
1007
1008
548
      case IMAGE_COMDAT_SELECT_ANY:
1009
548
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
548
        break;
1011
1012
14
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
14
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
14
        break;
1015
1016
931
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
931
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
931
        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
40
      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
40
        sec_flags &= ~SEC_LINK_ONCE;
1032
40
#endif
1033
40
        break;
1034
1035
173k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
173k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
173k
        break;
1039
177k
      }
1040
1041
177k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
177k
    if (*slot == NULL)
1043
0
      return false;
1044
177k
    struct comdat_hash_entry *newentry = *slot;
1045
177k
    newentry->sec_flags = sec_flags;
1046
177k
    newentry->symname = bfd_strdup (symname);
1047
177k
    newentry->target_index = isym.n_scnum;
1048
177k
    newentry->isym = isym;
1049
177k
    newentry->comdat_symbol = -1;
1050
177k
  }
1051
218k
      else
1052
218k
  {
1053
218k
    struct comdat_hash_entry *entry = *slot;
1054
1055
218k
    if (entry->comdat_symbol != -1)
1056
176k
      continue;
1057
1058
42.1k
    char *target_name = strchr (entry->symname, '$');
1059
42.1k
    if (target_name != NULL)
1060
10.3k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
10.3k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
10.3k
        if (strcmp (target_name,
1069
10.3k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
6.41k
    {
1071
      /* Not the name we're looking for */
1072
6.41k
      continue;
1073
6.41k
    }
1074
10.3k
      }
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
35.7k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
35.7k
    entry->comdat_name = bfd_strdup (symname);
1083
35.7k
  }
1084
397k
    }
1085
1086
36.2k
  return true;
1087
36.2k
}
pe-x86_64.c:fill_comdat_hash
Line
Count
Source
891
119k
{
892
119k
  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
119k
  if (! _bfd_coff_get_external_symbols (abfd))
910
46.8k
    return true;
911
912
72.4k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
72.4k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
72.4k
  for (struct internal_syment isym;
916
2.85M
       esym < esymend;
917
2.78M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
2.78M
    {
919
2.78M
      char buf[SYMNMLEN + 1];
920
2.78M
      const char *symname;
921
2.78M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
2.78M
      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.78M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
2.78M
      if (symname == NULL)
950
448k
  {
951
448k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
448k
            abfd);
953
448k
    continue;
954
448k
  }
955
956
2.33M
      union internal_auxent aux;
957
958
2.33M
      struct comdat_hash_entry needle;
959
2.33M
      needle.target_index = isym.n_scnum;
960
961
2.33M
      void **slot
962
2.33M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
2.33M
      if (slot == NULL)
964
0
  return false;
965
966
2.33M
      if (*slot == NULL)
967
409k
  {
968
409k
    if (isym.n_numaux != 1)
969
339k
      aux.x_scn.x_comdat = 0;
970
69.6k
    else
971
69.6k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
69.6k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.58k
    {
975
      /* xgettext:c-format */
976
1.58k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.58k
          " section '%s' found"),
978
1.58k
              abfd, symname);
979
1.58k
      continue;
980
1.58k
    }
981
68.0k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
68.0k
            isym.n_type, isym.n_sclass, 0,
983
68.0k
            isym.n_numaux, &aux);
984
68.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
407k
    switch (aux.x_scn.x_comdat)
999
407k
      {
1000
3.04k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
3.04k
        sec_flags &= ~SEC_LINK_ONCE;
1005
3.04k
#endif
1006
3.04k
        break;
1007
1008
242
      case IMAGE_COMDAT_SELECT_ANY:
1009
242
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
242
        break;
1011
1012
138
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
138
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
138
        break;
1015
1016
2.46k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
2.46k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
2.46k
        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
401k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
401k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
401k
        break;
1039
407k
      }
1040
1041
407k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
407k
    if (*slot == NULL)
1043
0
      return false;
1044
407k
    struct comdat_hash_entry *newentry = *slot;
1045
407k
    newentry->sec_flags = sec_flags;
1046
407k
    newentry->symname = bfd_strdup (symname);
1047
407k
    newentry->target_index = isym.n_scnum;
1048
407k
    newentry->isym = isym;
1049
407k
    newentry->comdat_symbol = -1;
1050
407k
  }
1051
1.92M
      else
1052
1.92M
  {
1053
1.92M
    struct comdat_hash_entry *entry = *slot;
1054
1055
1.92M
    if (entry->comdat_symbol != -1)
1056
1.83M
      continue;
1057
1058
91.9k
    char *target_name = strchr (entry->symname, '$');
1059
91.9k
    if (target_name != NULL)
1060
17.3k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
17.3k
        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.3k
        if (strcmp (target_name,
1069
17.3k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
16.1k
    {
1071
      /* Not the name we're looking for */
1072
16.1k
      continue;
1073
16.1k
    }
1074
17.3k
      }
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
75.7k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
75.7k
    entry->comdat_name = bfd_strdup (symname);
1083
75.7k
  }
1084
2.33M
    }
1085
1086
72.4k
  return true;
1087
72.4k
}
pei-x86_64.c:fill_comdat_hash
Line
Count
Source
891
62.7k
{
892
62.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
62.7k
  if (! _bfd_coff_get_external_symbols (abfd))
910
23.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.84M
       esym < esymend;
917
1.80M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.80M
    {
919
1.80M
      char buf[SYMNMLEN + 1];
920
1.80M
      const char *symname;
921
1.80M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.80M
      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.80M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.80M
      if (symname == NULL)
950
497k
  {
951
497k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
497k
            abfd);
953
497k
    continue;
954
497k
  }
955
956
1.30M
      union internal_auxent aux;
957
958
1.30M
      struct comdat_hash_entry needle;
959
1.30M
      needle.target_index = isym.n_scnum;
960
961
1.30M
      void **slot
962
1.30M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
1.30M
      if (slot == NULL)
964
0
  return false;
965
966
1.30M
      if (*slot == NULL)
967
261k
  {
968
261k
    if (isym.n_numaux != 1)
969
232k
      aux.x_scn.x_comdat = 0;
970
29.0k
    else
971
29.0k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
29.0k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.62k
    {
975
      /* xgettext:c-format */
976
1.62k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.62k
          " section '%s' found"),
978
1.62k
              abfd, symname);
979
1.62k
      continue;
980
1.62k
    }
981
27.3k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
27.3k
            isym.n_type, isym.n_sclass, 0,
983
27.3k
            isym.n_numaux, &aux);
984
27.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
260k
    switch (aux.x_scn.x_comdat)
999
260k
      {
1000
1.00k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.00k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.00k
#endif
1006
1.00k
        break;
1007
1008
536
      case IMAGE_COMDAT_SELECT_ANY:
1009
536
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
536
        break;
1011
1012
3
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
3
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
3
        break;
1015
1016
853
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
853
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
853
        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
31
      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
31
        sec_flags &= ~SEC_LINK_ONCE;
1032
31
#endif
1033
31
        break;
1034
1035
257k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
257k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
257k
        break;
1039
260k
      }
1040
1041
260k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
260k
    if (*slot == NULL)
1043
0
      return false;
1044
260k
    struct comdat_hash_entry *newentry = *slot;
1045
260k
    newentry->sec_flags = sec_flags;
1046
260k
    newentry->symname = bfd_strdup (symname);
1047
260k
    newentry->target_index = isym.n_scnum;
1048
260k
    newentry->isym = isym;
1049
260k
    newentry->comdat_symbol = -1;
1050
260k
  }
1051
1.04M
      else
1052
1.04M
  {
1053
1.04M
    struct comdat_hash_entry *entry = *slot;
1054
1055
1.04M
    if (entry->comdat_symbol != -1)
1056
964k
      continue;
1057
1058
82.1k
    char *target_name = strchr (entry->symname, '$');
1059
82.1k
    if (target_name != NULL)
1060
15.9k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
15.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
15.9k
        if (strcmp (target_name,
1069
15.9k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
14.0k
    {
1071
      /* Not the name we're looking for */
1072
14.0k
      continue;
1073
14.0k
    }
1074
15.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
68.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
68.0k
    entry->comdat_name = bfd_strdup (symname);
1083
68.0k
  }
1084
1.30M
    }
1085
1086
38.9k
  return true;
1087
38.9k
}
pe-aarch64.c:fill_comdat_hash
Line
Count
Source
891
33.4k
{
892
33.4k
  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
33.4k
  if (! _bfd_coff_get_external_symbols (abfd))
910
7.91k
    return true;
911
912
25.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
25.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
25.5k
  for (struct internal_syment isym;
916
243k
       esym < esymend;
917
217k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
217k
    {
919
217k
      char buf[SYMNMLEN + 1];
920
217k
      const char *symname;
921
217k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
217k
      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
217k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
217k
      if (symname == NULL)
950
62.2k
  {
951
62.2k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
62.2k
            abfd);
953
62.2k
    continue;
954
62.2k
  }
955
956
155k
      union internal_auxent aux;
957
958
155k
      struct comdat_hash_entry needle;
959
155k
      needle.target_index = isym.n_scnum;
960
961
155k
      void **slot
962
155k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
155k
      if (slot == NULL)
964
0
  return false;
965
966
155k
      if (*slot == NULL)
967
56.6k
  {
968
56.6k
    if (isym.n_numaux != 1)
969
46.0k
      aux.x_scn.x_comdat = 0;
970
10.6k
    else
971
10.6k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
10.6k
        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
9.45k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
9.45k
            isym.n_type, isym.n_sclass, 0,
983
9.45k
            isym.n_numaux, &aux);
984
9.45k
      }
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
55.5k
    switch (aux.x_scn.x_comdat)
999
55.5k
      {
1000
603
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
603
        sec_flags &= ~SEC_LINK_ONCE;
1005
603
#endif
1006
603
        break;
1007
1008
4
      case IMAGE_COMDAT_SELECT_ANY:
1009
4
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
4
        break;
1011
1012
236
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
236
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
236
        break;
1015
1016
411
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
411
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
411
        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
54.2k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
54.2k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
54.2k
        break;
1039
55.5k
      }
1040
1041
55.5k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
55.5k
    if (*slot == NULL)
1043
0
      return false;
1044
55.5k
    struct comdat_hash_entry *newentry = *slot;
1045
55.5k
    newentry->sec_flags = sec_flags;
1046
55.5k
    newentry->symname = bfd_strdup (symname);
1047
55.5k
    newentry->target_index = isym.n_scnum;
1048
55.5k
    newentry->isym = isym;
1049
55.5k
    newentry->comdat_symbol = -1;
1050
55.5k
  }
1051
98.6k
      else
1052
98.6k
  {
1053
98.6k
    struct comdat_hash_entry *entry = *slot;
1054
1055
98.6k
    if (entry->comdat_symbol != -1)
1056
81.6k
      continue;
1057
1058
17.0k
    char *target_name = strchr (entry->symname, '$');
1059
17.0k
    if (target_name != NULL)
1060
6.23k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
6.23k
        target_name += 1;
1064
6.23k
#ifndef TARGET_UNDERSCORE
1065
6.23k
#define TARGET_UNDERSCORE 0
1066
6.23k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
6.23k
        if (strcmp (target_name,
1069
6.23k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
5.51k
    {
1071
      /* Not the name we're looking for */
1072
5.51k
      continue;
1073
5.51k
    }
1074
6.23k
      }
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
11.5k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
11.5k
    entry->comdat_name = bfd_strdup (symname);
1083
11.5k
  }
1084
155k
    }
1085
1086
25.5k
  return true;
1087
25.5k
}
pei-aarch64.c:fill_comdat_hash
Line
Count
Source
891
47.1k
{
892
47.1k
  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
47.1k
  if (! _bfd_coff_get_external_symbols (abfd))
910
15.6k
    return true;
911
912
31.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
31.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
31.5k
  for (struct internal_syment isym;
916
1.53M
       esym < esymend;
917
1.50M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.50M
    {
919
1.50M
      char buf[SYMNMLEN + 1];
920
1.50M
      const char *symname;
921
1.50M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.50M
      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.50M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.50M
      if (symname == NULL)
950
409k
  {
951
409k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
409k
            abfd);
953
409k
    continue;
954
409k
  }
955
956
1.09M
      union internal_auxent aux;
957
958
1.09M
      struct comdat_hash_entry needle;
959
1.09M
      needle.target_index = isym.n_scnum;
960
961
1.09M
      void **slot
962
1.09M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
1.09M
      if (slot == NULL)
964
0
  return false;
965
966
1.09M
      if (*slot == NULL)
967
290k
  {
968
290k
    if (isym.n_numaux != 1)
969
251k
      aux.x_scn.x_comdat = 0;
970
38.7k
    else
971
38.7k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
38.7k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
724
    {
975
      /* xgettext:c-format */
976
724
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
724
          " section '%s' found"),
978
724
              abfd, symname);
979
724
      continue;
980
724
    }
981
38.0k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
38.0k
            isym.n_type, isym.n_sclass, 0,
983
38.0k
            isym.n_numaux, &aux);
984
38.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
289k
    switch (aux.x_scn.x_comdat)
999
289k
      {
1000
2.31k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.31k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.31k
#endif
1006
2.31k
        break;
1007
1008
49
      case IMAGE_COMDAT_SELECT_ANY:
1009
49
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
49
        break;
1011
1012
9
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
9
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
9
        break;
1015
1016
1.57k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.57k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.57k
        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
22
      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
22
        sec_flags &= ~SEC_LINK_ONCE;
1032
22
#endif
1033
22
        break;
1034
1035
285k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
285k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
285k
        break;
1039
289k
      }
1040
1041
289k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
289k
    if (*slot == NULL)
1043
0
      return false;
1044
289k
    struct comdat_hash_entry *newentry = *slot;
1045
289k
    newentry->sec_flags = sec_flags;
1046
289k
    newentry->symname = bfd_strdup (symname);
1047
289k
    newentry->target_index = isym.n_scnum;
1048
289k
    newentry->isym = isym;
1049
289k
    newentry->comdat_symbol = -1;
1050
289k
  }
1051
799k
      else
1052
799k
  {
1053
799k
    struct comdat_hash_entry *entry = *slot;
1054
1055
799k
    if (entry->comdat_symbol != -1)
1056
735k
      continue;
1057
1058
64.6k
    char *target_name = strchr (entry->symname, '$');
1059
64.6k
    if (target_name != NULL)
1060
10.6k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
10.6k
        target_name += 1;
1064
10.6k
#ifndef TARGET_UNDERSCORE
1065
10.6k
#define TARGET_UNDERSCORE 0
1066
10.6k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
10.6k
        if (strcmp (target_name,
1069
10.6k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
9.63k
    {
1071
      /* Not the name we're looking for */
1072
9.63k
      continue;
1073
9.63k
    }
1074
10.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
55.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
55.0k
    entry->comdat_name = bfd_strdup (symname);
1083
55.0k
  }
1084
1.09M
    }
1085
1086
31.5k
  return true;
1087
31.5k
}
pei-ia64.c:fill_comdat_hash
Line
Count
Source
891
57.8k
{
892
57.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
57.8k
  if (! _bfd_coff_get_external_symbols (abfd))
910
17.0k
    return true;
911
912
40.7k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
40.7k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
40.7k
  for (struct internal_syment isym;
916
1.42M
       esym < esymend;
917
1.38M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.38M
    {
919
1.38M
      char buf[SYMNMLEN + 1];
920
1.38M
      const char *symname;
921
1.38M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.38M
      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.38M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.38M
      if (symname == NULL)
950
455k
  {
951
455k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
455k
            abfd);
953
455k
    continue;
954
455k
  }
955
956
931k
      union internal_auxent aux;
957
958
931k
      struct comdat_hash_entry needle;
959
931k
      needle.target_index = isym.n_scnum;
960
961
931k
      void **slot
962
931k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
931k
      if (slot == NULL)
964
0
  return false;
965
966
931k
      if (*slot == NULL)
967
333k
  {
968
333k
    if (isym.n_numaux != 1)
969
288k
      aux.x_scn.x_comdat = 0;
970
44.5k
    else
971
44.5k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
44.5k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
820
    {
975
      /* xgettext:c-format */
976
820
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
820
          " section '%s' found"),
978
820
              abfd, symname);
979
820
      continue;
980
820
    }
981
43.7k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
43.7k
            isym.n_type, isym.n_sclass, 0,
983
43.7k
            isym.n_numaux, &aux);
984
43.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
332k
    switch (aux.x_scn.x_comdat)
999
332k
      {
1000
1.96k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.96k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.96k
#endif
1006
1.96k
        break;
1007
1008
6
      case IMAGE_COMDAT_SELECT_ANY:
1009
6
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
6
        break;
1011
1012
106
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
106
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
106
        break;
1015
1016
906
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
906
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
906
        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
728
      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
728
        sec_flags &= ~SEC_LINK_ONCE;
1032
728
#endif
1033
728
        break;
1034
1035
328k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
328k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
328k
        break;
1039
332k
      }
1040
1041
332k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
332k
    if (*slot == NULL)
1043
0
      return false;
1044
332k
    struct comdat_hash_entry *newentry = *slot;
1045
332k
    newentry->sec_flags = sec_flags;
1046
332k
    newentry->symname = bfd_strdup (symname);
1047
332k
    newentry->target_index = isym.n_scnum;
1048
332k
    newentry->isym = isym;
1049
332k
    newentry->comdat_symbol = -1;
1050
332k
  }
1051
598k
      else
1052
598k
  {
1053
598k
    struct comdat_hash_entry *entry = *slot;
1054
1055
598k
    if (entry->comdat_symbol != -1)
1056
523k
      continue;
1057
1058
74.9k
    char *target_name = strchr (entry->symname, '$');
1059
74.9k
    if (target_name != NULL)
1060
16.5k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
16.5k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
16.5k
        if (strcmp (target_name,
1069
16.5k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
13.5k
    {
1071
      /* Not the name we're looking for */
1072
13.5k
      continue;
1073
13.5k
    }
1074
16.5k
      }
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
61.4k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
61.4k
    entry->comdat_name = bfd_strdup (symname);
1083
61.4k
  }
1084
931k
    }
1085
1086
40.7k
  return true;
1087
40.7k
}
pei-loongarch64.c:fill_comdat_hash
Line
Count
Source
891
53.1k
{
892
53.1k
  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
53.1k
  if (! _bfd_coff_get_external_symbols (abfd))
910
18.7k
    return true;
911
912
34.4k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
34.4k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
34.4k
  for (struct internal_syment isym;
916
456k
       esym < esymend;
917
421k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
421k
    {
919
421k
      char buf[SYMNMLEN + 1];
920
421k
      const char *symname;
921
421k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
421k
      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
421k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
421k
      if (symname == NULL)
950
127k
  {
951
127k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
127k
            abfd);
953
127k
    continue;
954
127k
  }
955
956
294k
      union internal_auxent aux;
957
958
294k
      struct comdat_hash_entry needle;
959
294k
      needle.target_index = isym.n_scnum;
960
961
294k
      void **slot
962
294k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
294k
      if (slot == NULL)
964
0
  return false;
965
966
294k
      if (*slot == NULL)
967
145k
  {
968
145k
    if (isym.n_numaux != 1)
969
120k
      aux.x_scn.x_comdat = 0;
970
24.9k
    else
971
24.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
24.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.05k
    {
975
      /* xgettext:c-format */
976
1.05k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.05k
          " section '%s' found"),
978
1.05k
              abfd, symname);
979
1.05k
      continue;
980
1.05k
    }
981
23.8k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
23.8k
            isym.n_type, isym.n_sclass, 0,
983
23.8k
            isym.n_numaux, &aux);
984
23.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
144k
    switch (aux.x_scn.x_comdat)
999
144k
      {
1000
1.48k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.48k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.48k
#endif
1006
1.48k
        break;
1007
1008
244
      case IMAGE_COMDAT_SELECT_ANY:
1009
244
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
244
        break;
1011
1012
6
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
6
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
6
        break;
1015
1016
125
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
125
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
125
        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
652
      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
652
        sec_flags &= ~SEC_LINK_ONCE;
1032
652
#endif
1033
652
        break;
1034
1035
141k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
141k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
141k
        break;
1039
144k
      }
1040
1041
144k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
144k
    if (*slot == NULL)
1043
0
      return false;
1044
144k
    struct comdat_hash_entry *newentry = *slot;
1045
144k
    newentry->sec_flags = sec_flags;
1046
144k
    newentry->symname = bfd_strdup (symname);
1047
144k
    newentry->target_index = isym.n_scnum;
1048
144k
    newentry->isym = isym;
1049
144k
    newentry->comdat_symbol = -1;
1050
144k
  }
1051
148k
      else
1052
148k
  {
1053
148k
    struct comdat_hash_entry *entry = *slot;
1054
1055
148k
    if (entry->comdat_symbol != -1)
1056
111k
      continue;
1057
1058
37.5k
    char *target_name = strchr (entry->symname, '$');
1059
37.5k
    if (target_name != NULL)
1060
14.0k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
14.0k
        target_name += 1;
1064
14.0k
#ifndef TARGET_UNDERSCORE
1065
14.0k
#define TARGET_UNDERSCORE 0
1066
14.0k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
14.0k
        if (strcmp (target_name,
1069
14.0k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
12.5k
    {
1071
      /* Not the name we're looking for */
1072
12.5k
      continue;
1073
12.5k
    }
1074
14.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
25.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
25.0k
    entry->comdat_name = bfd_strdup (symname);
1083
25.0k
  }
1084
294k
    }
1085
1086
34.4k
  return true;
1087
34.4k
}
pei-riscv64.c:fill_comdat_hash
Line
Count
Source
891
48.4k
{
892
48.4k
  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
48.4k
  if (! _bfd_coff_get_external_symbols (abfd))
910
16.8k
    return true;
911
912
31.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
31.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
31.5k
  for (struct internal_syment isym;
916
1.21M
       esym < esymend;
917
1.18M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
1.18M
    {
919
1.18M
      char buf[SYMNMLEN + 1];
920
1.18M
      const char *symname;
921
1.18M
      flagword sec_flags = SEC_LINK_ONCE;
922
923
1.18M
      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.18M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
1.18M
      if (symname == NULL)
950
350k
  {
951
350k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
350k
            abfd);
953
350k
    continue;
954
350k
  }
955
956
832k
      union internal_auxent aux;
957
958
832k
      struct comdat_hash_entry needle;
959
832k
      needle.target_index = isym.n_scnum;
960
961
832k
      void **slot
962
832k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
832k
      if (slot == NULL)
964
0
  return false;
965
966
832k
      if (*slot == NULL)
967
247k
  {
968
247k
    if (isym.n_numaux != 1)
969
213k
      aux.x_scn.x_comdat = 0;
970
33.9k
    else
971
33.9k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
33.9k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
783
    {
975
      /* xgettext:c-format */
976
783
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
783
          " section '%s' found"),
978
783
              abfd, symname);
979
783
      continue;
980
783
    }
981
33.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
33.1k
            isym.n_type, isym.n_sclass, 0,
983
33.1k
            isym.n_numaux, &aux);
984
33.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
246k
    switch (aux.x_scn.x_comdat)
999
246k
      {
1000
2.18k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.18k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.18k
#endif
1006
2.18k
        break;
1007
1008
18
      case IMAGE_COMDAT_SELECT_ANY:
1009
18
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
18
        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.45k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.45k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.45k
        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
277
      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
277
        sec_flags &= ~SEC_LINK_ONCE;
1032
277
#endif
1033
277
        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
246k
      }
1040
1041
246k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
246k
    if (*slot == NULL)
1043
0
      return false;
1044
246k
    struct comdat_hash_entry *newentry = *slot;
1045
246k
    newentry->sec_flags = sec_flags;
1046
246k
    newentry->symname = bfd_strdup (symname);
1047
246k
    newentry->target_index = isym.n_scnum;
1048
246k
    newentry->isym = isym;
1049
246k
    newentry->comdat_symbol = -1;
1050
246k
  }
1051
585k
      else
1052
585k
  {
1053
585k
    struct comdat_hash_entry *entry = *slot;
1054
1055
585k
    if (entry->comdat_symbol != -1)
1056
528k
      continue;
1057
1058
56.8k
    char *target_name = strchr (entry->symname, '$');
1059
56.8k
    if (target_name != NULL)
1060
13.4k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
13.4k
        target_name += 1;
1064
13.4k
#ifndef TARGET_UNDERSCORE
1065
13.4k
#define TARGET_UNDERSCORE 0
1066
13.4k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
13.4k
        if (strcmp (target_name,
1069
13.4k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
12.6k
    {
1071
      /* Not the name we're looking for */
1072
12.6k
      continue;
1073
12.6k
    }
1074
13.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
44.2k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
44.2k
    entry->comdat_name = bfd_strdup (symname);
1083
44.2k
  }
1084
832k
    }
1085
1086
31.5k
  return true;
1087
31.5k
}
pe-arm-wince.c:fill_comdat_hash
Line
Count
Source
891
19.6k
{
892
19.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
19.6k
  if (! _bfd_coff_get_external_symbols (abfd))
910
8.38k
    return true;
911
912
11.2k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
11.2k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
11.2k
  for (struct internal_syment isym;
916
240k
       esym < esymend;
917
228k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
228k
    {
919
228k
      char buf[SYMNMLEN + 1];
920
228k
      const char *symname;
921
228k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
228k
      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
228k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
228k
      if (symname == NULL)
950
66.0k
  {
951
66.0k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
66.0k
            abfd);
953
66.0k
    continue;
954
66.0k
  }
955
956
162k
      union internal_auxent aux;
957
958
162k
      struct comdat_hash_entry needle;
959
162k
      needle.target_index = isym.n_scnum;
960
961
162k
      void **slot
962
162k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
162k
      if (slot == NULL)
964
0
  return false;
965
966
162k
      if (*slot == NULL)
967
70.7k
  {
968
70.7k
    if (isym.n_numaux != 1)
969
66.1k
      aux.x_scn.x_comdat = 0;
970
4.66k
    else
971
4.66k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
4.66k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
212
    {
975
      /* xgettext:c-format */
976
212
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
212
          " section '%s' found"),
978
212
              abfd, symname);
979
212
      continue;
980
212
    }
981
4.45k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
4.45k
            isym.n_type, isym.n_sclass, 0,
983
4.45k
            isym.n_numaux, &aux);
984
4.45k
      }
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
70.5k
    switch (aux.x_scn.x_comdat)
999
70.5k
      {
1000
547
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
547
        sec_flags &= ~SEC_LINK_ONCE;
1005
547
#endif
1006
547
        break;
1007
1008
3
      case IMAGE_COMDAT_SELECT_ANY:
1009
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
3
        break;
1011
1012
2
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
2
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
2
        break;
1015
1016
228
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
228
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
228
        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
1
      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
1
        sec_flags &= ~SEC_LINK_ONCE;
1032
1
#endif
1033
1
        break;
1034
1035
69.8k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
69.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
69.8k
        break;
1039
70.5k
      }
1040
1041
70.5k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
70.5k
    if (*slot == NULL)
1043
0
      return false;
1044
70.5k
    struct comdat_hash_entry *newentry = *slot;
1045
70.5k
    newentry->sec_flags = sec_flags;
1046
70.5k
    newentry->symname = bfd_strdup (symname);
1047
70.5k
    newentry->target_index = isym.n_scnum;
1048
70.5k
    newentry->isym = isym;
1049
70.5k
    newentry->comdat_symbol = -1;
1050
70.5k
  }
1051
92.1k
      else
1052
92.1k
  {
1053
92.1k
    struct comdat_hash_entry *entry = *slot;
1054
1055
92.1k
    if (entry->comdat_symbol != -1)
1056
74.3k
      continue;
1057
1058
17.8k
    char *target_name = strchr (entry->symname, '$');
1059
17.8k
    if (target_name != NULL)
1060
4.48k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
4.48k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
4.48k
        if (strcmp (target_name,
1069
4.48k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
3.92k
    {
1071
      /* Not the name we're looking for */
1072
3.92k
      continue;
1073
3.92k
    }
1074
4.48k
      }
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
13.9k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
13.9k
    entry->comdat_name = bfd_strdup (symname);
1083
13.9k
  }
1084
162k
    }
1085
1086
11.2k
  return true;
1087
11.2k
}
pe-arm.c:fill_comdat_hash
Line
Count
Source
891
19.6k
{
892
19.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
19.6k
  if (! _bfd_coff_get_external_symbols (abfd))
910
8.38k
    return true;
911
912
11.2k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
11.2k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
11.2k
  for (struct internal_syment isym;
916
240k
       esym < esymend;
917
228k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
228k
    {
919
228k
      char buf[SYMNMLEN + 1];
920
228k
      const char *symname;
921
228k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
228k
      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
228k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
228k
      if (symname == NULL)
950
66.0k
  {
951
66.0k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
66.0k
            abfd);
953
66.0k
    continue;
954
66.0k
  }
955
956
162k
      union internal_auxent aux;
957
958
162k
      struct comdat_hash_entry needle;
959
162k
      needle.target_index = isym.n_scnum;
960
961
162k
      void **slot
962
162k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
162k
      if (slot == NULL)
964
0
  return false;
965
966
162k
      if (*slot == NULL)
967
70.7k
  {
968
70.7k
    if (isym.n_numaux != 1)
969
66.1k
      aux.x_scn.x_comdat = 0;
970
4.66k
    else
971
4.66k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
4.66k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
212
    {
975
      /* xgettext:c-format */
976
212
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
212
          " section '%s' found"),
978
212
              abfd, symname);
979
212
      continue;
980
212
    }
981
4.45k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
4.45k
            isym.n_type, isym.n_sclass, 0,
983
4.45k
            isym.n_numaux, &aux);
984
4.45k
      }
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
70.5k
    switch (aux.x_scn.x_comdat)
999
70.5k
      {
1000
547
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
547
        sec_flags &= ~SEC_LINK_ONCE;
1005
547
#endif
1006
547
        break;
1007
1008
3
      case IMAGE_COMDAT_SELECT_ANY:
1009
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
3
        break;
1011
1012
2
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
2
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
2
        break;
1015
1016
228
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
228
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
228
        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
1
      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
1
        sec_flags &= ~SEC_LINK_ONCE;
1032
1
#endif
1033
1
        break;
1034
1035
69.8k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
69.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
69.8k
        break;
1039
70.5k
      }
1040
1041
70.5k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
70.5k
    if (*slot == NULL)
1043
0
      return false;
1044
70.5k
    struct comdat_hash_entry *newentry = *slot;
1045
70.5k
    newentry->sec_flags = sec_flags;
1046
70.5k
    newentry->symname = bfd_strdup (symname);
1047
70.5k
    newentry->target_index = isym.n_scnum;
1048
70.5k
    newentry->isym = isym;
1049
70.5k
    newentry->comdat_symbol = -1;
1050
70.5k
  }
1051
92.1k
      else
1052
92.1k
  {
1053
92.1k
    struct comdat_hash_entry *entry = *slot;
1054
1055
92.1k
    if (entry->comdat_symbol != -1)
1056
74.8k
      continue;
1057
1058
17.3k
    char *target_name = strchr (entry->symname, '$');
1059
17.3k
    if (target_name != NULL)
1060
3.95k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
3.95k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
3.95k
        if (strcmp (target_name,
1069
3.95k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
3.10k
    {
1071
      /* Not the name we're looking for */
1072
3.10k
      continue;
1073
3.10k
    }
1074
3.95k
      }
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.2k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
14.2k
    entry->comdat_name = bfd_strdup (symname);
1083
14.2k
  }
1084
162k
    }
1085
1086
11.2k
  return true;
1087
11.2k
}
pe-i386.c:fill_comdat_hash
Line
Count
Source
891
37.7k
{
892
37.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
37.7k
  if (! _bfd_coff_get_external_symbols (abfd))
910
15.6k
    return true;
911
912
22.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
22.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
22.1k
  for (struct internal_syment isym;
916
410k
       esym < esymend;
917
388k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
388k
    {
919
388k
      char buf[SYMNMLEN + 1];
920
388k
      const char *symname;
921
388k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
388k
      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
388k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
388k
      if (symname == NULL)
950
139k
  {
951
139k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
139k
            abfd);
953
139k
    continue;
954
139k
  }
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
101k
  {
968
101k
    if (isym.n_numaux != 1)
969
84.6k
      aux.x_scn.x_comdat = 0;
970
16.8k
    else
971
16.8k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
16.8k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
415
    {
975
      /* xgettext:c-format */
976
415
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
415
          " section '%s' found"),
978
415
              abfd, symname);
979
415
      continue;
980
415
    }
981
16.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
16.4k
            isym.n_type, isym.n_sclass, 0,
983
16.4k
            isym.n_numaux, &aux);
984
16.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
101k
    switch (aux.x_scn.x_comdat)
999
101k
      {
1000
880
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
880
        sec_flags &= ~SEC_LINK_ONCE;
1005
880
#endif
1006
880
        break;
1007
1008
6
      case IMAGE_COMDAT_SELECT_ANY:
1009
6
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
6
        break;
1011
1012
2
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
2
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
2
        break;
1015
1016
427
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
427
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
427
        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
14
      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
14
        sec_flags &= ~SEC_LINK_ONCE;
1032
14
#endif
1033
14
        break;
1034
1035
99.8k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
99.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
99.8k
        break;
1039
101k
      }
1040
1041
101k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
101k
    if (*slot == NULL)
1043
0
      return false;
1044
101k
    struct comdat_hash_entry *newentry = *slot;
1045
101k
    newentry->sec_flags = sec_flags;
1046
101k
    newentry->symname = bfd_strdup (symname);
1047
101k
    newentry->target_index = isym.n_scnum;
1048
101k
    newentry->isym = isym;
1049
101k
    newentry->comdat_symbol = -1;
1050
101k
  }
1051
147k
      else
1052
147k
  {
1053
147k
    struct comdat_hash_entry *entry = *slot;
1054
1055
147k
    if (entry->comdat_symbol != -1)
1056
118k
      continue;
1057
1058
28.8k
    char *target_name = strchr (entry->symname, '$');
1059
28.8k
    if (target_name != NULL)
1060
10.4k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
10.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
10.4k
        if (strcmp (target_name,
1069
10.4k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
9.18k
    {
1071
      /* Not the name we're looking for */
1072
9.18k
      continue;
1073
9.18k
    }
1074
10.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
19.6k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
19.6k
    entry->comdat_name = bfd_strdup (symname);
1083
19.6k
  }
1084
248k
    }
1085
1086
22.1k
  return true;
1087
22.1k
}
pe-mcore.c:fill_comdat_hash
Line
Count
Source
891
39.2k
{
892
39.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
39.2k
  if (! _bfd_coff_get_external_symbols (abfd))
910
13.1k
    return true;
911
912
26.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
26.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
26.1k
  for (struct internal_syment isym;
916
188k
       esym < esymend;
917
161k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
161k
    {
919
161k
      char buf[SYMNMLEN + 1];
920
161k
      const char *symname;
921
161k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
161k
      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
161k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
161k
      if (symname == NULL)
950
49.7k
  {
951
49.7k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
49.7k
            abfd);
953
49.7k
    continue;
954
49.7k
  }
955
956
112k
      union internal_auxent aux;
957
958
112k
      struct comdat_hash_entry needle;
959
112k
      needle.target_index = isym.n_scnum;
960
961
112k
      void **slot
962
112k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
112k
      if (slot == NULL)
964
0
  return false;
965
966
112k
      if (*slot == NULL)
967
52.1k
  {
968
52.1k
    if (isym.n_numaux != 1)
969
44.5k
      aux.x_scn.x_comdat = 0;
970
7.58k
    else
971
7.58k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
7.58k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
714
    {
975
      /* xgettext:c-format */
976
714
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
714
          " section '%s' found"),
978
714
              abfd, symname);
979
714
      continue;
980
714
    }
981
6.87k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
6.87k
            isym.n_type, isym.n_sclass, 0,
983
6.87k
            isym.n_numaux, &aux);
984
6.87k
      }
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
51.3k
    switch (aux.x_scn.x_comdat)
999
51.3k
      {
1000
391
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
391
        sec_flags &= ~SEC_LINK_ONCE;
1005
391
#endif
1006
391
        break;
1007
1008
240
      case IMAGE_COMDAT_SELECT_ANY:
1009
240
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
240
        break;
1011
1012
240
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
240
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
240
        break;
1015
1016
389
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
389
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
389
        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
50.1k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
50.1k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
50.1k
        break;
1039
51.3k
      }
1040
1041
51.3k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
51.3k
    if (*slot == NULL)
1043
0
      return false;
1044
51.3k
    struct comdat_hash_entry *newentry = *slot;
1045
51.3k
    newentry->sec_flags = sec_flags;
1046
51.3k
    newentry->symname = bfd_strdup (symname);
1047
51.3k
    newentry->target_index = isym.n_scnum;
1048
51.3k
    newentry->isym = isym;
1049
51.3k
    newentry->comdat_symbol = -1;
1050
51.3k
  }
1051
60.1k
      else
1052
60.1k
  {
1053
60.1k
    struct comdat_hash_entry *entry = *slot;
1054
1055
60.1k
    if (entry->comdat_symbol != -1)
1056
40.2k
      continue;
1057
1058
19.8k
    char *target_name = strchr (entry->symname, '$');
1059
19.8k
    if (target_name != NULL)
1060
10.3k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
10.3k
        target_name += 1;
1064
10.3k
#ifndef TARGET_UNDERSCORE
1065
10.3k
#define TARGET_UNDERSCORE 0
1066
10.3k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
10.3k
        if (strcmp (target_name,
1069
10.3k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
9.86k
    {
1071
      /* Not the name we're looking for */
1072
9.86k
      continue;
1073
9.86k
    }
1074
10.3k
      }
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
9.97k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
9.97k
    entry->comdat_name = bfd_strdup (symname);
1083
9.97k
  }
1084
112k
    }
1085
1086
26.1k
  return true;
1087
26.1k
}
pe-sh.c:fill_comdat_hash
Line
Count
Source
891
31.3k
{
892
31.3k
  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
31.3k
  if (! _bfd_coff_get_external_symbols (abfd))
910
11.3k
    return true;
911
912
20.0k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
20.0k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
20.0k
  for (struct internal_syment isym;
916
404k
       esym < esymend;
917
384k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
384k
    {
919
384k
      char buf[SYMNMLEN + 1];
920
384k
      const char *symname;
921
384k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
384k
      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
384k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
384k
      if (symname == NULL)
950
107k
  {
951
107k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
107k
            abfd);
953
107k
    continue;
954
107k
  }
955
956
277k
      union internal_auxent aux;
957
958
277k
      struct comdat_hash_entry needle;
959
277k
      needle.target_index = isym.n_scnum;
960
961
277k
      void **slot
962
277k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
277k
      if (slot == NULL)
964
0
  return false;
965
966
277k
      if (*slot == NULL)
967
77.2k
  {
968
77.2k
    if (isym.n_numaux != 1)
969
68.4k
      aux.x_scn.x_comdat = 0;
970
8.79k
    else
971
8.79k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
8.79k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
517
    {
975
      /* xgettext:c-format */
976
517
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
517
          " section '%s' found"),
978
517
              abfd, symname);
979
517
      continue;
980
517
    }
981
8.27k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
8.27k
            isym.n_type, isym.n_sclass, 0,
983
8.27k
            isym.n_numaux, &aux);
984
8.27k
      }
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
76.7k
    switch (aux.x_scn.x_comdat)
999
76.7k
      {
1000
432
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
432
        sec_flags &= ~SEC_LINK_ONCE;
1005
432
#endif
1006
432
        break;
1007
1008
2
      case IMAGE_COMDAT_SELECT_ANY:
1009
2
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
2
        break;
1011
1012
4
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
4
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
4
        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
103
      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
103
        sec_flags &= ~SEC_LINK_ONCE;
1032
103
#endif
1033
103
        break;
1034
1035
75.8k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
75.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
75.8k
        break;
1039
76.7k
      }
1040
1041
76.7k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
76.7k
    if (*slot == NULL)
1043
0
      return false;
1044
76.7k
    struct comdat_hash_entry *newentry = *slot;
1045
76.7k
    newentry->sec_flags = sec_flags;
1046
76.7k
    newentry->symname = bfd_strdup (symname);
1047
76.7k
    newentry->target_index = isym.n_scnum;
1048
76.7k
    newentry->isym = isym;
1049
76.7k
    newentry->comdat_symbol = -1;
1050
76.7k
  }
1051
199k
      else
1052
199k
  {
1053
199k
    struct comdat_hash_entry *entry = *slot;
1054
1055
199k
    if (entry->comdat_symbol != -1)
1056
180k
      continue;
1057
1058
19.3k
    char *target_name = strchr (entry->symname, '$');
1059
19.3k
    if (target_name != NULL)
1060
2.24k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
2.24k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
2.24k
        if (strcmp (target_name,
1069
2.24k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
1.31k
    {
1071
      /* Not the name we're looking for */
1072
1.31k
      continue;
1073
1.31k
    }
1074
2.24k
      }
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
18.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
18.0k
    entry->comdat_name = bfd_strdup (symname);
1083
18.0k
  }
1084
277k
    }
1085
1086
20.0k
  return true;
1087
20.0k
}
pei-arm-wince.c:fill_comdat_hash
Line
Count
Source
891
60.1k
{
892
60.1k
  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
60.1k
  if (! _bfd_coff_get_external_symbols (abfd))
910
23.9k
    return true;
911
912
36.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
36.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
36.1k
  for (struct internal_syment isym;
916
617k
       esym < esymend;
917
581k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
581k
    {
919
581k
      char buf[SYMNMLEN + 1];
920
581k
      const char *symname;
921
581k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
581k
      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
581k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
581k
      if (symname == NULL)
950
172k
  {
951
172k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
172k
            abfd);
953
172k
    continue;
954
172k
  }
955
956
409k
      union internal_auxent aux;
957
958
409k
      struct comdat_hash_entry needle;
959
409k
      needle.target_index = isym.n_scnum;
960
961
409k
      void **slot
962
409k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
409k
      if (slot == NULL)
964
0
  return false;
965
966
409k
      if (*slot == NULL)
967
155k
  {
968
155k
    if (isym.n_numaux != 1)
969
127k
      aux.x_scn.x_comdat = 0;
970
27.5k
    else
971
27.5k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
27.5k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.31k
    {
975
      /* xgettext:c-format */
976
1.31k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.31k
          " section '%s' found"),
978
1.31k
              abfd, symname);
979
1.31k
      continue;
980
1.31k
    }
981
26.2k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
26.2k
            isym.n_type, isym.n_sclass, 0,
983
26.2k
            isym.n_numaux, &aux);
984
26.2k
      }
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
154k
    switch (aux.x_scn.x_comdat)
999
154k
      {
1000
2.45k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.45k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.45k
#endif
1006
2.45k
        break;
1007
1008
19
      case IMAGE_COMDAT_SELECT_ANY:
1009
19
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
19
        break;
1011
1012
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
5
        break;
1015
1016
1.43k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.43k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.43k
        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
13
      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
13
        sec_flags &= ~SEC_LINK_ONCE;
1032
13
#endif
1033
13
        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
154k
      }
1040
1041
154k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
154k
    if (*slot == NULL)
1043
0
      return false;
1044
154k
    struct comdat_hash_entry *newentry = *slot;
1045
154k
    newentry->sec_flags = sec_flags;
1046
154k
    newentry->symname = bfd_strdup (symname);
1047
154k
    newentry->target_index = isym.n_scnum;
1048
154k
    newentry->isym = isym;
1049
154k
    newentry->comdat_symbol = -1;
1050
154k
  }
1051
254k
      else
1052
254k
  {
1053
254k
    struct comdat_hash_entry *entry = *slot;
1054
1055
254k
    if (entry->comdat_symbol != -1)
1056
199k
      continue;
1057
1058
54.7k
    char *target_name = strchr (entry->symname, '$');
1059
54.7k
    if (target_name != NULL)
1060
26.2k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
26.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
26.2k
        if (strcmp (target_name,
1069
26.2k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
23.8k
    {
1071
      /* Not the name we're looking for */
1072
23.8k
      continue;
1073
23.8k
    }
1074
26.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
30.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
30.8k
    entry->comdat_name = bfd_strdup (symname);
1083
30.8k
  }
1084
409k
    }
1085
1086
36.1k
  return true;
1087
36.1k
}
pei-arm.c:fill_comdat_hash
Line
Count
Source
891
70.6k
{
892
70.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
70.6k
  if (! _bfd_coff_get_external_symbols (abfd))
910
30.3k
    return true;
911
912
40.2k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
40.2k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
40.2k
  for (struct internal_syment isym;
916
703k
       esym < esymend;
917
662k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
662k
    {
919
662k
      char buf[SYMNMLEN + 1];
920
662k
      const char *symname;
921
662k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
662k
      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
662k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
662k
      if (symname == NULL)
950
197k
  {
951
197k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
197k
            abfd);
953
197k
    continue;
954
197k
  }
955
956
464k
      union internal_auxent aux;
957
958
464k
      struct comdat_hash_entry needle;
959
464k
      needle.target_index = isym.n_scnum;
960
961
464k
      void **slot
962
464k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
464k
      if (slot == NULL)
964
0
  return false;
965
966
464k
      if (*slot == NULL)
967
176k
  {
968
176k
    if (isym.n_numaux != 1)
969
146k
      aux.x_scn.x_comdat = 0;
970
29.4k
    else
971
29.4k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
29.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
2.16k
    {
975
      /* xgettext:c-format */
976
2.16k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
2.16k
          " section '%s' found"),
978
2.16k
              abfd, symname);
979
2.16k
      continue;
980
2.16k
    }
981
27.2k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
27.2k
            isym.n_type, isym.n_sclass, 0,
983
27.2k
            isym.n_numaux, &aux);
984
27.2k
      }
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
174k
    switch (aux.x_scn.x_comdat)
999
174k
      {
1000
2.46k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
2.46k
        sec_flags &= ~SEC_LINK_ONCE;
1005
2.46k
#endif
1006
2.46k
        break;
1007
1008
24
      case IMAGE_COMDAT_SELECT_ANY:
1009
24
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
24
        break;
1011
1012
9
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
9
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
9
        break;
1015
1016
1.53k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.53k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.53k
        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
148
      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
148
        sec_flags &= ~SEC_LINK_ONCE;
1032
148
#endif
1033
148
        break;
1034
1035
169k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
169k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
169k
        break;
1039
174k
      }
1040
1041
174k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
174k
    if (*slot == NULL)
1043
0
      return false;
1044
174k
    struct comdat_hash_entry *newentry = *slot;
1045
174k
    newentry->sec_flags = sec_flags;
1046
174k
    newentry->symname = bfd_strdup (symname);
1047
174k
    newentry->target_index = isym.n_scnum;
1048
174k
    newentry->isym = isym;
1049
174k
    newentry->comdat_symbol = -1;
1050
174k
  }
1051
288k
      else
1052
288k
  {
1053
288k
    struct comdat_hash_entry *entry = *slot;
1054
1055
288k
    if (entry->comdat_symbol != -1)
1056
235k
      continue;
1057
1058
53.4k
    char *target_name = strchr (entry->symname, '$');
1059
53.4k
    if (target_name != NULL)
1060
20.5k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
20.5k
        target_name += 1;
1064
#ifndef TARGET_UNDERSCORE
1065
#define TARGET_UNDERSCORE 0
1066
#endif
1067
        /* Is this the name we're looking for ?  */
1068
20.5k
        if (strcmp (target_name,
1069
20.5k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
16.8k
    {
1071
      /* Not the name we're looking for */
1072
16.8k
      continue;
1073
16.8k
    }
1074
20.5k
      }
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
36.5k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
36.5k
    entry->comdat_name = bfd_strdup (symname);
1083
36.5k
  }
1084
464k
    }
1085
1086
40.2k
  return true;
1087
40.2k
}
pei-mcore.c:fill_comdat_hash
Line
Count
Source
891
48.1k
{
892
48.1k
  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
48.1k
  if (! _bfd_coff_get_external_symbols (abfd))
910
19.4k
    return true;
911
912
28.7k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
28.7k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
28.7k
  for (struct internal_syment isym;
916
287k
       esym < esymend;
917
258k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
258k
    {
919
258k
      char buf[SYMNMLEN + 1];
920
258k
      const char *symname;
921
258k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
258k
      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
258k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
258k
      if (symname == NULL)
950
81.3k
  {
951
81.3k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
81.3k
            abfd);
953
81.3k
    continue;
954
81.3k
  }
955
956
177k
      union internal_auxent aux;
957
958
177k
      struct comdat_hash_entry needle;
959
177k
      needle.target_index = isym.n_scnum;
960
961
177k
      void **slot
962
177k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
177k
      if (slot == NULL)
964
0
  return false;
965
966
177k
      if (*slot == NULL)
967
84.7k
  {
968
84.7k
    if (isym.n_numaux != 1)
969
73.7k
      aux.x_scn.x_comdat = 0;
970
11.0k
    else
971
11.0k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
11.0k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
1.16k
    {
975
      /* xgettext:c-format */
976
1.16k
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
1.16k
          " section '%s' found"),
978
1.16k
              abfd, symname);
979
1.16k
      continue;
980
1.16k
    }
981
9.86k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
9.86k
            isym.n_type, isym.n_sclass, 0,
983
9.86k
            isym.n_numaux, &aux);
984
9.86k
      }
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
83.5k
    switch (aux.x_scn.x_comdat)
999
83.5k
      {
1000
1.23k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
1.23k
        sec_flags &= ~SEC_LINK_ONCE;
1005
1.23k
#endif
1006
1.23k
        break;
1007
1008
243
      case IMAGE_COMDAT_SELECT_ANY:
1009
243
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
243
        break;
1011
1012
7
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
7
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
7
        break;
1015
1016
432
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
432
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
432
        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
108
      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
108
        sec_flags &= ~SEC_LINK_ONCE;
1032
108
#endif
1033
108
        break;
1034
1035
81.5k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
81.5k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
81.5k
        break;
1039
83.5k
      }
1040
1041
83.5k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
83.5k
    if (*slot == NULL)
1043
0
      return false;
1044
83.5k
    struct comdat_hash_entry *newentry = *slot;
1045
83.5k
    newentry->sec_flags = sec_flags;
1046
83.5k
    newentry->symname = bfd_strdup (symname);
1047
83.5k
    newentry->target_index = isym.n_scnum;
1048
83.5k
    newentry->isym = isym;
1049
83.5k
    newentry->comdat_symbol = -1;
1050
83.5k
  }
1051
92.3k
      else
1052
92.3k
  {
1053
92.3k
    struct comdat_hash_entry *entry = *slot;
1054
1055
92.3k
    if (entry->comdat_symbol != -1)
1056
64.0k
      continue;
1057
1058
28.3k
    char *target_name = strchr (entry->symname, '$');
1059
28.3k
    if (target_name != NULL)
1060
14.2k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
14.2k
        target_name += 1;
1064
14.2k
#ifndef TARGET_UNDERSCORE
1065
14.2k
#define TARGET_UNDERSCORE 0
1066
14.2k
#endif
1067
        /* Is this the name we're looking for ?  */
1068
14.2k
        if (strcmp (target_name,
1069
14.2k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
13.5k
    {
1071
      /* Not the name we're looking for */
1072
13.5k
      continue;
1073
13.5k
    }
1074
14.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
14.8k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
14.8k
    entry->comdat_name = bfd_strdup (symname);
1083
14.8k
  }
1084
177k
    }
1085
1086
28.7k
  return true;
1087
28.7k
}
pei-sh.c:fill_comdat_hash
Line
Count
Source
891
49.4k
{
892
49.4k
  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
49.4k
  if (! _bfd_coff_get_external_symbols (abfd))
910
16.4k
    return true;
911
912
32.9k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
913
32.9k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
914
915
32.9k
  for (struct internal_syment isym;
916
398k
       esym < esymend;
917
365k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
918
365k
    {
919
365k
      char buf[SYMNMLEN + 1];
920
365k
      const char *symname;
921
365k
      flagword sec_flags = SEC_LINK_ONCE;
922
923
365k
      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
365k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
947
948
      /* PR 17512 file: 078-11867-0.004  */
949
365k
      if (symname == NULL)
950
100k
  {
951
100k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
952
100k
            abfd);
953
100k
    continue;
954
100k
  }
955
956
264k
      union internal_auxent aux;
957
958
264k
      struct comdat_hash_entry needle;
959
264k
      needle.target_index = isym.n_scnum;
960
961
264k
      void **slot
962
264k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
963
264k
      if (slot == NULL)
964
0
  return false;
965
966
264k
      if (*slot == NULL)
967
103k
  {
968
103k
    if (isym.n_numaux != 1)
969
88.6k
      aux.x_scn.x_comdat = 0;
970
15.1k
    else
971
15.1k
      {
972
        /* PR 17512: file: e2cfe54f.  */
973
15.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
974
926
    {
975
      /* xgettext:c-format */
976
926
      _bfd_error_handler (_("%pB: warning: no symbol for"
977
926
          " section '%s' found"),
978
926
              abfd, symname);
979
926
      continue;
980
926
    }
981
14.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
982
14.1k
            isym.n_type, isym.n_sclass, 0,
983
14.1k
            isym.n_numaux, &aux);
984
14.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
102k
    switch (aux.x_scn.x_comdat)
999
102k
      {
1000
604
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1001
#ifdef STRICT_PE_FORMAT
1002
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1003
#else
1004
604
        sec_flags &= ~SEC_LINK_ONCE;
1005
604
#endif
1006
604
        break;
1007
1008
140
      case IMAGE_COMDAT_SELECT_ANY:
1009
140
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1010
140
        break;
1011
1012
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1013
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1014
5
        break;
1015
1016
1.86k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1017
        /* Not yet fully implemented ??? */
1018
1.86k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1019
1.86k
        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
238
      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
238
        sec_flags &= ~SEC_LINK_ONCE;
1032
238
#endif
1033
238
        break;
1034
1035
99.9k
      default:  /* 0 means "no symbol" */
1036
        /* debug$F gets this case; other implications ???  */
1037
99.9k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1038
99.9k
        break;
1039
102k
      }
1040
1041
102k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1042
102k
    if (*slot == NULL)
1043
0
      return false;
1044
102k
    struct comdat_hash_entry *newentry = *slot;
1045
102k
    newentry->sec_flags = sec_flags;
1046
102k
    newentry->symname = bfd_strdup (symname);
1047
102k
    newentry->target_index = isym.n_scnum;
1048
102k
    newentry->isym = isym;
1049
102k
    newentry->comdat_symbol = -1;
1050
102k
  }
1051
160k
      else
1052
160k
  {
1053
160k
    struct comdat_hash_entry *entry = *slot;
1054
1055
160k
    if (entry->comdat_symbol != -1)
1056
130k
      continue;
1057
1058
30.2k
    char *target_name = strchr (entry->symname, '$');
1059
30.2k
    if (target_name != NULL)
1060
9.39k
      {
1061
        /* Gas mode: the first matching on partial name.  */
1062
1063
9.39k
        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.39k
        if (strcmp (target_name,
1069
9.39k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1070
7.59k
    {
1071
      /* Not the name we're looking for */
1072
7.59k
      continue;
1073
7.59k
    }
1074
9.39k
      }
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
22.6k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1082
22.6k
    entry->comdat_name = bfd_strdup (symname);
1083
22.6k
  }
1084
264k
    }
1085
1086
32.9k
  return true;
1087
32.9k
}
1088
1089
static bool
1090
insert_coff_comdat_info (bfd *abfd, asection *section, const char *symname,
1091
       long symbol)
1092
28.7k
{
1093
28.7k
  struct coff_comdat_info *comdat;
1094
28.7k
  size_t len = strlen (symname) + 1;
1095
1096
28.7k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
28.7k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
28.7k
  coff_section_data (abfd, section)->comdat = comdat;
1101
28.7k
  comdat->symbol = symbol;
1102
28.7k
  char *newname = (char *) (comdat + 1);
1103
28.7k
  comdat->name = newname;
1104
28.7k
  memcpy (newname, symname, len);
1105
28.7k
  return true;
1106
28.7k
}
pei-i386.c:insert_coff_comdat_info
Line
Count
Source
1092
3.22k
{
1093
3.22k
  struct coff_comdat_info *comdat;
1094
3.22k
  size_t len = strlen (symname) + 1;
1095
1096
3.22k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
3.22k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
3.22k
  coff_section_data (abfd, section)->comdat = comdat;
1101
3.22k
  comdat->symbol = symbol;
1102
3.22k
  char *newname = (char *) (comdat + 1);
1103
3.22k
  comdat->name = newname;
1104
3.22k
  memcpy (newname, symname, len);
1105
3.22k
  return true;
1106
3.22k
}
pe-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1092
1.96k
{
1093
1.96k
  struct coff_comdat_info *comdat;
1094
1.96k
  size_t len = strlen (symname) + 1;
1095
1096
1.96k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.96k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.96k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.96k
  comdat->symbol = symbol;
1102
1.96k
  char *newname = (char *) (comdat + 1);
1103
1.96k
  comdat->name = newname;
1104
1.96k
  memcpy (newname, symname, len);
1105
1.96k
  return true;
1106
1.96k
}
pei-x86_64.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
}
pe-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
573
{
1093
573
  struct coff_comdat_info *comdat;
1094
573
  size_t len = strlen (symname) + 1;
1095
1096
573
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
573
  if (comdat == NULL)
1098
0
    return false;
1099
1100
573
  coff_section_data (abfd, section)->comdat = comdat;
1101
573
  comdat->symbol = symbol;
1102
573
  char *newname = (char *) (comdat + 1);
1103
573
  comdat->name = newname;
1104
573
  memcpy (newname, symname, len);
1105
573
  return true;
1106
573
}
pei-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
2.40k
{
1093
2.40k
  struct coff_comdat_info *comdat;
1094
2.40k
  size_t len = strlen (symname) + 1;
1095
1096
2.40k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
2.40k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
2.40k
  coff_section_data (abfd, section)->comdat = comdat;
1101
2.40k
  comdat->symbol = symbol;
1102
2.40k
  char *newname = (char *) (comdat + 1);
1103
2.40k
  comdat->name = newname;
1104
2.40k
  memcpy (newname, symname, len);
1105
2.40k
  return true;
1106
2.40k
}
pei-ia64.c:insert_coff_comdat_info
Line
Count
Source
1092
2.50k
{
1093
2.50k
  struct coff_comdat_info *comdat;
1094
2.50k
  size_t len = strlen (symname) + 1;
1095
1096
2.50k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
2.50k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
2.50k
  coff_section_data (abfd, section)->comdat = comdat;
1101
2.50k
  comdat->symbol = symbol;
1102
2.50k
  char *newname = (char *) (comdat + 1);
1103
2.50k
  comdat->name = newname;
1104
2.50k
  memcpy (newname, symname, len);
1105
2.50k
  return true;
1106
2.50k
}
pei-loongarch64.c:insert_coff_comdat_info
Line
Count
Source
1092
1.82k
{
1093
1.82k
  struct coff_comdat_info *comdat;
1094
1.82k
  size_t len = strlen (symname) + 1;
1095
1096
1.82k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.82k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.82k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.82k
  comdat->symbol = symbol;
1102
1.82k
  char *newname = (char *) (comdat + 1);
1103
1.82k
  comdat->name = newname;
1104
1.82k
  memcpy (newname, symname, len);
1105
1.82k
  return true;
1106
1.82k
}
pei-riscv64.c:insert_coff_comdat_info
Line
Count
Source
1092
1.12k
{
1093
1.12k
  struct coff_comdat_info *comdat;
1094
1.12k
  size_t len = strlen (symname) + 1;
1095
1096
1.12k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.12k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.12k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.12k
  comdat->symbol = symbol;
1102
1.12k
  char *newname = (char *) (comdat + 1);
1103
1.12k
  comdat->name = newname;
1104
1.12k
  memcpy (newname, symname, len);
1105
1.12k
  return true;
1106
1.12k
}
pe-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1092
748
{
1093
748
  struct coff_comdat_info *comdat;
1094
748
  size_t len = strlen (symname) + 1;
1095
1096
748
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
748
  if (comdat == NULL)
1098
0
    return false;
1099
1100
748
  coff_section_data (abfd, section)->comdat = comdat;
1101
748
  comdat->symbol = symbol;
1102
748
  char *newname = (char *) (comdat + 1);
1103
748
  comdat->name = newname;
1104
748
  memcpy (newname, symname, len);
1105
748
  return true;
1106
748
}
pe-arm.c:insert_coff_comdat_info
Line
Count
Source
1092
748
{
1093
748
  struct coff_comdat_info *comdat;
1094
748
  size_t len = strlen (symname) + 1;
1095
1096
748
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
748
  if (comdat == NULL)
1098
0
    return false;
1099
1100
748
  coff_section_data (abfd, section)->comdat = comdat;
1101
748
  comdat->symbol = symbol;
1102
748
  char *newname = (char *) (comdat + 1);
1103
748
  comdat->name = newname;
1104
748
  memcpy (newname, symname, len);
1105
748
  return true;
1106
748
}
pe-i386.c:insert_coff_comdat_info
Line
Count
Source
1092
777
{
1093
777
  struct coff_comdat_info *comdat;
1094
777
  size_t len = strlen (symname) + 1;
1095
1096
777
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
777
  if (comdat == NULL)
1098
0
    return false;
1099
1100
777
  coff_section_data (abfd, section)->comdat = comdat;
1101
777
  comdat->symbol = symbol;
1102
777
  char *newname = (char *) (comdat + 1);
1103
777
  comdat->name = newname;
1104
777
  memcpy (newname, symname, len);
1105
777
  return true;
1106
777
}
pe-mcore.c:insert_coff_comdat_info
Line
Count
Source
1092
640
{
1093
640
  struct coff_comdat_info *comdat;
1094
640
  size_t len = strlen (symname) + 1;
1095
1096
640
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
640
  if (comdat == NULL)
1098
0
    return false;
1099
1100
640
  coff_section_data (abfd, section)->comdat = comdat;
1101
640
  comdat->symbol = symbol;
1102
640
  char *newname = (char *) (comdat + 1);
1103
640
  comdat->name = newname;
1104
640
  memcpy (newname, symname, len);
1105
640
  return true;
1106
640
}
pe-sh.c:insert_coff_comdat_info
Line
Count
Source
1092
853
{
1093
853
  struct coff_comdat_info *comdat;
1094
853
  size_t len = strlen (symname) + 1;
1095
1096
853
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
853
  if (comdat == NULL)
1098
0
    return false;
1099
1100
853
  coff_section_data (abfd, section)->comdat = comdat;
1101
853
  comdat->symbol = symbol;
1102
853
  char *newname = (char *) (comdat + 1);
1103
853
  comdat->name = newname;
1104
853
  memcpy (newname, symname, len);
1105
853
  return true;
1106
853
}
pei-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1092
2.22k
{
1093
2.22k
  struct coff_comdat_info *comdat;
1094
2.22k
  size_t len = strlen (symname) + 1;
1095
1096
2.22k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
2.22k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
2.22k
  coff_section_data (abfd, section)->comdat = comdat;
1101
2.22k
  comdat->symbol = symbol;
1102
2.22k
  char *newname = (char *) (comdat + 1);
1103
2.22k
  comdat->name = newname;
1104
2.22k
  memcpy (newname, symname, len);
1105
2.22k
  return true;
1106
2.22k
}
pei-arm.c:insert_coff_comdat_info
Line
Count
Source
1092
2.25k
{
1093
2.25k
  struct coff_comdat_info *comdat;
1094
2.25k
  size_t len = strlen (symname) + 1;
1095
1096
2.25k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
2.25k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
2.25k
  coff_section_data (abfd, section)->comdat = comdat;
1101
2.25k
  comdat->symbol = symbol;
1102
2.25k
  char *newname = (char *) (comdat + 1);
1103
2.25k
  comdat->name = newname;
1104
2.25k
  memcpy (newname, symname, len);
1105
2.25k
  return true;
1106
2.25k
}
pei-mcore.c:insert_coff_comdat_info
Line
Count
Source
1092
1.04k
{
1093
1.04k
  struct coff_comdat_info *comdat;
1094
1.04k
  size_t len = strlen (symname) + 1;
1095
1096
1.04k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
1.04k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
1.04k
  coff_section_data (abfd, section)->comdat = comdat;
1101
1.04k
  comdat->symbol = symbol;
1102
1.04k
  char *newname = (char *) (comdat + 1);
1103
1.04k
  comdat->name = newname;
1104
1.04k
  memcpy (newname, symname, len);
1105
1.04k
  return true;
1106
1.04k
}
pei-sh.c:insert_coff_comdat_info
Line
Count
Source
1092
2.80k
{
1093
2.80k
  struct coff_comdat_info *comdat;
1094
2.80k
  size_t len = strlen (symname) + 1;
1095
1096
2.80k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1097
2.80k
  if (comdat == NULL)
1098
0
    return false;
1099
1100
2.80k
  coff_section_data (abfd, section)->comdat = comdat;
1101
2.80k
  comdat->symbol = symbol;
1102
2.80k
  char *newname = (char *) (comdat + 1);
1103
2.80k
  comdat->name = newname;
1104
2.80k
  memcpy (newname, symname, len);
1105
2.80k
  return true;
1106
2.80k
}
1107
1108
static bool
1109
handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
1110
         asection *section)
1111
1.02M
{
1112
1.02M
  if (pe_data (abfd)->comdat_hash == NULL)
1113
727k
    {
1114
727k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
727k
             comdat_delf);
1116
727k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
727k
    }
1119
1120
1.02M
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
850k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
1.02M
  struct comdat_hash_entry *found
1125
1.02M
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
1.02M
  if (found != NULL)
1127
150k
    {
1128
150k
      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
150k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
150k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
62.0k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
62.0k
    _bfd_error_handler
1148
62.0k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
62.0k
       abfd, found->symname);
1150
62.0k
    return false;
1151
62.0k
  }
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
88.2k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
44.1k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
44.1k
            " does not match section name '%s'"),
1161
44.1k
          abfd, found->symname, name);
1162
1163
88.2k
      if (found->comdat_symbol != -1)
1164
28.7k
  {
1165
28.7k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
28.7k
           found->comdat_symbol))
1167
0
      return false;
1168
28.7k
  }
1169
88.2k
      *sec_flags = *sec_flags | found->sec_flags;
1170
88.2k
      return true;
1171
88.2k
    }
1172
877k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
877k
  return true;
1174
1.02M
}
pei-i386.c:handle_COMDAT
Line
Count
Source
1111
76.4k
{
1112
76.4k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
46.1k
    {
1114
46.1k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
46.1k
             comdat_delf);
1116
46.1k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
46.1k
    }
1119
1120
76.4k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
52.1k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
76.4k
  struct comdat_hash_entry *found
1125
76.4k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
76.4k
  if (found != NULL)
1127
12.2k
    {
1128
12.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
12.2k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
12.2k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.13k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.13k
    _bfd_error_handler
1148
3.13k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.13k
       abfd, found->symname);
1150
3.13k
    return false;
1151
3.13k
  }
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.11k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
4.97k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
4.97k
            " does not match section name '%s'"),
1161
4.97k
          abfd, found->symname, name);
1162
1163
9.11k
      if (found->comdat_symbol != -1)
1164
3.22k
  {
1165
3.22k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
3.22k
           found->comdat_symbol))
1167
0
      return false;
1168
3.22k
  }
1169
9.11k
      *sec_flags = *sec_flags | found->sec_flags;
1170
9.11k
      return true;
1171
9.11k
    }
1172
64.2k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
64.2k
  return true;
1174
76.4k
}
pe-x86_64.c:handle_COMDAT
Line
Count
Source
1111
127k
{
1112
127k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
109k
    {
1114
109k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
109k
             comdat_delf);
1116
109k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
109k
    }
1119
1120
127k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
119k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
127k
  struct comdat_hash_entry *found
1125
127k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
127k
  if (found != NULL)
1127
11.8k
    {
1128
11.8k
      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
11.8k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
11.8k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
6.20k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
6.20k
    _bfd_error_handler
1148
6.20k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
6.20k
       abfd, found->symname);
1150
6.20k
    return false;
1151
6.20k
  }
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.60k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.90k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.90k
            " does not match section name '%s'"),
1161
1.90k
          abfd, found->symname, name);
1162
1163
5.60k
      if (found->comdat_symbol != -1)
1164
1.96k
  {
1165
1.96k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.96k
           found->comdat_symbol))
1167
0
      return false;
1168
1.96k
  }
1169
5.60k
      *sec_flags = *sec_flags | found->sec_flags;
1170
5.60k
      return true;
1171
5.60k
    }
1172
116k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
116k
  return true;
1174
127k
}
pei-x86_64.c:handle_COMDAT
Line
Count
Source
1111
84.7k
{
1112
84.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
54.8k
    {
1114
54.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
54.8k
             comdat_delf);
1116
54.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
54.8k
    }
1119
1120
84.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
62.7k
    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
11.9k
    {
1128
11.9k
      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
11.9k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
11.9k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
2.81k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
2.81k
    _bfd_error_handler
1148
2.81k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
2.81k
       abfd, found->symname);
1150
2.81k
    return false;
1151
2.81k
  }
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.14k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
4.86k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
4.86k
            " does not match section name '%s'"),
1161
4.86k
          abfd, found->symname, name);
1162
1163
9.14k
      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.14k
      *sec_flags = *sec_flags | found->sec_flags;
1170
9.14k
      return true;
1171
9.14k
    }
1172
72.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
72.7k
  return true;
1174
84.7k
}
pe-aarch64.c:handle_COMDAT
Line
Count
Source
1111
38.7k
{
1112
38.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
30.0k
    {
1114
30.0k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
30.0k
             comdat_delf);
1116
30.0k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
30.0k
    }
1119
1120
38.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
33.4k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
38.7k
  struct comdat_hash_entry *found
1125
38.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
38.7k
  if (found != NULL)
1127
4.44k
    {
1128
4.44k
      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
4.44k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
4.44k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
989
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
989
    _bfd_error_handler
1148
989
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
989
       abfd, found->symname);
1150
989
    return false;
1151
989
  }
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.46k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.11k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.11k
            " does not match section name '%s'"),
1161
1.11k
          abfd, found->symname, name);
1162
1163
3.46k
      if (found->comdat_symbol != -1)
1164
573
  {
1165
573
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
573
           found->comdat_symbol))
1167
0
      return false;
1168
573
  }
1169
3.46k
      *sec_flags = *sec_flags | found->sec_flags;
1170
3.46k
      return true;
1171
3.46k
    }
1172
34.2k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
34.2k
  return true;
1174
38.7k
}
pei-aarch64.c:handle_COMDAT
Line
Count
Source
1111
66.3k
{
1112
66.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
38.7k
    {
1114
38.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
38.7k
             comdat_delf);
1116
38.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
38.7k
    }
1119
1120
66.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
47.1k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
66.3k
  struct comdat_hash_entry *found
1125
66.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
66.3k
  if (found != NULL)
1127
11.7k
    {
1128
11.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
11.7k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
11.7k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
5.57k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
5.57k
    _bfd_error_handler
1148
5.57k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
5.57k
       abfd, found->symname);
1150
5.57k
    return false;
1151
5.57k
  }
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.16k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
3.47k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
3.47k
            " does not match section name '%s'"),
1161
3.47k
          abfd, found->symname, name);
1162
1163
6.16k
      if (found->comdat_symbol != -1)
1164
2.40k
  {
1165
2.40k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
2.40k
           found->comdat_symbol))
1167
0
      return false;
1168
2.40k
  }
1169
6.16k
      *sec_flags = *sec_flags | found->sec_flags;
1170
6.16k
      return true;
1171
6.16k
    }
1172
54.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
54.6k
  return true;
1174
66.3k
}
pei-ia64.c:handle_COMDAT
Line
Count
Source
1111
66.5k
{
1112
66.5k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
48.5k
    {
1114
48.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
48.5k
             comdat_delf);
1116
48.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
48.5k
    }
1119
1120
66.5k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
57.8k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
66.5k
  struct comdat_hash_entry *found
1125
66.5k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
66.5k
  if (found != NULL)
1127
11.9k
    {
1128
11.9k
      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
11.9k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
11.9k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
6.55k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
6.55k
    _bfd_error_handler
1148
6.55k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
6.55k
       abfd, found->symname);
1150
6.55k
    return false;
1151
6.55k
  }
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.35k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
3.33k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
3.33k
            " does not match section name '%s'"),
1161
3.33k
          abfd, found->symname, name);
1162
1163
5.35k
      if (found->comdat_symbol != -1)
1164
2.50k
  {
1165
2.50k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
2.50k
           found->comdat_symbol))
1167
0
      return false;
1168
2.50k
  }
1169
5.35k
      *sec_flags = *sec_flags | found->sec_flags;
1170
5.35k
      return true;
1171
5.35k
    }
1172
54.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
54.6k
  return true;
1174
66.5k
}
pei-loongarch64.c:handle_COMDAT
Line
Count
Source
1111
58.1k
{
1112
58.1k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
44.7k
    {
1114
44.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
44.7k
             comdat_delf);
1116
44.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
44.7k
    }
1119
1120
58.1k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
53.1k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
58.1k
  struct comdat_hash_entry *found
1125
58.1k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
58.1k
  if (found != NULL)
1127
8.46k
    {
1128
8.46k
      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
8.46k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
8.46k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.60k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.60k
    _bfd_error_handler
1148
3.60k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.60k
       abfd, found->symname);
1150
3.60k
    return false;
1151
3.60k
  }
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.86k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.72k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.72k
            " does not match section name '%s'"),
1161
1.72k
          abfd, found->symname, name);
1162
1163
4.86k
      if (found->comdat_symbol != -1)
1164
1.82k
  {
1165
1.82k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.82k
           found->comdat_symbol))
1167
0
      return false;
1168
1.82k
  }
1169
4.86k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.86k
      return true;
1171
4.86k
    }
1172
49.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
49.6k
  return true;
1174
58.1k
}
pei-riscv64.c:handle_COMDAT
Line
Count
Source
1111
54.0k
{
1112
54.0k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
41.3k
    {
1114
41.3k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
41.3k
             comdat_delf);
1116
41.3k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
41.3k
    }
1119
1120
54.0k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
48.4k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
54.0k
  struct comdat_hash_entry *found
1125
54.0k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
54.0k
  if (found != NULL)
1127
8.56k
    {
1128
8.56k
      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
8.56k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
8.56k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
4.81k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
4.81k
    _bfd_error_handler
1148
4.81k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
4.81k
       abfd, found->symname);
1150
4.81k
    return false;
1151
4.81k
  }
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.75k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.35k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.35k
            " does not match section name '%s'"),
1161
1.35k
          abfd, found->symname, name);
1162
1163
3.75k
      if (found->comdat_symbol != -1)
1164
1.12k
  {
1165
1.12k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.12k
           found->comdat_symbol))
1167
0
      return false;
1168
1.12k
  }
1169
3.75k
      *sec_flags = *sec_flags | found->sec_flags;
1170
3.75k
      return true;
1171
3.75k
    }
1172
45.5k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
45.5k
  return true;
1174
54.0k
}
pe-arm-wince.c:handle_COMDAT
Line
Count
Source
1111
24.3k
{
1112
24.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
16.7k
    {
1114
16.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
16.7k
             comdat_delf);
1116
16.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
16.7k
    }
1119
1120
24.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
19.6k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
24.3k
  struct comdat_hash_entry *found
1125
24.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
24.3k
  if (found != NULL)
1127
4.63k
    {
1128
4.63k
      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
4.63k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
4.63k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
1.81k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
1.81k
    _bfd_error_handler
1148
1.81k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
1.81k
       abfd, found->symname);
1150
1.81k
    return false;
1151
1.81k
  }
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
2.82k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.77k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.77k
            " does not match section name '%s'"),
1161
1.77k
          abfd, found->symname, name);
1162
1163
2.82k
      if (found->comdat_symbol != -1)
1164
748
  {
1165
748
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
748
           found->comdat_symbol))
1167
0
      return false;
1168
748
  }
1169
2.82k
      *sec_flags = *sec_flags | found->sec_flags;
1170
2.82k
      return true;
1171
2.82k
    }
1172
19.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
19.7k
  return true;
1174
24.3k
}
pe-arm.c:handle_COMDAT
Line
Count
Source
1111
24.3k
{
1112
24.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
16.7k
    {
1114
16.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
16.7k
             comdat_delf);
1116
16.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
16.7k
    }
1119
1120
24.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
19.6k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
24.3k
  struct comdat_hash_entry *found
1125
24.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
24.3k
  if (found != NULL)
1127
4.63k
    {
1128
4.63k
      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
4.63k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
4.63k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
1.81k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
1.81k
    _bfd_error_handler
1148
1.81k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
1.81k
       abfd, found->symname);
1150
1.81k
    return false;
1151
1.81k
  }
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
2.82k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.77k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.77k
            " does not match section name '%s'"),
1161
1.77k
          abfd, found->symname, name);
1162
1163
2.82k
      if (found->comdat_symbol != -1)
1164
748
  {
1165
748
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
748
           found->comdat_symbol))
1167
0
      return false;
1168
748
  }
1169
2.82k
      *sec_flags = *sec_flags | found->sec_flags;
1170
2.82k
      return true;
1171
2.82k
    }
1172
19.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
19.7k
  return true;
1174
24.3k
}
pe-i386.c:handle_COMDAT
Line
Count
Source
1111
43.2k
{
1112
43.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
31.8k
    {
1114
31.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
31.8k
             comdat_delf);
1116
31.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
31.8k
    }
1119
1120
43.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
37.7k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
43.2k
  struct comdat_hash_entry *found
1125
43.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
43.2k
  if (found != NULL)
1127
5.30k
    {
1128
5.30k
      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.30k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
5.30k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
2.73k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
2.73k
    _bfd_error_handler
1148
2.73k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
2.73k
       abfd, found->symname);
1150
2.73k
    return false;
1151
2.73k
  }
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
2.57k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.08k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.08k
            " does not match section name '%s'"),
1161
1.08k
          abfd, found->symname, name);
1162
1163
2.57k
      if (found->comdat_symbol != -1)
1164
777
  {
1165
777
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
777
           found->comdat_symbol))
1167
0
      return false;
1168
777
  }
1169
2.57k
      *sec_flags = *sec_flags | found->sec_flags;
1170
2.57k
      return true;
1171
2.57k
    }
1172
37.9k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
37.9k
  return true;
1174
43.2k
}
pe-mcore.c:handle_COMDAT
Line
Count
Source
1111
49.8k
{
1112
49.8k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
31.8k
    {
1114
31.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
31.8k
             comdat_delf);
1116
31.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
31.8k
    }
1119
1120
49.8k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
39.2k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
49.8k
  struct comdat_hash_entry *found
1125
49.8k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
49.8k
  if (found != NULL)
1127
3.71k
    {
1128
3.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
3.71k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
3.71k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
874
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
874
    _bfd_error_handler
1148
874
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
874
       abfd, found->symname);
1150
874
    return false;
1151
874
  }
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
2.84k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.35k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.35k
            " does not match section name '%s'"),
1161
1.35k
          abfd, found->symname, name);
1162
1163
2.84k
      if (found->comdat_symbol != -1)
1164
640
  {
1165
640
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
640
           found->comdat_symbol))
1167
0
      return false;
1168
640
  }
1169
2.84k
      *sec_flags = *sec_flags | found->sec_flags;
1170
2.84k
      return true;
1171
2.84k
    }
1172
46.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
46.1k
  return true;
1174
49.8k
}
pe-sh.c:handle_COMDAT
Line
Count
Source
1111
35.2k
{
1112
35.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
27.2k
    {
1114
27.2k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
27.2k
             comdat_delf);
1116
27.2k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
27.2k
    }
1119
1120
35.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
31.3k
    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
4.51k
    {
1128
4.51k
      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
4.51k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
4.51k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
1.76k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
1.76k
    _bfd_error_handler
1148
1.76k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
1.76k
       abfd, found->symname);
1150
1.76k
    return false;
1151
1.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
2.75k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
1.37k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
1.37k
            " does not match section name '%s'"),
1161
1.37k
          abfd, found->symname, name);
1162
1163
2.75k
      if (found->comdat_symbol != -1)
1164
853
  {
1165
853
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
853
           found->comdat_symbol))
1167
0
      return false;
1168
853
  }
1169
2.75k
      *sec_flags = *sec_flags | found->sec_flags;
1170
2.75k
      return true;
1171
2.75k
    }
1172
30.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
30.7k
  return true;
1174
35.2k
}
pei-arm-wince.c:handle_COMDAT
Line
Count
Source
1111
70.8k
{
1112
70.8k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
50.9k
    {
1114
50.9k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
50.9k
             comdat_delf);
1116
50.9k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
50.9k
    }
1119
1120
70.8k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
60.1k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
70.8k
  struct comdat_hash_entry *found
1125
70.8k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
70.8k
  if (found != NULL)
1127
11.2k
    {
1128
11.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
11.2k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
11.2k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
5.41k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
5.41k
    _bfd_error_handler
1148
5.41k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
5.41k
       abfd, found->symname);
1150
5.41k
    return false;
1151
5.41k
  }
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.88k
      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
5.88k
      if (found->comdat_symbol != -1)
1164
2.22k
  {
1165
2.22k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
2.22k
           found->comdat_symbol))
1167
0
      return false;
1168
2.22k
  }
1169
5.88k
      *sec_flags = *sec_flags | found->sec_flags;
1170
5.88k
      return true;
1171
5.88k
    }
1172
59.5k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
59.5k
  return true;
1174
70.8k
}
pei-arm.c:handle_COMDAT
Line
Count
Source
1111
81.6k
{
1112
81.6k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
59.8k
    {
1114
59.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
59.8k
             comdat_delf);
1116
59.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
59.8k
    }
1119
1120
81.6k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
70.6k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
81.6k
  struct comdat_hash_entry *found
1125
81.6k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
81.6k
  if (found != NULL)
1127
12.5k
    {
1128
12.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
12.5k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
12.5k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
5.97k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
5.97k
    _bfd_error_handler
1148
5.97k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
5.97k
       abfd, found->symname);
1150
5.97k
    return false;
1151
5.97k
  }
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.59k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
2.89k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
2.89k
            " does not match section name '%s'"),
1161
2.89k
          abfd, found->symname, name);
1162
1163
6.59k
      if (found->comdat_symbol != -1)
1164
2.25k
  {
1165
2.25k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
2.25k
           found->comdat_symbol))
1167
0
      return false;
1168
2.25k
  }
1169
6.59k
      *sec_flags = *sec_flags | found->sec_flags;
1170
6.59k
      return true;
1171
6.59k
    }
1172
69.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
69.1k
  return true;
1174
81.6k
}
pei-mcore.c:handle_COMDAT
Line
Count
Source
1111
57.0k
{
1112
57.0k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
38.3k
    {
1114
38.3k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
38.3k
             comdat_delf);
1116
38.3k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
38.3k
    }
1119
1120
57.0k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
48.1k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
57.0k
  struct comdat_hash_entry *found
1125
57.0k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
57.0k
  if (found != NULL)
1127
8.51k
    {
1128
8.51k
      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
8.51k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
8.51k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
3.69k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
3.69k
    _bfd_error_handler
1148
3.69k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
3.69k
       abfd, found->symname);
1150
3.69k
    return false;
1151
3.69k
  }
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.82k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
2.54k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
2.54k
            " does not match section name '%s'"),
1161
2.54k
          abfd, found->symname, name);
1162
1163
4.82k
      if (found->comdat_symbol != -1)
1164
1.04k
  {
1165
1.04k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
1.04k
           found->comdat_symbol))
1167
0
      return false;
1168
1.04k
  }
1169
4.82k
      *sec_flags = *sec_flags | found->sec_flags;
1170
4.82k
      return true;
1171
4.82k
    }
1172
48.5k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
48.5k
  return true;
1174
57.0k
}
pei-sh.c:handle_COMDAT
Line
Count
Source
1111
67.7k
{
1112
67.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1113
39.7k
    {
1114
39.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1115
39.7k
             comdat_delf);
1116
39.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1117
0
  return false;
1118
39.7k
    }
1119
1120
67.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1121
49.4k
    if (! fill_comdat_hash (abfd))
1122
0
      return false;
1123
1124
67.7k
  struct comdat_hash_entry *found
1125
67.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1126
67.7k
  if (found != NULL)
1127
13.9k
    {
1128
13.9k
      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
13.9k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1143
13.9k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1144
4.32k
  {
1145
    /* Malformed input files can trigger this test.
1146
       cf PR 21781.  */
1147
4.32k
    _bfd_error_handler
1148
4.32k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1149
4.32k
       abfd, found->symname);
1150
4.32k
    return false;
1151
4.32k
  }
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.67k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1158
  /* xgettext:c-format */
1159
5.72k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1160
5.72k
            " does not match section name '%s'"),
1161
5.72k
          abfd, found->symname, name);
1162
1163
9.67k
      if (found->comdat_symbol != -1)
1164
2.80k
  {
1165
2.80k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1166
2.80k
           found->comdat_symbol))
1167
0
      return false;
1168
2.80k
  }
1169
9.67k
      *sec_flags = *sec_flags | found->sec_flags;
1170
9.67k
      return true;
1171
9.67k
    }
1172
53.7k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1173
53.7k
  return true;
1174
67.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
3.77M
{
1193
3.77M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
3.77M
  unsigned long styp_flags = internal_s->s_flags;
1195
3.77M
  flagword sec_flags;
1196
3.77M
  bool result = true;
1197
3.77M
  bool is_dbg = false;
1198
1199
3.77M
  if (startswith (name, DOT_DEBUG)
1200
3.77M
      || startswith (name, DOT_ZDEBUG)
1201
3.77M
#ifdef COFF_LONG_SECTION_NAMES
1202
3.77M
      || startswith (name, GNU_LINKONCE_WI)
1203
3.77M
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
3.77M
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
3.77M
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
3.77M
      || startswith (name, GNU_DEBUGLINK)
1208
3.77M
      || startswith (name, GNU_DEBUGALTLINK)
1209
3.77M
#endif
1210
3.77M
      || startswith (name, ".stab"))
1211
216k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
3.77M
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
3.77M
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
2.93M
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
26.6M
  while (styp_flags)
1221
22.8M
    {
1222
22.8M
      unsigned long flag = styp_flags & - styp_flags;
1223
22.8M
      char * unhandled = NULL;
1224
1225
22.8M
      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
22.8M
      switch (flag)
1232
22.8M
  {
1233
331k
  case STYP_DSECT:
1234
331k
    unhandled = "STYP_DSECT";
1235
331k
    break;
1236
319k
  case STYP_GROUP:
1237
319k
    unhandled = "STYP_GROUP";
1238
319k
    break;
1239
363k
  case STYP_COPY:
1240
363k
    unhandled = "STYP_COPY";
1241
363k
    break;
1242
349k
  case STYP_OVER:
1243
349k
    unhandled = "STYP_OVER";
1244
349k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
723k
  case STYP_NOLOAD:
1247
723k
    sec_flags |= SEC_NEVER_LOAD;
1248
723k
    break;
1249
0
#endif
1250
837k
  case IMAGE_SCN_MEM_READ:
1251
837k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
837k
    break;
1253
676k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
676k
    break;
1256
354k
  case IMAGE_SCN_LNK_OTHER:
1257
354k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
354k
    break;
1259
320k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
320k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
320k
    break;
1262
839k
  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
839k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
839k
        " %s in section %s"),
1269
839k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
839k
    break;
1271
1.02M
  case IMAGE_SCN_MEM_EXECUTE:
1272
1.02M
    sec_flags |= SEC_CODE;
1273
1.02M
    break;
1274
686k
  case IMAGE_SCN_MEM_WRITE:
1275
686k
    sec_flags &= ~ SEC_READONLY;
1276
686k
    break;
1277
982k
  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
982k
       if (is_dbg
1284
982k
#ifdef _COMMENT
1285
982k
        || strcmp (name, _COMMENT) == 0
1286
982k
#endif
1287
982k
        )
1288
120k
      {
1289
120k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
120k
      }
1291
982k
    break;
1292
685k
  case IMAGE_SCN_MEM_SHARED:
1293
685k
    sec_flags |= SEC_COFF_SHARED;
1294
685k
    break;
1295
912k
  case IMAGE_SCN_LNK_REMOVE:
1296
912k
    if (!is_dbg)
1297
821k
      sec_flags |= SEC_EXCLUDE;
1298
912k
    break;
1299
860k
  case IMAGE_SCN_CNT_CODE:
1300
860k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
860k
    break;
1302
656k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
656k
    if (is_dbg)
1304
69.6k
      sec_flags |= SEC_DEBUGGING;
1305
586k
    else
1306
586k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
656k
    break;
1308
563k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
563k
    sec_flags |= SEC_ALLOC;
1310
563k
    break;
1311
910k
  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
836k
    sec_flags |= SEC_DEBUGGING;
1320
#endif
1321
910k
    break;
1322
1.02M
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
1.02M
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
62.0k
      result = false;
1326
1.02M
    break;
1327
9.46M
  default:
1328
    /* Silently ignore for now.  */
1329
9.46M
    break;
1330
22.8M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
22.8M
      if (unhandled != NULL)
1334
2.03M
  {
1335
2.03M
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
2.03M
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
2.03M
       abfd, name, unhandled, flag);
1339
2.03M
    result = false;
1340
2.03M
  }
1341
22.8M
    }
1342
1343
3.77M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
3.77M
      && (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
1.35M
  if (startswith (name, ".gnu.linkonce"))
1356
2.42k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
#endif
1358
1359
3.77M
  if (flags_ptr)
1360
3.77M
    * flags_ptr = sec_flags;
1361
1362
3.77M
  return result;
1363
3.77M
}
pei-i386.c:styp_to_sec_flags
Line
Count
Source
1192
301k
{
1193
301k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
301k
  unsigned long styp_flags = internal_s->s_flags;
1195
301k
  flagword sec_flags;
1196
301k
  bool result = true;
1197
301k
  bool is_dbg = false;
1198
1199
301k
  if (startswith (name, DOT_DEBUG)
1200
301k
      || startswith (name, DOT_ZDEBUG)
1201
301k
#ifdef COFF_LONG_SECTION_NAMES
1202
301k
      || startswith (name, GNU_LINKONCE_WI)
1203
301k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
301k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
301k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
301k
      || startswith (name, GNU_DEBUGLINK)
1208
301k
      || startswith (name, GNU_DEBUGALTLINK)
1209
301k
#endif
1210
301k
      || startswith (name, ".stab"))
1211
15.9k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
301k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
301k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
239k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.91M
  while (styp_flags)
1221
1.61M
    {
1222
1.61M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.61M
      char * unhandled = NULL;
1224
1225
1.61M
      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.61M
      switch (flag)
1232
1.61M
  {
1233
16.4k
  case STYP_DSECT:
1234
16.4k
    unhandled = "STYP_DSECT";
1235
16.4k
    break;
1236
15.3k
  case STYP_GROUP:
1237
15.3k
    unhandled = "STYP_GROUP";
1238
15.3k
    break;
1239
18.1k
  case STYP_COPY:
1240
18.1k
    unhandled = "STYP_COPY";
1241
18.1k
    break;
1242
20.3k
  case STYP_OVER:
1243
20.3k
    unhandled = "STYP_OVER";
1244
20.3k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
42.6k
  case STYP_NOLOAD:
1247
42.6k
    sec_flags |= SEC_NEVER_LOAD;
1248
42.6k
    break;
1249
0
#endif
1250
61.4k
  case IMAGE_SCN_MEM_READ:
1251
61.4k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
61.4k
    break;
1253
42.1k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
42.1k
    break;
1256
16.5k
  case IMAGE_SCN_LNK_OTHER:
1257
16.5k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
16.5k
    break;
1259
15.0k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
15.0k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
15.0k
    break;
1262
57.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
57.2k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
57.2k
        " %s in section %s"),
1269
57.2k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
57.2k
    break;
1271
100k
  case IMAGE_SCN_MEM_EXECUTE:
1272
100k
    sec_flags |= SEC_CODE;
1273
100k
    break;
1274
75.6k
  case IMAGE_SCN_MEM_WRITE:
1275
75.6k
    sec_flags &= ~ SEC_READONLY;
1276
75.6k
    break;
1277
70.2k
  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
70.2k
       if (is_dbg
1284
70.2k
#ifdef _COMMENT
1285
70.2k
        || strcmp (name, _COMMENT) == 0
1286
70.2k
#endif
1287
70.2k
        )
1288
9.08k
      {
1289
9.08k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
9.08k
      }
1291
70.2k
    break;
1292
46.8k
  case IMAGE_SCN_MEM_SHARED:
1293
46.8k
    sec_flags |= SEC_COFF_SHARED;
1294
46.8k
    break;
1295
65.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
65.2k
    if (!is_dbg)
1297
59.0k
      sec_flags |= SEC_EXCLUDE;
1298
65.2k
    break;
1299
61.2k
  case IMAGE_SCN_CNT_CODE:
1300
61.2k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
61.2k
    break;
1302
46.9k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
46.9k
    if (is_dbg)
1304
5.83k
      sec_flags |= SEC_DEBUGGING;
1305
41.1k
    else
1306
41.1k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
46.9k
    break;
1308
39.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
39.7k
    sec_flags |= SEC_ALLOC;
1310
39.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
76.4k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
76.4k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.13k
      result = false;
1326
76.4k
    break;
1327
672k
  default:
1328
    /* Silently ignore for now.  */
1329
672k
    break;
1330
1.61M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.61M
      if (unhandled != NULL)
1334
101k
  {
1335
101k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
101k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
101k
       abfd, name, unhandled, flag);
1339
101k
    result = false;
1340
101k
  }
1341
1.61M
    }
1342
1343
301k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
301k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
301k
#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
301k
  if (startswith (name, ".gnu.linkonce"))
1356
83
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
301k
#endif
1358
1359
301k
  if (flags_ptr)
1360
301k
    * flags_ptr = sec_flags;
1361
1362
301k
  return result;
1363
301k
}
pe-x86_64.c:styp_to_sec_flags
Line
Count
Source
1192
642k
{
1193
642k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
642k
  unsigned long styp_flags = internal_s->s_flags;
1195
642k
  flagword sec_flags;
1196
642k
  bool result = true;
1197
642k
  bool is_dbg = false;
1198
1199
642k
  if (startswith (name, DOT_DEBUG)
1200
642k
      || startswith (name, DOT_ZDEBUG)
1201
642k
#ifdef COFF_LONG_SECTION_NAMES
1202
642k
      || startswith (name, GNU_LINKONCE_WI)
1203
642k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
642k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
642k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
642k
      || startswith (name, GNU_DEBUGLINK)
1208
642k
      || startswith (name, GNU_DEBUGALTLINK)
1209
642k
#endif
1210
642k
      || startswith (name, ".stab"))
1211
31.5k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
642k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
642k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
554k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
3.65M
  while (styp_flags)
1221
3.00M
    {
1222
3.00M
      unsigned long flag = styp_flags & - styp_flags;
1223
3.00M
      char * unhandled = NULL;
1224
1225
3.00M
      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
3.00M
      switch (flag)
1232
3.00M
  {
1233
58.7k
  case STYP_DSECT:
1234
58.7k
    unhandled = "STYP_DSECT";
1235
58.7k
    break;
1236
59.2k
  case STYP_GROUP:
1237
59.2k
    unhandled = "STYP_GROUP";
1238
59.2k
    break;
1239
67.4k
  case STYP_COPY:
1240
67.4k
    unhandled = "STYP_COPY";
1241
67.4k
    break;
1242
56.1k
  case STYP_OVER:
1243
56.1k
    unhandled = "STYP_OVER";
1244
56.1k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
126k
  case STYP_NOLOAD:
1247
126k
    sec_flags |= SEC_NEVER_LOAD;
1248
126k
    break;
1249
0
#endif
1250
88.2k
  case IMAGE_SCN_MEM_READ:
1251
88.2k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
88.2k
    break;
1253
111k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
111k
    break;
1256
63.3k
  case IMAGE_SCN_LNK_OTHER:
1257
63.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
63.3k
    break;
1259
52.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
52.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
52.2k
    break;
1262
124k
  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
124k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
124k
        " %s in section %s"),
1269
124k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
124k
    break;
1271
112k
  case IMAGE_SCN_MEM_EXECUTE:
1272
112k
    sec_flags |= SEC_CODE;
1273
112k
    break;
1274
67.9k
  case IMAGE_SCN_MEM_WRITE:
1275
67.9k
    sec_flags &= ~ SEC_READONLY;
1276
67.9k
    break;
1277
135k
  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
135k
       if (is_dbg
1284
135k
#ifdef _COMMENT
1285
135k
        || strcmp (name, _COMMENT) == 0
1286
135k
#endif
1287
135k
        )
1288
11.8k
      {
1289
11.8k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
11.8k
      }
1291
135k
    break;
1292
98.0k
  case IMAGE_SCN_MEM_SHARED:
1293
98.0k
    sec_flags |= SEC_COFF_SHARED;
1294
98.0k
    break;
1295
119k
  case IMAGE_SCN_LNK_REMOVE:
1296
119k
    if (!is_dbg)
1297
111k
      sec_flags |= SEC_EXCLUDE;
1298
119k
    break;
1299
109k
  case IMAGE_SCN_CNT_CODE:
1300
109k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
109k
    break;
1302
79.7k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
79.7k
    if (is_dbg)
1304
6.21k
      sec_flags |= SEC_DEBUGGING;
1305
73.5k
    else
1306
73.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
79.7k
    break;
1308
61.3k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
61.3k
    sec_flags |= SEC_ALLOC;
1310
61.3k
    break;
1311
130k
  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
130k
#ifdef COFF_PAGE_SIZE
1319
130k
    sec_flags |= SEC_DEBUGGING;
1320
130k
#endif
1321
130k
    break;
1322
127k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
127k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
6.20k
      result = false;
1326
127k
    break;
1327
1.15M
  default:
1328
    /* Silently ignore for now.  */
1329
1.15M
    break;
1330
3.00M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
3.00M
      if (unhandled != NULL)
1334
357k
  {
1335
357k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
357k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
357k
       abfd, name, unhandled, flag);
1339
357k
    result = false;
1340
357k
  }
1341
3.00M
    }
1342
1343
642k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
642k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
642k
#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
642k
  if (startswith (name, ".gnu.linkonce"))
1356
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
642k
#endif
1358
1359
642k
  if (flags_ptr)
1360
642k
    * flags_ptr = sec_flags;
1361
1362
642k
  return result;
1363
642k
}
pei-x86_64.c:styp_to_sec_flags
Line
Count
Source
1192
286k
{
1193
286k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
286k
  unsigned long styp_flags = internal_s->s_flags;
1195
286k
  flagword sec_flags;
1196
286k
  bool result = true;
1197
286k
  bool is_dbg = false;
1198
1199
286k
  if (startswith (name, DOT_DEBUG)
1200
286k
      || startswith (name, DOT_ZDEBUG)
1201
286k
#ifdef COFF_LONG_SECTION_NAMES
1202
286k
      || startswith (name, GNU_LINKONCE_WI)
1203
286k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
286k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
286k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
286k
      || startswith (name, GNU_DEBUGLINK)
1208
286k
      || startswith (name, GNU_DEBUGALTLINK)
1209
286k
#endif
1210
286k
      || startswith (name, ".stab"))
1211
27.8k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
286k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
286k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
220k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.83M
  while (styp_flags)
1221
1.55M
    {
1222
1.55M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.55M
      char * unhandled = NULL;
1224
1225
1.55M
      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.55M
      switch (flag)
1232
1.55M
  {
1233
16.0k
  case STYP_DSECT:
1234
16.0k
    unhandled = "STYP_DSECT";
1235
16.0k
    break;
1236
14.2k
  case STYP_GROUP:
1237
14.2k
    unhandled = "STYP_GROUP";
1238
14.2k
    break;
1239
18.0k
  case STYP_COPY:
1240
18.0k
    unhandled = "STYP_COPY";
1241
18.0k
    break;
1242
16.5k
  case STYP_OVER:
1243
16.5k
    unhandled = "STYP_OVER";
1244
16.5k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
45.5k
  case STYP_NOLOAD:
1247
45.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
45.5k
    break;
1249
0
#endif
1250
66.0k
  case IMAGE_SCN_MEM_READ:
1251
66.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
66.0k
    break;
1253
33.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
33.3k
    break;
1256
15.7k
  case IMAGE_SCN_LNK_OTHER:
1257
15.7k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
15.7k
    break;
1259
15.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
15.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
15.9k
    break;
1262
61.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
61.3k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
61.3k
        " %s in section %s"),
1269
61.3k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
61.3k
    break;
1271
66.0k
  case IMAGE_SCN_MEM_EXECUTE:
1272
66.0k
    sec_flags |= SEC_CODE;
1273
66.0k
    break;
1274
34.6k
  case IMAGE_SCN_MEM_WRITE:
1275
34.6k
    sec_flags &= ~ SEC_READONLY;
1276
34.6k
    break;
1277
77.2k
  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
77.2k
       if (is_dbg
1284
77.2k
#ifdef _COMMENT
1285
77.2k
        || strcmp (name, _COMMENT) == 0
1286
77.2k
#endif
1287
77.2k
        )
1288
17.3k
      {
1289
17.3k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
17.3k
      }
1291
77.2k
    break;
1292
47.7k
  case IMAGE_SCN_MEM_SHARED:
1293
47.7k
    sec_flags |= SEC_COFF_SHARED;
1294
47.7k
    break;
1295
73.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
73.9k
    if (!is_dbg)
1297
56.7k
      sec_flags |= SEC_EXCLUDE;
1298
73.9k
    break;
1299
69.3k
  case IMAGE_SCN_CNT_CODE:
1300
69.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
69.3k
    break;
1302
38.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
38.6k
    if (is_dbg)
1304
6.95k
      sec_flags |= SEC_DEBUGGING;
1305
31.6k
    else
1306
31.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
38.6k
    break;
1308
29.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
29.9k
    sec_flags |= SEC_ALLOC;
1310
29.9k
    break;
1311
74.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
74.2k
#ifdef COFF_PAGE_SIZE
1319
74.2k
    sec_flags |= SEC_DEBUGGING;
1320
74.2k
#endif
1321
74.2k
    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
2.81k
      result = false;
1326
84.7k
    break;
1327
654k
  default:
1328
    /* Silently ignore for now.  */
1329
654k
    break;
1330
1.55M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.55M
      if (unhandled != NULL)
1334
96.5k
  {
1335
96.5k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
96.5k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
96.5k
       abfd, name, unhandled, flag);
1339
96.5k
    result = false;
1340
96.5k
  }
1341
1.55M
    }
1342
1343
286k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
286k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
286k
#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
286k
  if (startswith (name, ".gnu.linkonce"))
1356
300
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
286k
#endif
1358
1359
286k
  if (flags_ptr)
1360
286k
    * flags_ptr = sec_flags;
1361
1362
286k
  return result;
1363
286k
}
pe-aarch64.c:styp_to_sec_flags
Line
Count
Source
1192
197k
{
1193
197k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
197k
  unsigned long styp_flags = internal_s->s_flags;
1195
197k
  flagword sec_flags;
1196
197k
  bool result = true;
1197
197k
  bool is_dbg = false;
1198
1199
197k
  if (startswith (name, DOT_DEBUG)
1200
197k
      || startswith (name, DOT_ZDEBUG)
1201
197k
#ifdef COFF_LONG_SECTION_NAMES
1202
197k
      || startswith (name, GNU_LINKONCE_WI)
1203
197k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
197k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
197k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
197k
      || startswith (name, GNU_DEBUGLINK)
1208
197k
      || startswith (name, GNU_DEBUGALTLINK)
1209
197k
#endif
1210
197k
      || startswith (name, ".stab"))
1211
5.23k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
197k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
197k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
166k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
963k
  while (styp_flags)
1221
766k
    {
1222
766k
      unsigned long flag = styp_flags & - styp_flags;
1223
766k
      char * unhandled = NULL;
1224
1225
766k
      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
766k
      switch (flag)
1232
766k
  {
1233
7.71k
  case STYP_DSECT:
1234
7.71k
    unhandled = "STYP_DSECT";
1235
7.71k
    break;
1236
7.95k
  case STYP_GROUP:
1237
7.95k
    unhandled = "STYP_GROUP";
1238
7.95k
    break;
1239
8.00k
  case STYP_COPY:
1240
8.00k
    unhandled = "STYP_COPY";
1241
8.00k
    break;
1242
8.35k
  case STYP_OVER:
1243
8.35k
    unhandled = "STYP_OVER";
1244
8.35k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
23.2k
  case STYP_NOLOAD:
1247
23.2k
    sec_flags |= SEC_NEVER_LOAD;
1248
23.2k
    break;
1249
0
#endif
1250
30.2k
  case IMAGE_SCN_MEM_READ:
1251
30.2k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
30.2k
    break;
1253
22.2k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
22.2k
    break;
1256
7.89k
  case IMAGE_SCN_LNK_OTHER:
1257
7.89k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
7.89k
    break;
1259
7.07k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
7.07k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
7.07k
    break;
1262
28.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
28.2k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
28.2k
        " %s in section %s"),
1269
28.2k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
28.2k
    break;
1271
39.4k
  case IMAGE_SCN_MEM_EXECUTE:
1272
39.4k
    sec_flags |= SEC_CODE;
1273
39.4k
    break;
1274
22.5k
  case IMAGE_SCN_MEM_WRITE:
1275
22.5k
    sec_flags &= ~ SEC_READONLY;
1276
22.5k
    break;
1277
32.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
32.3k
       if (is_dbg
1284
32.3k
#ifdef _COMMENT
1285
32.3k
        || strcmp (name, _COMMENT) == 0
1286
32.3k
#endif
1287
32.3k
        )
1288
2.89k
      {
1289
2.89k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
2.89k
      }
1291
32.3k
    break;
1292
21.1k
  case IMAGE_SCN_MEM_SHARED:
1293
21.1k
    sec_flags |= SEC_COFF_SHARED;
1294
21.1k
    break;
1295
22.3k
  case IMAGE_SCN_LNK_REMOVE:
1296
22.3k
    if (!is_dbg)
1297
20.6k
      sec_flags |= SEC_EXCLUDE;
1298
22.3k
    break;
1299
28.9k
  case IMAGE_SCN_CNT_CODE:
1300
28.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
28.9k
    break;
1302
18.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
18.0k
    if (is_dbg)
1304
1.21k
      sec_flags |= SEC_DEBUGGING;
1305
16.8k
    else
1306
16.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
18.0k
    break;
1308
19.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
19.6k
    sec_flags |= SEC_ALLOC;
1310
19.6k
    break;
1311
30.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
30.6k
#ifdef COFF_PAGE_SIZE
1319
30.6k
    sec_flags |= SEC_DEBUGGING;
1320
30.6k
#endif
1321
30.6k
    break;
1322
38.7k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
38.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
989
      result = false;
1326
38.7k
    break;
1327
341k
  default:
1328
    /* Silently ignore for now.  */
1329
341k
    break;
1330
766k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
766k
      if (unhandled != NULL)
1334
47.0k
  {
1335
47.0k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
47.0k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
47.0k
       abfd, name, unhandled, flag);
1339
47.0k
    result = false;
1340
47.0k
  }
1341
766k
    }
1342
1343
197k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
197k
      && (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
197k
  if (flags_ptr)
1360
197k
    * flags_ptr = sec_flags;
1361
1362
197k
  return result;
1363
197k
}
pei-aarch64.c:styp_to_sec_flags
Line
Count
Source
1192
258k
{
1193
258k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
258k
  unsigned long styp_flags = internal_s->s_flags;
1195
258k
  flagword sec_flags;
1196
258k
  bool result = true;
1197
258k
  bool is_dbg = false;
1198
1199
258k
  if (startswith (name, DOT_DEBUG)
1200
258k
      || startswith (name, DOT_ZDEBUG)
1201
258k
#ifdef COFF_LONG_SECTION_NAMES
1202
258k
      || startswith (name, GNU_LINKONCE_WI)
1203
258k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
258k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
258k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
258k
      || startswith (name, GNU_DEBUGLINK)
1208
258k
      || startswith (name, GNU_DEBUGALTLINK)
1209
258k
#endif
1210
258k
      || startswith (name, ".stab"))
1211
7.47k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
258k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
258k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
198k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.59M
  while (styp_flags)
1221
1.34M
    {
1222
1.34M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.34M
      char * unhandled = NULL;
1224
1225
1.34M
      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.34M
      switch (flag)
1232
1.34M
  {
1233
13.5k
  case STYP_DSECT:
1234
13.5k
    unhandled = "STYP_DSECT";
1235
13.5k
    break;
1236
14.0k
  case STYP_GROUP:
1237
14.0k
    unhandled = "STYP_GROUP";
1238
14.0k
    break;
1239
16.9k
  case STYP_COPY:
1240
16.9k
    unhandled = "STYP_COPY";
1241
16.9k
    break;
1242
14.0k
  case STYP_OVER:
1243
14.0k
    unhandled = "STYP_OVER";
1244
14.0k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
41.1k
  case STYP_NOLOAD:
1247
41.1k
    sec_flags |= SEC_NEVER_LOAD;
1248
41.1k
    break;
1249
0
#endif
1250
59.1k
  case IMAGE_SCN_MEM_READ:
1251
59.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
59.1k
    break;
1253
40.5k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
40.5k
    break;
1256
14.2k
  case IMAGE_SCN_LNK_OTHER:
1257
14.2k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
14.2k
    break;
1259
11.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
11.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
11.6k
    break;
1262
50.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
50.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
50.5k
        " %s in section %s"),
1269
50.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
50.5k
    break;
1271
58.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
58.7k
    sec_flags |= SEC_CODE;
1273
58.7k
    break;
1274
52.1k
  case IMAGE_SCN_MEM_WRITE:
1275
52.1k
    sec_flags &= ~ SEC_READONLY;
1276
52.1k
    break;
1277
55.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
55.5k
       if (is_dbg
1284
55.5k
#ifdef _COMMENT
1285
55.5k
        || strcmp (name, _COMMENT) == 0
1286
55.5k
#endif
1287
55.5k
        )
1288
8.92k
      {
1289
8.92k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
8.92k
      }
1291
55.5k
    break;
1292
39.8k
  case IMAGE_SCN_MEM_SHARED:
1293
39.8k
    sec_flags |= SEC_COFF_SHARED;
1294
39.8k
    break;
1295
72.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
72.2k
    if (!is_dbg)
1297
68.1k
      sec_flags |= SEC_EXCLUDE;
1298
72.2k
    break;
1299
46.5k
  case IMAGE_SCN_CNT_CODE:
1300
46.5k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
46.5k
    break;
1302
33.3k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
33.3k
    if (is_dbg)
1304
2.99k
      sec_flags |= SEC_DEBUGGING;
1305
30.3k
    else
1306
30.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
33.3k
    break;
1308
35.3k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
35.3k
    sec_flags |= SEC_ALLOC;
1310
35.3k
    break;
1311
54.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
54.7k
#ifdef COFF_PAGE_SIZE
1319
54.7k
    sec_flags |= SEC_DEBUGGING;
1320
54.7k
#endif
1321
54.7k
    break;
1322
66.3k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
66.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
5.57k
      result = false;
1326
66.3k
    break;
1327
550k
  default:
1328
    /* Silently ignore for now.  */
1329
550k
    break;
1330
1.34M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.34M
      if (unhandled != NULL)
1334
84.4k
  {
1335
84.4k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
84.4k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
84.4k
       abfd, name, unhandled, flag);
1339
84.4k
    result = false;
1340
84.4k
  }
1341
1.34M
    }
1342
1343
258k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
258k
      && (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
258k
  if (flags_ptr)
1360
258k
    * flags_ptr = sec_flags;
1361
1362
258k
  return result;
1363
258k
}
pei-ia64.c:styp_to_sec_flags
Line
Count
Source
1192
230k
{
1193
230k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
230k
  unsigned long styp_flags = internal_s->s_flags;
1195
230k
  flagword sec_flags;
1196
230k
  bool result = true;
1197
230k
  bool is_dbg = false;
1198
1199
230k
  if (startswith (name, DOT_DEBUG)
1200
230k
      || startswith (name, DOT_ZDEBUG)
1201
230k
#ifdef COFF_LONG_SECTION_NAMES
1202
230k
      || startswith (name, GNU_LINKONCE_WI)
1203
230k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
230k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
230k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
230k
      || startswith (name, GNU_DEBUGLINK)
1208
230k
      || startswith (name, GNU_DEBUGALTLINK)
1209
230k
#endif
1210
230k
      || startswith (name, ".stab"))
1211
10.9k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
230k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
230k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
179k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.71M
  while (styp_flags)
1221
1.48M
    {
1222
1.48M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.48M
      char * unhandled = NULL;
1224
1225
1.48M
      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.48M
      switch (flag)
1232
1.48M
  {
1233
20.4k
  case STYP_DSECT:
1234
20.4k
    unhandled = "STYP_DSECT";
1235
20.4k
    break;
1236
18.1k
  case STYP_GROUP:
1237
18.1k
    unhandled = "STYP_GROUP";
1238
18.1k
    break;
1239
19.5k
  case STYP_COPY:
1240
19.5k
    unhandled = "STYP_COPY";
1241
19.5k
    break;
1242
24.4k
  case STYP_OVER:
1243
24.4k
    unhandled = "STYP_OVER";
1244
24.4k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
45.7k
  case STYP_NOLOAD:
1247
45.7k
    sec_flags |= SEC_NEVER_LOAD;
1248
45.7k
    break;
1249
0
#endif
1250
50.8k
  case IMAGE_SCN_MEM_READ:
1251
50.8k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
50.8k
    break;
1253
44.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
44.6k
    break;
1256
23.4k
  case IMAGE_SCN_LNK_OTHER:
1257
23.4k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
23.4k
    break;
1259
17.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
17.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
17.6k
    break;
1262
45.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
45.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
45.9k
        " %s in section %s"),
1269
45.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
45.9k
    break;
1271
65.0k
  case IMAGE_SCN_MEM_EXECUTE:
1272
65.0k
    sec_flags |= SEC_CODE;
1273
65.0k
    break;
1274
49.4k
  case IMAGE_SCN_MEM_WRITE:
1275
49.4k
    sec_flags &= ~ SEC_READONLY;
1276
49.4k
    break;
1277
66.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
66.1k
       if (is_dbg
1284
66.1k
#ifdef _COMMENT
1285
66.1k
        || strcmp (name, _COMMENT) == 0
1286
66.1k
#endif
1287
66.1k
        )
1288
7.37k
      {
1289
7.37k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
7.37k
      }
1291
66.1k
    break;
1292
38.9k
  case IMAGE_SCN_MEM_SHARED:
1293
38.9k
    sec_flags |= SEC_COFF_SHARED;
1294
38.9k
    break;
1295
58.1k
  case IMAGE_SCN_LNK_REMOVE:
1296
58.1k
    if (!is_dbg)
1297
54.3k
      sec_flags |= SEC_EXCLUDE;
1298
58.1k
    break;
1299
57.7k
  case IMAGE_SCN_CNT_CODE:
1300
57.7k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
57.7k
    break;
1302
39.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
39.1k
    if (is_dbg)
1304
3.24k
      sec_flags |= SEC_DEBUGGING;
1305
35.8k
    else
1306
35.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
39.1k
    break;
1308
45.2k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
45.2k
    sec_flags |= SEC_ALLOC;
1310
45.2k
    break;
1311
64.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
64.6k
#ifdef COFF_PAGE_SIZE
1319
64.6k
    sec_flags |= SEC_DEBUGGING;
1320
64.6k
#endif
1321
64.6k
    break;
1322
66.5k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
66.5k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
6.55k
      result = false;
1326
66.5k
    break;
1327
626k
  default:
1328
    /* Silently ignore for now.  */
1329
626k
    break;
1330
1.48M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.48M
      if (unhandled != NULL)
1334
123k
  {
1335
123k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
123k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
123k
       abfd, name, unhandled, flag);
1339
123k
    result = false;
1340
123k
  }
1341
1.48M
    }
1342
1343
230k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
230k
      && (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
230k
  if (flags_ptr)
1360
230k
    * flags_ptr = sec_flags;
1361
1362
230k
  return result;
1363
230k
}
pei-loongarch64.c:styp_to_sec_flags
Line
Count
Source
1192
229k
{
1193
229k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
229k
  unsigned long styp_flags = internal_s->s_flags;
1195
229k
  flagword sec_flags;
1196
229k
  bool result = true;
1197
229k
  bool is_dbg = false;
1198
1199
229k
  if (startswith (name, DOT_DEBUG)
1200
229k
      || startswith (name, DOT_ZDEBUG)
1201
229k
#ifdef COFF_LONG_SECTION_NAMES
1202
229k
      || startswith (name, GNU_LINKONCE_WI)
1203
229k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
229k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
229k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
229k
      || startswith (name, GNU_DEBUGLINK)
1208
229k
      || startswith (name, GNU_DEBUGALTLINK)
1209
229k
#endif
1210
229k
      || startswith (name, ".stab"))
1211
10.6k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
229k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
229k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
178k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.63M
  while (styp_flags)
1221
1.40M
    {
1222
1.40M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.40M
      char * unhandled = NULL;
1224
1225
1.40M
      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.40M
      switch (flag)
1232
1.40M
  {
1233
11.9k
  case STYP_DSECT:
1234
11.9k
    unhandled = "STYP_DSECT";
1235
11.9k
    break;
1236
12.0k
  case STYP_GROUP:
1237
12.0k
    unhandled = "STYP_GROUP";
1238
12.0k
    break;
1239
17.9k
  case STYP_COPY:
1240
17.9k
    unhandled = "STYP_COPY";
1241
17.9k
    break;
1242
12.0k
  case STYP_OVER:
1243
12.0k
    unhandled = "STYP_OVER";
1244
12.0k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
39.8k
  case STYP_NOLOAD:
1247
39.8k
    sec_flags |= SEC_NEVER_LOAD;
1248
39.8k
    break;
1249
0
#endif
1250
51.0k
  case IMAGE_SCN_MEM_READ:
1251
51.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
51.0k
    break;
1253
41.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
41.9k
    break;
1256
12.6k
  case IMAGE_SCN_LNK_OTHER:
1257
12.6k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
12.6k
    break;
1259
10.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
10.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
10.6k
    break;
1262
58.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
58.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
58.9k
        " %s in section %s"),
1269
58.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
58.9k
    break;
1271
67.3k
  case IMAGE_SCN_MEM_EXECUTE:
1272
67.3k
    sec_flags |= SEC_CODE;
1273
67.3k
    break;
1274
43.5k
  case IMAGE_SCN_MEM_WRITE:
1275
43.5k
    sec_flags &= ~ SEC_READONLY;
1276
43.5k
    break;
1277
66.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
66.4k
       if (is_dbg
1284
66.4k
#ifdef _COMMENT
1285
66.4k
        || strcmp (name, _COMMENT) == 0
1286
66.4k
#endif
1287
66.4k
        )
1288
6.60k
      {
1289
6.60k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
6.60k
      }
1291
66.4k
    break;
1292
41.1k
  case IMAGE_SCN_MEM_SHARED:
1293
41.1k
    sec_flags |= SEC_COFF_SHARED;
1294
41.1k
    break;
1295
66.4k
  case IMAGE_SCN_LNK_REMOVE:
1296
66.4k
    if (!is_dbg)
1297
62.1k
      sec_flags |= SEC_EXCLUDE;
1298
66.4k
    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
40.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
40.1k
    if (is_dbg)
1304
4.06k
      sec_flags |= SEC_DEBUGGING;
1305
36.1k
    else
1306
36.1k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
40.1k
    break;
1308
32.3k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
32.3k
    sec_flags |= SEC_ALLOC;
1310
32.3k
    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
58.1k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
58.1k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.60k
      result = false;
1326
58.1k
    break;
1327
599k
  default:
1328
    /* Silently ignore for now.  */
1329
599k
    break;
1330
1.40M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.40M
      if (unhandled != NULL)
1334
77.3k
  {
1335
77.3k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
77.3k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
77.3k
       abfd, name, unhandled, flag);
1339
77.3k
    result = false;
1340
77.3k
  }
1341
1.40M
    }
1342
1343
229k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
229k
      && (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
229k
  if (flags_ptr)
1360
229k
    * flags_ptr = sec_flags;
1361
1362
229k
  return result;
1363
229k
}
pei-riscv64.c:styp_to_sec_flags
Line
Count
Source
1192
210k
{
1193
210k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
210k
  unsigned long styp_flags = internal_s->s_flags;
1195
210k
  flagword sec_flags;
1196
210k
  bool result = true;
1197
210k
  bool is_dbg = false;
1198
1199
210k
  if (startswith (name, DOT_DEBUG)
1200
210k
      || startswith (name, DOT_ZDEBUG)
1201
210k
#ifdef COFF_LONG_SECTION_NAMES
1202
210k
      || startswith (name, GNU_LINKONCE_WI)
1203
210k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
210k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
210k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
210k
      || startswith (name, GNU_DEBUGLINK)
1208
210k
      || startswith (name, GNU_DEBUGALTLINK)
1209
210k
#endif
1210
210k
      || startswith (name, ".stab"))
1211
5.97k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
210k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
210k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
173k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.30M
  while (styp_flags)
1221
1.09M
    {
1222
1.09M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.09M
      char * unhandled = NULL;
1224
1225
1.09M
      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.09M
      switch (flag)
1232
1.09M
  {
1233
15.2k
  case STYP_DSECT:
1234
15.2k
    unhandled = "STYP_DSECT";
1235
15.2k
    break;
1236
15.8k
  case STYP_GROUP:
1237
15.8k
    unhandled = "STYP_GROUP";
1238
15.8k
    break;
1239
19.8k
  case STYP_COPY:
1240
19.8k
    unhandled = "STYP_COPY";
1241
19.8k
    break;
1242
16.1k
  case STYP_OVER:
1243
16.1k
    unhandled = "STYP_OVER";
1244
16.1k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
34.9k
  case STYP_NOLOAD:
1247
34.9k
    sec_flags |= SEC_NEVER_LOAD;
1248
34.9k
    break;
1249
0
#endif
1250
37.5k
  case IMAGE_SCN_MEM_READ:
1251
37.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
37.5k
    break;
1253
33.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
33.9k
    break;
1256
17.5k
  case IMAGE_SCN_LNK_OTHER:
1257
17.5k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
17.5k
    break;
1259
14.7k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
14.7k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
14.7k
    break;
1262
42.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
42.8k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
42.8k
        " %s in section %s"),
1269
42.8k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
42.8k
    break;
1271
51.1k
  case IMAGE_SCN_MEM_EXECUTE:
1272
51.1k
    sec_flags |= SEC_CODE;
1273
51.1k
    break;
1274
30.5k
  case IMAGE_SCN_MEM_WRITE:
1275
30.5k
    sec_flags &= ~ SEC_READONLY;
1276
30.5k
    break;
1277
41.6k
  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
41.6k
       if (is_dbg
1284
41.6k
#ifdef _COMMENT
1285
41.6k
        || strcmp (name, _COMMENT) == 0
1286
41.6k
#endif
1287
41.6k
        )
1288
3.41k
      {
1289
3.41k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
3.41k
      }
1291
41.6k
    break;
1292
40.0k
  case IMAGE_SCN_MEM_SHARED:
1293
40.0k
    sec_flags |= SEC_COFF_SHARED;
1294
40.0k
    break;
1295
44.2k
  case IMAGE_SCN_LNK_REMOVE:
1296
44.2k
    if (!is_dbg)
1297
40.7k
      sec_flags |= SEC_EXCLUDE;
1298
44.2k
    break;
1299
41.1k
  case IMAGE_SCN_CNT_CODE:
1300
41.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
41.1k
    break;
1302
30.5k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
30.5k
    if (is_dbg)
1304
2.25k
      sec_flags |= SEC_DEBUGGING;
1305
28.3k
    else
1306
28.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
30.5k
    break;
1308
22.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
22.9k
    sec_flags |= SEC_ALLOC;
1310
22.9k
    break;
1311
45.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
#ifdef COFF_PAGE_SIZE
1319
    sec_flags |= SEC_DEBUGGING;
1320
#endif
1321
45.6k
    break;
1322
54.0k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
54.0k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
4.81k
      result = false;
1326
54.0k
    break;
1327
440k
  default:
1328
    /* Silently ignore for now.  */
1329
440k
    break;
1330
1.09M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.09M
      if (unhandled != NULL)
1334
99.4k
  {
1335
99.4k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
99.4k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
99.4k
       abfd, name, unhandled, flag);
1339
99.4k
    result = false;
1340
99.4k
  }
1341
1.09M
    }
1342
1343
210k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
210k
      && (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
210k
  if (flags_ptr)
1360
210k
    * flags_ptr = sec_flags;
1361
1362
210k
  return result;
1363
210k
}
pe-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1192
56.8k
{
1193
56.8k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
56.8k
  unsigned long styp_flags = internal_s->s_flags;
1195
56.8k
  flagword sec_flags;
1196
56.8k
  bool result = true;
1197
56.8k
  bool is_dbg = false;
1198
1199
56.8k
  if (startswith (name, DOT_DEBUG)
1200
56.8k
      || startswith (name, DOT_ZDEBUG)
1201
56.8k
#ifdef COFF_LONG_SECTION_NAMES
1202
56.8k
      || startswith (name, GNU_LINKONCE_WI)
1203
56.8k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
56.8k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
56.8k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
56.8k
      || startswith (name, GNU_DEBUGLINK)
1208
56.8k
      || startswith (name, GNU_DEBUGALTLINK)
1209
56.8k
#endif
1210
56.8k
      || startswith (name, ".stab"))
1211
8.32k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
56.8k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
56.8k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
37.7k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
623k
  while (styp_flags)
1221
566k
    {
1222
566k
      unsigned long flag = styp_flags & - styp_flags;
1223
566k
      char * unhandled = NULL;
1224
1225
566k
      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
566k
      switch (flag)
1232
566k
  {
1233
10.5k
  case STYP_DSECT:
1234
10.5k
    unhandled = "STYP_DSECT";
1235
10.5k
    break;
1236
11.1k
  case STYP_GROUP:
1237
11.1k
    unhandled = "STYP_GROUP";
1238
11.1k
    break;
1239
13.0k
  case STYP_COPY:
1240
13.0k
    unhandled = "STYP_COPY";
1241
13.0k
    break;
1242
10.9k
  case STYP_OVER:
1243
10.9k
    unhandled = "STYP_OVER";
1244
10.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
17.5k
  case STYP_NOLOAD:
1247
17.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
17.5k
    break;
1249
0
#endif
1250
19.1k
  case IMAGE_SCN_MEM_READ:
1251
19.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
19.1k
    break;
1253
16.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
16.3k
    break;
1256
10.9k
  case IMAGE_SCN_LNK_OTHER:
1257
10.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
10.9k
    break;
1259
10.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
10.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
10.6k
    break;
1262
19.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
19.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
19.1k
        " %s in section %s"),
1269
19.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
19.1k
    break;
1271
24.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
24.7k
    sec_flags |= SEC_CODE;
1273
24.7k
    break;
1274
14.2k
  case IMAGE_SCN_MEM_WRITE:
1275
14.2k
    sec_flags &= ~ SEC_READONLY;
1276
14.2k
    break;
1277
20.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
20.4k
       if (is_dbg
1284
20.4k
#ifdef _COMMENT
1285
20.4k
        || strcmp (name, _COMMENT) == 0
1286
20.4k
#endif
1287
20.4k
        )
1288
4.27k
      {
1289
4.27k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
4.27k
      }
1291
20.4k
    break;
1292
17.3k
  case IMAGE_SCN_MEM_SHARED:
1293
17.3k
    sec_flags |= SEC_COFF_SHARED;
1294
17.3k
    break;
1295
22.7k
  case IMAGE_SCN_LNK_REMOVE:
1296
22.7k
    if (!is_dbg)
1297
17.3k
      sec_flags |= SEC_EXCLUDE;
1298
22.7k
    break;
1299
25.1k
  case IMAGE_SCN_CNT_CODE:
1300
25.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
25.1k
    break;
1302
18.4k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
18.4k
    if (is_dbg)
1304
2.91k
      sec_flags |= SEC_DEBUGGING;
1305
15.5k
    else
1306
15.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
18.4k
    break;
1308
13.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
13.7k
    sec_flags |= SEC_ALLOC;
1310
13.7k
    break;
1311
20.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
20.4k
#ifdef COFF_PAGE_SIZE
1319
20.4k
    sec_flags |= SEC_DEBUGGING;
1320
20.4k
#endif
1321
20.4k
    break;
1322
24.3k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
24.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
1.81k
      result = false;
1326
24.3k
    break;
1327
225k
  default:
1328
    /* Silently ignore for now.  */
1329
225k
    break;
1330
566k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
566k
      if (unhandled != NULL)
1334
67.3k
  {
1335
67.3k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
67.3k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
67.3k
       abfd, name, unhandled, flag);
1339
67.3k
    result = false;
1340
67.3k
  }
1341
566k
    }
1342
1343
56.8k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
56.8k
      && (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
56.8k
  if (flags_ptr)
1360
56.8k
    * flags_ptr = sec_flags;
1361
1362
56.8k
  return result;
1363
56.8k
}
pe-arm.c:styp_to_sec_flags
Line
Count
Source
1192
56.8k
{
1193
56.8k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
56.8k
  unsigned long styp_flags = internal_s->s_flags;
1195
56.8k
  flagword sec_flags;
1196
56.8k
  bool result = true;
1197
56.8k
  bool is_dbg = false;
1198
1199
56.8k
  if (startswith (name, DOT_DEBUG)
1200
56.8k
      || startswith (name, DOT_ZDEBUG)
1201
56.8k
#ifdef COFF_LONG_SECTION_NAMES
1202
56.8k
      || startswith (name, GNU_LINKONCE_WI)
1203
56.8k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
56.8k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
56.8k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
56.8k
      || startswith (name, GNU_DEBUGLINK)
1208
56.8k
      || startswith (name, GNU_DEBUGALTLINK)
1209
56.8k
#endif
1210
56.8k
      || startswith (name, ".stab"))
1211
8.32k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
56.8k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
56.8k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
37.7k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
623k
  while (styp_flags)
1221
566k
    {
1222
566k
      unsigned long flag = styp_flags & - styp_flags;
1223
566k
      char * unhandled = NULL;
1224
1225
566k
      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
566k
      switch (flag)
1232
566k
  {
1233
10.5k
  case STYP_DSECT:
1234
10.5k
    unhandled = "STYP_DSECT";
1235
10.5k
    break;
1236
11.1k
  case STYP_GROUP:
1237
11.1k
    unhandled = "STYP_GROUP";
1238
11.1k
    break;
1239
13.0k
  case STYP_COPY:
1240
13.0k
    unhandled = "STYP_COPY";
1241
13.0k
    break;
1242
10.9k
  case STYP_OVER:
1243
10.9k
    unhandled = "STYP_OVER";
1244
10.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
17.5k
  case STYP_NOLOAD:
1247
17.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
17.5k
    break;
1249
0
#endif
1250
19.1k
  case IMAGE_SCN_MEM_READ:
1251
19.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
19.1k
    break;
1253
16.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
16.3k
    break;
1256
10.9k
  case IMAGE_SCN_LNK_OTHER:
1257
10.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
10.9k
    break;
1259
10.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
10.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
10.6k
    break;
1262
19.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
19.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
19.1k
        " %s in section %s"),
1269
19.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
19.1k
    break;
1271
24.7k
  case IMAGE_SCN_MEM_EXECUTE:
1272
24.7k
    sec_flags |= SEC_CODE;
1273
24.7k
    break;
1274
14.2k
  case IMAGE_SCN_MEM_WRITE:
1275
14.2k
    sec_flags &= ~ SEC_READONLY;
1276
14.2k
    break;
1277
20.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
20.4k
       if (is_dbg
1284
20.4k
#ifdef _COMMENT
1285
20.4k
        || strcmp (name, _COMMENT) == 0
1286
20.4k
#endif
1287
20.4k
        )
1288
4.27k
      {
1289
4.27k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
4.27k
      }
1291
20.4k
    break;
1292
17.3k
  case IMAGE_SCN_MEM_SHARED:
1293
17.3k
    sec_flags |= SEC_COFF_SHARED;
1294
17.3k
    break;
1295
22.7k
  case IMAGE_SCN_LNK_REMOVE:
1296
22.7k
    if (!is_dbg)
1297
17.3k
      sec_flags |= SEC_EXCLUDE;
1298
22.7k
    break;
1299
25.1k
  case IMAGE_SCN_CNT_CODE:
1300
25.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
25.1k
    break;
1302
18.4k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
18.4k
    if (is_dbg)
1304
2.91k
      sec_flags |= SEC_DEBUGGING;
1305
15.5k
    else
1306
15.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
18.4k
    break;
1308
13.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
13.7k
    sec_flags |= SEC_ALLOC;
1310
13.7k
    break;
1311
20.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
20.4k
#ifdef COFF_PAGE_SIZE
1319
20.4k
    sec_flags |= SEC_DEBUGGING;
1320
20.4k
#endif
1321
20.4k
    break;
1322
24.3k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
24.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
1.81k
      result = false;
1326
24.3k
    break;
1327
225k
  default:
1328
    /* Silently ignore for now.  */
1329
225k
    break;
1330
566k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
566k
      if (unhandled != NULL)
1334
67.3k
  {
1335
67.3k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
67.3k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
67.3k
       abfd, name, unhandled, flag);
1339
67.3k
    result = false;
1340
67.3k
  }
1341
566k
    }
1342
1343
56.8k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
56.8k
      && (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
56.8k
  if (flags_ptr)
1360
56.8k
    * flags_ptr = sec_flags;
1361
1362
56.8k
  return result;
1363
56.8k
}
pe-i386.c:styp_to_sec_flags
Line
Count
Source
1192
128k
{
1193
128k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
128k
  unsigned long styp_flags = internal_s->s_flags;
1195
128k
  flagword sec_flags;
1196
128k
  bool result = true;
1197
128k
  bool is_dbg = false;
1198
1199
128k
  if (startswith (name, DOT_DEBUG)
1200
128k
      || startswith (name, DOT_ZDEBUG)
1201
128k
#ifdef COFF_LONG_SECTION_NAMES
1202
128k
      || startswith (name, GNU_LINKONCE_WI)
1203
128k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
128k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
128k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
128k
      || startswith (name, GNU_DEBUGLINK)
1208
128k
      || startswith (name, GNU_DEBUGALTLINK)
1209
128k
#endif
1210
128k
      || startswith (name, ".stab"))
1211
14.6k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
128k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
128k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
96.9k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.16M
  while (styp_flags)
1221
1.03M
    {
1222
1.03M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.03M
      char * unhandled = NULL;
1224
1225
1.03M
      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.03M
      switch (flag)
1232
1.03M
  {
1233
21.3k
  case STYP_DSECT:
1234
21.3k
    unhandled = "STYP_DSECT";
1235
21.3k
    break;
1236
21.4k
  case STYP_GROUP:
1237
21.4k
    unhandled = "STYP_GROUP";
1238
21.4k
    break;
1239
20.1k
  case STYP_COPY:
1240
20.1k
    unhandled = "STYP_COPY";
1241
20.1k
    break;
1242
25.4k
  case STYP_OVER:
1243
25.4k
    unhandled = "STYP_OVER";
1244
25.4k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
29.3k
  case STYP_NOLOAD:
1247
29.3k
    sec_flags |= SEC_NEVER_LOAD;
1248
29.3k
    break;
1249
0
#endif
1250
31.6k
  case IMAGE_SCN_MEM_READ:
1251
31.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
31.6k
    break;
1253
27.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
27.6k
    break;
1256
22.8k
  case IMAGE_SCN_LNK_OTHER:
1257
22.8k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
22.8k
    break;
1259
23.3k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
23.3k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
23.3k
    break;
1262
33.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
33.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
33.7k
        " %s in section %s"),
1269
33.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
33.7k
    break;
1271
42.4k
  case IMAGE_SCN_MEM_EXECUTE:
1272
42.4k
    sec_flags |= SEC_CODE;
1273
42.4k
    break;
1274
29.5k
  case IMAGE_SCN_MEM_WRITE:
1275
29.5k
    sec_flags &= ~ SEC_READONLY;
1276
29.5k
    break;
1277
38.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
38.1k
       if (is_dbg
1284
38.1k
#ifdef _COMMENT
1285
38.1k
        || strcmp (name, _COMMENT) == 0
1286
38.1k
#endif
1287
38.1k
        )
1288
7.34k
      {
1289
7.34k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
7.34k
      }
1291
38.1k
    break;
1292
28.1k
  case IMAGE_SCN_MEM_SHARED:
1293
28.1k
    sec_flags |= SEC_COFF_SHARED;
1294
28.1k
    break;
1295
33.9k
  case IMAGE_SCN_LNK_REMOVE:
1296
33.9k
    if (!is_dbg)
1297
28.6k
      sec_flags |= SEC_EXCLUDE;
1298
33.9k
    break;
1299
37.4k
  case IMAGE_SCN_CNT_CODE:
1300
37.4k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
37.4k
    break;
1302
27.8k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
27.8k
    if (is_dbg)
1304
5.01k
      sec_flags |= SEC_DEBUGGING;
1305
22.8k
    else
1306
22.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
27.8k
    break;
1308
19.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
19.9k
    sec_flags |= SEC_ALLOC;
1310
19.9k
    break;
1311
37.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
37.9k
#ifdef COFF_PAGE_SIZE
1319
37.9k
    sec_flags |= SEC_DEBUGGING;
1320
37.9k
#endif
1321
37.9k
    break;
1322
43.2k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
43.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
2.73k
      result = false;
1326
43.2k
    break;
1327
442k
  default:
1328
    /* Silently ignore for now.  */
1329
442k
    break;
1330
1.03M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.03M
      if (unhandled != NULL)
1334
134k
  {
1335
134k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
134k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
134k
       abfd, name, unhandled, flag);
1339
134k
    result = false;
1340
134k
  }
1341
1.03M
    }
1342
1343
128k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
128k
      && (startswith (name, ".sbss")
1345
0
    || startswith (name, ".sdata")))
1346
0
    sec_flags |= SEC_SMALL_DATA;
1347
1348
128k
#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
128k
  if (startswith (name, ".gnu.linkonce"))
1356
2.04k
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1357
128k
#endif
1358
1359
128k
  if (flags_ptr)
1360
128k
    * flags_ptr = sec_flags;
1361
1362
128k
  return result;
1363
128k
}
pe-mcore.c:styp_to_sec_flags
Line
Count
Source
1192
168k
{
1193
168k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
168k
  unsigned long styp_flags = internal_s->s_flags;
1195
168k
  flagword sec_flags;
1196
168k
  bool result = true;
1197
168k
  bool is_dbg = false;
1198
1199
168k
  if (startswith (name, DOT_DEBUG)
1200
168k
      || startswith (name, DOT_ZDEBUG)
1201
168k
#ifdef COFF_LONG_SECTION_NAMES
1202
168k
      || startswith (name, GNU_LINKONCE_WI)
1203
168k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
168k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
168k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
168k
      || startswith (name, GNU_DEBUGLINK)
1208
168k
      || startswith (name, GNU_DEBUGALTLINK)
1209
168k
#endif
1210
168k
      || startswith (name, ".stab"))
1211
13.2k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
168k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
168k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
124k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.25M
  while (styp_flags)
1221
1.08M
    {
1222
1.08M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.08M
      char * unhandled = NULL;
1224
1225
1.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
1.08M
      switch (flag)
1232
1.08M
  {
1233
5.11k
  case STYP_DSECT:
1234
5.11k
    unhandled = "STYP_DSECT";
1235
5.11k
    break;
1236
6.19k
  case STYP_GROUP:
1237
6.19k
    unhandled = "STYP_GROUP";
1238
6.19k
    break;
1239
6.30k
  case STYP_COPY:
1240
6.30k
    unhandled = "STYP_COPY";
1241
6.30k
    break;
1242
5.93k
  case STYP_OVER:
1243
5.93k
    unhandled = "STYP_OVER";
1244
5.93k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
36.8k
  case STYP_NOLOAD:
1247
36.8k
    sec_flags |= SEC_NEVER_LOAD;
1248
36.8k
    break;
1249
0
#endif
1250
43.6k
  case IMAGE_SCN_MEM_READ:
1251
43.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
43.6k
    break;
1253
34.4k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
34.4k
    break;
1256
5.26k
  case IMAGE_SCN_LNK_OTHER:
1257
5.26k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
5.26k
    break;
1259
4.76k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
4.76k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
4.76k
    break;
1262
41.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
41.2k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
41.2k
        " %s in section %s"),
1269
41.2k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
41.2k
    break;
1271
49.2k
  case IMAGE_SCN_MEM_EXECUTE:
1272
49.2k
    sec_flags |= SEC_CODE;
1273
49.2k
    break;
1274
32.2k
  case IMAGE_SCN_MEM_WRITE:
1275
32.2k
    sec_flags &= ~ SEC_READONLY;
1276
32.2k
    break;
1277
44.8k
  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
44.8k
       if (is_dbg
1284
44.8k
#ifdef _COMMENT
1285
44.8k
        || strcmp (name, _COMMENT) == 0
1286
44.8k
#endif
1287
44.8k
        )
1288
7.03k
      {
1289
7.03k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
7.03k
      }
1291
44.8k
    break;
1292
28.8k
  case IMAGE_SCN_MEM_SHARED:
1293
28.8k
    sec_flags |= SEC_COFF_SHARED;
1294
28.8k
    break;
1295
41.1k
  case IMAGE_SCN_LNK_REMOVE:
1296
41.1k
    if (!is_dbg)
1297
35.6k
      sec_flags |= SEC_EXCLUDE;
1298
41.1k
    break;
1299
51.1k
  case IMAGE_SCN_CNT_CODE:
1300
51.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
51.1k
    break;
1302
45.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
45.0k
    if (is_dbg)
1304
6.84k
      sec_flags |= SEC_DEBUGGING;
1305
38.2k
    else
1306
38.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
45.0k
    break;
1308
34.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
34.9k
    sec_flags |= SEC_ALLOC;
1310
34.9k
    break;
1311
45.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
45.2k
#ifdef COFF_PAGE_SIZE
1319
45.2k
    sec_flags |= SEC_DEBUGGING;
1320
45.2k
#endif
1321
45.2k
    break;
1322
49.8k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
49.8k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
874
      result = false;
1326
49.8k
    break;
1327
472k
  default:
1328
    /* Silently ignore for now.  */
1329
472k
    break;
1330
1.08M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.08M
      if (unhandled != NULL)
1334
33.5k
  {
1335
33.5k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
33.5k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
33.5k
       abfd, name, unhandled, flag);
1339
33.5k
    result = false;
1340
33.5k
  }
1341
1.08M
    }
1342
1343
168k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
168k
      && (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
168k
  if (flags_ptr)
1360
168k
    * flags_ptr = sec_flags;
1361
1362
168k
  return result;
1363
168k
}
pe-sh.c:styp_to_sec_flags
Line
Count
Source
1192
118k
{
1193
118k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
118k
  unsigned long styp_flags = internal_s->s_flags;
1195
118k
  flagword sec_flags;
1196
118k
  bool result = true;
1197
118k
  bool is_dbg = false;
1198
1199
118k
  if (startswith (name, DOT_DEBUG)
1200
118k
      || startswith (name, DOT_ZDEBUG)
1201
118k
#ifdef COFF_LONG_SECTION_NAMES
1202
118k
      || startswith (name, GNU_LINKONCE_WI)
1203
118k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
118k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
118k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
118k
      || startswith (name, GNU_DEBUGLINK)
1208
118k
      || startswith (name, GNU_DEBUGALTLINK)
1209
118k
#endif
1210
118k
      || startswith (name, ".stab"))
1211
7.50k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
118k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
118k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
89.7k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
929k
  while (styp_flags)
1221
811k
    {
1222
811k
      unsigned long flag = styp_flags & - styp_flags;
1223
811k
      char * unhandled = NULL;
1224
1225
811k
      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
811k
      switch (flag)
1232
811k
  {
1233
13.1k
  case STYP_DSECT:
1234
13.1k
    unhandled = "STYP_DSECT";
1235
13.1k
    break;
1236
12.2k
  case STYP_GROUP:
1237
12.2k
    unhandled = "STYP_GROUP";
1238
12.2k
    break;
1239
12.8k
  case STYP_COPY:
1240
12.8k
    unhandled = "STYP_COPY";
1241
12.8k
    break;
1242
12.0k
  case STYP_OVER:
1243
12.0k
    unhandled = "STYP_OVER";
1244
12.0k
    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
28.5k
  case IMAGE_SCN_MEM_READ:
1251
28.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
28.5k
    break;
1253
22.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
22.6k
    break;
1256
14.2k
  case IMAGE_SCN_LNK_OTHER:
1257
14.2k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
14.2k
    break;
1259
11.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
11.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
11.9k
    break;
1262
29.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
29.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
29.9k
        " %s in section %s"),
1269
29.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
29.9k
    break;
1271
38.8k
  case IMAGE_SCN_MEM_EXECUTE:
1272
38.8k
    sec_flags |= SEC_CODE;
1273
38.8k
    break;
1274
20.4k
  case IMAGE_SCN_MEM_WRITE:
1275
20.4k
    sec_flags &= ~ SEC_READONLY;
1276
20.4k
    break;
1277
31.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
31.3k
       if (is_dbg
1284
31.3k
#ifdef _COMMENT
1285
31.3k
        || strcmp (name, _COMMENT) == 0
1286
31.3k
#endif
1287
31.3k
        )
1288
4.34k
      {
1289
4.34k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
4.34k
      }
1291
31.3k
    break;
1292
23.4k
  case IMAGE_SCN_MEM_SHARED:
1293
23.4k
    sec_flags |= SEC_COFF_SHARED;
1294
23.4k
    break;
1295
29.1k
  case IMAGE_SCN_LNK_REMOVE:
1296
29.1k
    if (!is_dbg)
1297
26.3k
      sec_flags |= SEC_EXCLUDE;
1298
29.1k
    break;
1299
30.9k
  case IMAGE_SCN_CNT_CODE:
1300
30.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
30.9k
    break;
1302
25.3k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
25.3k
    if (is_dbg)
1304
2.54k
      sec_flags |= SEC_DEBUGGING;
1305
22.8k
    else
1306
22.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
25.3k
    break;
1308
19.4k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
19.4k
    sec_flags |= SEC_ALLOC;
1310
19.4k
    break;
1311
28.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
28.5k
    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
1.76k
      result = false;
1326
35.2k
    break;
1327
344k
  default:
1328
    /* Silently ignore for now.  */
1329
344k
    break;
1330
811k
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
811k
      if (unhandled != NULL)
1334
76.6k
  {
1335
76.6k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
76.6k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
76.6k
       abfd, name, unhandled, flag);
1339
76.6k
    result = false;
1340
76.6k
  }
1341
811k
    }
1342
1343
118k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
118k
      && (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
118k
  if (flags_ptr)
1360
118k
    * flags_ptr = sec_flags;
1361
1362
118k
  return result;
1363
118k
}
pei-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1192
204k
{
1193
204k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
204k
  unsigned long styp_flags = internal_s->s_flags;
1195
204k
  flagword sec_flags;
1196
204k
  bool result = true;
1197
204k
  bool is_dbg = false;
1198
1199
204k
  if (startswith (name, DOT_DEBUG)
1200
204k
      || startswith (name, DOT_ZDEBUG)
1201
204k
#ifdef COFF_LONG_SECTION_NAMES
1202
204k
      || startswith (name, GNU_LINKONCE_WI)
1203
204k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
204k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
204k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
204k
      || startswith (name, GNU_DEBUGLINK)
1208
204k
      || startswith (name, GNU_DEBUGALTLINK)
1209
204k
#endif
1210
204k
      || startswith (name, ".stab"))
1211
11.2k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
204k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
204k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
142k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.85M
  while (styp_flags)
1221
1.65M
    {
1222
1.65M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.65M
      char * unhandled = NULL;
1224
1225
1.65M
      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.65M
      switch (flag)
1232
1.65M
  {
1233
32.9k
  case STYP_DSECT:
1234
32.9k
    unhandled = "STYP_DSECT";
1235
32.9k
    break;
1236
31.2k
  case STYP_GROUP:
1237
31.2k
    unhandled = "STYP_GROUP";
1238
31.2k
    break;
1239
33.2k
  case STYP_COPY:
1240
33.2k
    unhandled = "STYP_COPY";
1241
33.2k
    break;
1242
34.5k
  case STYP_OVER:
1243
34.5k
    unhandled = "STYP_OVER";
1244
34.5k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
50.3k
  case STYP_NOLOAD:
1247
50.3k
    sec_flags |= SEC_NEVER_LOAD;
1248
50.3k
    break;
1249
0
#endif
1250
62.0k
  case IMAGE_SCN_MEM_READ:
1251
62.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
62.0k
    break;
1253
45.5k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
45.5k
    break;
1256
35.3k
  case IMAGE_SCN_LNK_OTHER:
1257
35.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
35.3k
    break;
1259
35.4k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
35.4k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
35.4k
    break;
1262
50.0k
  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
50.0k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
50.0k
        " %s in section %s"),
1269
50.0k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
50.0k
    break;
1271
68.6k
  case IMAGE_SCN_MEM_EXECUTE:
1272
68.6k
    sec_flags |= SEC_CODE;
1273
68.6k
    break;
1274
48.6k
  case IMAGE_SCN_MEM_WRITE:
1275
48.6k
    sec_flags &= ~ SEC_READONLY;
1276
48.6k
    break;
1277
63.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
63.4k
       if (is_dbg
1284
63.4k
#ifdef _COMMENT
1285
63.4k
        || strcmp (name, _COMMENT) == 0
1286
63.4k
#endif
1287
63.4k
        )
1288
5.20k
      {
1289
5.20k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
5.20k
      }
1291
63.4k
    break;
1292
47.5k
  case IMAGE_SCN_MEM_SHARED:
1293
47.5k
    sec_flags |= SEC_COFF_SHARED;
1294
47.5k
    break;
1295
56.7k
  case IMAGE_SCN_LNK_REMOVE:
1296
56.7k
    if (!is_dbg)
1297
53.3k
      sec_flags |= SEC_EXCLUDE;
1298
56.7k
    break;
1299
51.6k
  case IMAGE_SCN_CNT_CODE:
1300
51.6k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
51.6k
    break;
1302
50.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
50.6k
    if (is_dbg)
1304
4.82k
      sec_flags |= SEC_DEBUGGING;
1305
45.8k
    else
1306
45.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
50.6k
    break;
1308
41.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
41.7k
    sec_flags |= SEC_ALLOC;
1310
41.7k
    break;
1311
58.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
58.8k
#ifdef COFF_PAGE_SIZE
1319
58.8k
    sec_flags |= SEC_DEBUGGING;
1320
58.8k
#endif
1321
58.8k
    break;
1322
70.8k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
70.8k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
5.41k
      result = false;
1326
70.8k
    break;
1327
684k
  default:
1328
    /* Silently ignore for now.  */
1329
684k
    break;
1330
1.65M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.65M
      if (unhandled != NULL)
1334
202k
  {
1335
202k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
202k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
202k
       abfd, name, unhandled, flag);
1339
202k
    result = false;
1340
202k
  }
1341
1.65M
    }
1342
1343
204k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
204k
      && (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
204k
  if (flags_ptr)
1360
204k
    * flags_ptr = sec_flags;
1361
1362
204k
  return result;
1363
204k
}
pei-arm.c:styp_to_sec_flags
Line
Count
Source
1192
265k
{
1193
265k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
265k
  unsigned long styp_flags = internal_s->s_flags;
1195
265k
  flagword sec_flags;
1196
265k
  bool result = true;
1197
265k
  bool is_dbg = false;
1198
1199
265k
  if (startswith (name, DOT_DEBUG)
1200
265k
      || startswith (name, DOT_ZDEBUG)
1201
265k
#ifdef COFF_LONG_SECTION_NAMES
1202
265k
      || startswith (name, GNU_LINKONCE_WI)
1203
265k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
265k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
265k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
265k
      || startswith (name, GNU_DEBUGLINK)
1208
265k
      || startswith (name, GNU_DEBUGALTLINK)
1209
265k
#endif
1210
265k
      || startswith (name, ".stab"))
1211
14.1k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
265k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
265k
  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.31M
  while (styp_flags)
1221
2.04M
    {
1222
2.04M
      unsigned long flag = styp_flags & - styp_flags;
1223
2.04M
      char * unhandled = NULL;
1224
1225
2.04M
      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.04M
      switch (flag)
1232
2.04M
  {
1233
39.3k
  case STYP_DSECT:
1234
39.3k
    unhandled = "STYP_DSECT";
1235
39.3k
    break;
1236
36.8k
  case STYP_GROUP:
1237
36.8k
    unhandled = "STYP_GROUP";
1238
36.8k
    break;
1239
39.6k
  case STYP_COPY:
1240
39.6k
    unhandled = "STYP_COPY";
1241
39.6k
    break;
1242
41.5k
  case STYP_OVER:
1243
41.5k
    unhandled = "STYP_OVER";
1244
41.5k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
62.2k
  case STYP_NOLOAD:
1247
62.2k
    sec_flags |= SEC_NEVER_LOAD;
1248
62.2k
    break;
1249
0
#endif
1250
79.0k
  case IMAGE_SCN_MEM_READ:
1251
79.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
79.0k
    break;
1253
56.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
56.9k
    break;
1256
42.8k
  case IMAGE_SCN_LNK_OTHER:
1257
42.8k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
42.8k
    break;
1259
43.0k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
43.0k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
43.0k
    break;
1262
65.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
65.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
65.1k
        " %s in section %s"),
1269
65.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
65.1k
    break;
1271
83.9k
  case IMAGE_SCN_MEM_EXECUTE:
1272
83.9k
    sec_flags |= SEC_CODE;
1273
83.9k
    break;
1274
63.9k
  case IMAGE_SCN_MEM_WRITE:
1275
63.9k
    sec_flags &= ~ SEC_READONLY;
1276
63.9k
    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
5.83k
      {
1289
5.83k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
5.83k
      }
1291
81.0k
    break;
1292
59.0k
  case IMAGE_SCN_MEM_SHARED:
1293
59.0k
    sec_flags |= SEC_COFF_SHARED;
1294
59.0k
    break;
1295
68.6k
  case IMAGE_SCN_LNK_REMOVE:
1296
68.6k
    if (!is_dbg)
1297
63.8k
      sec_flags |= SEC_EXCLUDE;
1298
68.6k
    break;
1299
65.7k
  case IMAGE_SCN_CNT_CODE:
1300
65.7k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
65.7k
    break;
1302
63.5k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
63.5k
    if (is_dbg)
1304
5.28k
      sec_flags |= SEC_DEBUGGING;
1305
58.2k
    else
1306
58.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
63.5k
    break;
1308
54.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
54.7k
    sec_flags |= SEC_ALLOC;
1310
54.7k
    break;
1311
74.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
74.2k
#ifdef COFF_PAGE_SIZE
1319
74.2k
    sec_flags |= SEC_DEBUGGING;
1320
74.2k
#endif
1321
74.2k
    break;
1322
81.6k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
81.6k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
5.97k
      result = false;
1326
81.6k
    break;
1327
844k
  default:
1328
    /* Silently ignore for now.  */
1329
844k
    break;
1330
2.04M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
2.04M
      if (unhandled != NULL)
1334
243k
  {
1335
243k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
243k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
243k
       abfd, name, unhandled, flag);
1339
243k
    result = false;
1340
243k
  }
1341
2.04M
    }
1342
1343
265k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
265k
      && (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
265k
  if (flags_ptr)
1360
265k
    * flags_ptr = sec_flags;
1361
1362
265k
  return result;
1363
265k
}
pei-mcore.c:styp_to_sec_flags
Line
Count
Source
1192
199k
{
1193
199k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
199k
  unsigned long styp_flags = internal_s->s_flags;
1195
199k
  flagword sec_flags;
1196
199k
  bool result = true;
1197
199k
  bool is_dbg = false;
1198
1199
199k
  if (startswith (name, DOT_DEBUG)
1200
199k
      || startswith (name, DOT_ZDEBUG)
1201
199k
#ifdef COFF_LONG_SECTION_NAMES
1202
199k
      || startswith (name, GNU_LINKONCE_WI)
1203
199k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
199k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
199k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
199k
      || startswith (name, GNU_DEBUGLINK)
1208
199k
      || startswith (name, GNU_DEBUGALTLINK)
1209
199k
#endif
1210
199k
      || startswith (name, ".stab"))
1211
10.7k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
199k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
199k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
147k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.55M
  while (styp_flags)
1221
1.36M
    {
1222
1.36M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.36M
      char * unhandled = NULL;
1224
1225
1.36M
      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.36M
      switch (flag)
1232
1.36M
  {
1233
16.9k
  case STYP_DSECT:
1234
16.9k
    unhandled = "STYP_DSECT";
1235
16.9k
    break;
1236
13.7k
  case STYP_GROUP:
1237
13.7k
    unhandled = "STYP_GROUP";
1238
13.7k
    break;
1239
18.5k
  case STYP_COPY:
1240
18.5k
    unhandled = "STYP_COPY";
1241
18.5k
    break;
1242
16.9k
  case STYP_OVER:
1243
16.9k
    unhandled = "STYP_OVER";
1244
16.9k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
41.7k
  case STYP_NOLOAD:
1247
41.7k
    sec_flags |= SEC_NEVER_LOAD;
1248
41.7k
    break;
1249
0
#endif
1250
51.9k
  case IMAGE_SCN_MEM_READ:
1251
51.9k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
51.9k
    break;
1253
41.2k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
41.2k
    break;
1256
18.0k
  case IMAGE_SCN_LNK_OTHER:
1257
18.0k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
18.0k
    break;
1259
15.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
15.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
15.9k
    break;
1262
44.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
44.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
44.7k
        " %s in section %s"),
1269
44.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
44.7k
    break;
1271
69.4k
  case IMAGE_SCN_MEM_EXECUTE:
1272
69.4k
    sec_flags |= SEC_CODE;
1273
69.4k
    break;
1274
40.4k
  case IMAGE_SCN_MEM_WRITE:
1275
40.4k
    sec_flags &= ~ SEC_READONLY;
1276
40.4k
    break;
1277
62.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
62.9k
       if (is_dbg
1284
62.9k
#ifdef _COMMENT
1285
62.9k
        || strcmp (name, _COMMENT) == 0
1286
62.9k
#endif
1287
62.9k
        )
1288
6.77k
      {
1289
6.77k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
6.77k
      }
1291
62.9k
    break;
1292
38.8k
  case IMAGE_SCN_MEM_SHARED:
1293
38.8k
    sec_flags |= SEC_COFF_SHARED;
1294
38.8k
    break;
1295
55.4k
  case IMAGE_SCN_LNK_REMOVE:
1296
55.4k
    if (!is_dbg)
1297
50.0k
      sec_flags |= SEC_EXCLUDE;
1298
55.4k
    break;
1299
52.5k
  case IMAGE_SCN_CNT_CODE:
1300
52.5k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
52.5k
    break;
1302
44.5k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
44.5k
    if (is_dbg)
1304
3.84k
      sec_flags |= SEC_DEBUGGING;
1305
40.7k
    else
1306
40.7k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
44.5k
    break;
1308
41.1k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
41.1k
    sec_flags |= SEC_ALLOC;
1310
41.1k
    break;
1311
51.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
51.6k
#ifdef COFF_PAGE_SIZE
1319
51.6k
    sec_flags |= SEC_DEBUGGING;
1320
51.6k
#endif
1321
51.6k
    break;
1322
57.0k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
57.0k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
3.69k
      result = false;
1326
57.0k
    break;
1327
566k
  default:
1328
    /* Silently ignore for now.  */
1329
566k
    break;
1330
1.36M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.36M
      if (unhandled != NULL)
1334
100k
  {
1335
100k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
100k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
100k
       abfd, name, unhandled, flag);
1339
100k
    result = false;
1340
100k
  }
1341
1.36M
    }
1342
1343
199k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
199k
      && (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
199k
  if (flags_ptr)
1360
199k
    * flags_ptr = sec_flags;
1361
1362
199k
  return result;
1363
199k
}
pei-sh.c:styp_to_sec_flags
Line
Count
Source
1192
218k
{
1193
218k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1194
218k
  unsigned long styp_flags = internal_s->s_flags;
1195
218k
  flagword sec_flags;
1196
218k
  bool result = true;
1197
218k
  bool is_dbg = false;
1198
1199
218k
  if (startswith (name, DOT_DEBUG)
1200
218k
      || startswith (name, DOT_ZDEBUG)
1201
218k
#ifdef COFF_LONG_SECTION_NAMES
1202
218k
      || startswith (name, GNU_LINKONCE_WI)
1203
218k
      || startswith (name, GNU_LINKONCE_WT)
1204
      /* FIXME: These definitions ought to be in a header file.  */
1205
218k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1206
218k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1207
218k
      || startswith (name, GNU_DEBUGLINK)
1208
218k
      || startswith (name, GNU_DEBUGALTLINK)
1209
218k
#endif
1210
218k
      || startswith (name, ".stab"))
1211
12.7k
    is_dbg = true;
1212
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1213
218k
  sec_flags = SEC_READONLY;
1214
1215
  /* If section disallows read, then set the NOREAD flag. */
1216
218k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1217
160k
    sec_flags |= SEC_COFF_NOREAD;
1218
1219
  /* Process each flag bit in styp_flags in turn.  */
1220
1.70M
  while (styp_flags)
1221
1.49M
    {
1222
1.49M
      unsigned long flag = styp_flags & - styp_flags;
1223
1.49M
      char * unhandled = NULL;
1224
1225
1.49M
      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.49M
      switch (flag)
1232
1.49M
  {
1233
21.0k
  case STYP_DSECT:
1234
21.0k
    unhandled = "STYP_DSECT";
1235
21.0k
    break;
1236
18.5k
  case STYP_GROUP:
1237
18.5k
    unhandled = "STYP_GROUP";
1238
18.5k
    break;
1239
20.8k
  case STYP_COPY:
1240
20.8k
    unhandled = "STYP_COPY";
1241
20.8k
    break;
1242
23.0k
  case STYP_OVER:
1243
23.0k
    unhandled = "STYP_OVER";
1244
23.0k
    break;
1245
0
#ifdef SEC_NEVER_LOAD
1246
41.5k
  case STYP_NOLOAD:
1247
41.5k
    sec_flags |= SEC_NEVER_LOAD;
1248
41.5k
    break;
1249
0
#endif
1250
57.5k
  case IMAGE_SCN_MEM_READ:
1251
57.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1252
57.5k
    break;
1253
45.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1254
    /* Skip.  */
1255
45.3k
    break;
1256
22.5k
  case IMAGE_SCN_LNK_OTHER:
1257
22.5k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1258
22.5k
    break;
1259
19.6k
  case IMAGE_SCN_MEM_NOT_CACHED:
1260
19.6k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1261
19.6k
    break;
1262
66.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
66.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1268
66.7k
        " %s in section %s"),
1269
66.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1270
66.7k
    break;
1271
64.8k
  case IMAGE_SCN_MEM_EXECUTE:
1272
64.8k
    sec_flags |= SEC_CODE;
1273
64.8k
    break;
1274
45.8k
  case IMAGE_SCN_MEM_WRITE:
1275
45.8k
    sec_flags &= ~ SEC_READONLY;
1276
45.8k
    break;
1277
74.8k
  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
74.8k
       if (is_dbg
1284
74.8k
#ifdef _COMMENT
1285
74.8k
        || strcmp (name, _COMMENT) == 0
1286
74.8k
#endif
1287
74.8k
        )
1288
8.12k
      {
1289
8.12k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1290
8.12k
      }
1291
74.8k
    break;
1292
50.6k
  case IMAGE_SCN_MEM_SHARED:
1293
50.6k
    sec_flags |= SEC_COFF_SHARED;
1294
50.6k
    break;
1295
59.6k
  case IMAGE_SCN_LNK_REMOVE:
1296
59.6k
    if (!is_dbg)
1297
55.3k
      sec_flags |= SEC_EXCLUDE;
1298
59.6k
    break;
1299
52.6k
  case IMAGE_SCN_CNT_CODE:
1300
52.6k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1301
52.6k
    break;
1302
35.4k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1303
35.4k
    if (is_dbg)
1304
2.65k
      sec_flags |= SEC_DEBUGGING;
1305
32.8k
    else
1306
32.8k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1307
35.4k
    break;
1308
36.8k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1309
36.8k
    sec_flags |= SEC_ALLOC;
1310
36.8k
    break;
1311
53.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
53.5k
#ifdef COFF_PAGE_SIZE
1319
53.5k
    sec_flags |= SEC_DEBUGGING;
1320
53.5k
#endif
1321
53.5k
    break;
1322
67.7k
  case IMAGE_SCN_LNK_COMDAT:
1323
    /* COMDAT gets very special treatment.  */
1324
67.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1325
4.32k
      result = false;
1326
67.7k
    break;
1327
611k
  default:
1328
    /* Silently ignore for now.  */
1329
611k
    break;
1330
1.49M
  }
1331
1332
      /* If the section flag was not handled, report it here.  */
1333
1.49M
      if (unhandled != NULL)
1334
125k
  {
1335
125k
    _bfd_error_handler
1336
      /* xgettext:c-format */
1337
125k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1338
125k
       abfd, name, unhandled, flag);
1339
125k
    result = false;
1340
125k
  }
1341
1.49M
    }
1342
1343
218k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1344
218k
      && (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
218k
  if (flags_ptr)
1360
218k
    * flags_ptr = sec_flags;
1361
1362
218k
  return result;
1363
218k
}
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
79.0M
{
1679
79.0M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
79.0M
  if (BADMAG (*internal_f))
1682
76.7M
    return false;
1683
1684
2.28M
  return true;
1685
79.0M
}
pei-i386.c:coff_bad_format_hook
Line
Count
Source
1678
901k
{
1679
901k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
901k
  if (BADMAG (*internal_f))
1682
768k
    return false;
1683
1684
133k
  return true;
1685
901k
}
pe-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
5.23M
{
1679
5.23M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.23M
  if (BADMAG (*internal_f))
1682
5.01M
    return false;
1683
1684
219k
  return true;
1685
5.23M
}
pei-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
899k
{
1679
899k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
899k
  if (BADMAG (*internal_f))
1682
772k
    return false;
1683
1684
127k
  return true;
1685
899k
}
coff-x86_64.c:coff_bad_format_hook
Line
Count
Source
1678
2.73M
{
1679
2.73M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.73M
  if (BADMAG (*internal_f))
1682
2.56M
    return false;
1683
1684
168k
  return true;
1685
2.73M
}
Unexecuted instantiation: coff64-rs6000.c:coff_bad_format_hook
pe-aarch64.c:coff_bad_format_hook
Line
Count
Source
1678
2.73M
{
1679
2.73M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.73M
  if (BADMAG (*internal_f))
1682
2.67M
    return false;
1683
1684
60.8k
  return true;
1685
2.73M
}
pei-aarch64.c:coff_bad_format_hook
Line
Count
Source
1678
869k
{
1679
869k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
869k
  if (BADMAG (*internal_f))
1682
777k
    return false;
1683
1684
91.6k
  return true;
1685
869k
}
pei-ia64.c:coff_bad_format_hook
Line
Count
Source
1678
852k
{
1679
852k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
852k
  if (BADMAG (*internal_f))
1682
746k
    return false;
1683
1684
106k
  return true;
1685
852k
}
pei-loongarch64.c:coff_bad_format_hook
Line
Count
Source
1678
868k
{
1679
868k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
868k
  if (BADMAG (*internal_f))
1682
782k
    return false;
1683
1684
85.8k
  return true;
1685
868k
}
pei-riscv64.c:coff_bad_format_hook
Line
Count
Source
1678
868k
{
1679
868k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
868k
  if (BADMAG (*internal_f))
1682
789k
    return false;
1683
1684
79.0k
  return true;
1685
868k
}
cf-i386lynx.c:coff_bad_format_hook
Line
Count
Source
1678
2.73M
{
1679
2.73M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.73M
  if (BADMAG (*internal_f))
1682
2.66M
    return false;
1683
1684
70.1k
  return true;
1685
2.73M
}
coff-go32.c:coff_bad_format_hook
Line
Count
Source
1678
2.73M
{
1679
2.73M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.73M
  if (BADMAG (*internal_f))
1682
2.66M
    return false;
1683
1684
68.3k
  return true;
1685
2.73M
}
coff-i386.c:coff_bad_format_hook
Line
Count
Source
1678
2.73M
{
1679
2.73M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.73M
  if (BADMAG (*internal_f))
1682
2.66M
    return false;
1683
1684
68.3k
  return true;
1685
2.73M
}
coff-rs6000.c:coff_bad_format_hook
Line
Count
Source
1678
2.72M
{
1679
2.72M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.72M
  if (BADMAG (*internal_f))
1682
2.65M
    return false;
1683
1684
72.7k
  return true;
1685
2.72M
}
coff-sh.c:coff_bad_format_hook
Line
Count
Source
1678
10.7M
{
1679
10.7M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
10.7M
  if (BADMAG (*internal_f))
1682
10.6M
    return false;
1683
1684
100k
  return true;
1685
10.7M
}
coff-stgo32.c:coff_bad_format_hook
Line
Count
Source
1678
2.15k
{
1679
2.15k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.15k
  if (BADMAG (*internal_f))
1682
110
    return false;
1683
1684
2.04k
  return true;
1685
2.15k
}
coff-tic30.c:coff_bad_format_hook
Line
Count
Source
1678
2.72M
{
1679
2.72M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.72M
  if (BADMAG (*internal_f))
1682
2.68M
    return false;
1683
1684
40.8k
  return true;
1685
2.72M
}
Unexecuted instantiation: coff-tic4x.c:coff_bad_format_hook
coff-tic54x.c:coff_bad_format_hook
Line
Count
Source
1678
5.41M
{
1679
5.41M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.41M
  if (BADMAG (*internal_f))
1682
5.41M
    return false;
1683
1684
781
  return true;
1685
5.41M
}
coff-z80.c:coff_bad_format_hook
Line
Count
Source
1678
2.72M
{
1679
2.72M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.72M
  if (BADMAG (*internal_f))
1682
2.69M
    return false;
1683
1684
35.7k
  return true;
1685
2.72M
}
coff-z8k.c:coff_bad_format_hook
Line
Count
Source
1678
2.72M
{
1679
2.72M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.72M
  if (BADMAG (*internal_f))
1682
2.68M
    return false;
1683
1684
43.9k
  return true;
1685
2.72M
}
pe-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1678
5.45M
{
1679
5.45M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.45M
  if (BADMAG (*internal_f))
1682
5.42M
    return false;
1683
1684
28.8k
  return true;
1685
5.45M
}
pe-arm.c:coff_bad_format_hook
Line
Count
Source
1678
5.45M
{
1679
5.45M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.45M
  if (BADMAG (*internal_f))
1682
5.42M
    return false;
1683
1684
28.8k
  return true;
1685
5.45M
}
pe-i386.c:coff_bad_format_hook
Line
Count
Source
1678
5.17M
{
1679
5.17M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.17M
  if (BADMAG (*internal_f))
1682
5.09M
    return false;
1683
1684
84.5k
  return true;
1685
5.17M
}
pe-mcore.c:coff_bad_format_hook
Line
Count
Source
1678
5.45M
{
1679
5.45M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
5.45M
  if (BADMAG (*internal_f))
1682
5.39M
    return false;
1683
1684
63.0k
  return true;
1685
5.45M
}
pe-sh.c:coff_bad_format_hook
Line
Count
Source
1678
2.72M
{
1679
2.72M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
2.72M
  if (BADMAG (*internal_f))
1682
2.67M
    return false;
1683
1684
50.2k
  return true;
1685
2.72M
}
pei-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1678
867k
{
1679
867k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
867k
  if (BADMAG (*internal_f))
1682
724k
    return false;
1683
1684
143k
  return true;
1685
867k
}
pei-arm.c:coff_bad_format_hook
Line
Count
Source
1678
867k
{
1679
867k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
867k
  if (BADMAG (*internal_f))
1682
724k
    return false;
1683
1684
143k
  return true;
1685
867k
}
pei-mcore.c:coff_bad_format_hook
Line
Count
Source
1678
867k
{
1679
867k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
867k
  if (BADMAG (*internal_f))
1682
787k
    return false;
1683
1684
80.0k
  return true;
1685
867k
}
pei-sh.c:coff_bad_format_hook
Line
Count
Source
1678
867k
{
1679
867k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1680
1681
867k
  if (BADMAG (*internal_f))
1682
785k
    return false;
1683
1684
82.1k
  return true;
1685
867k
}
1686
1687
#ifdef TICOFF
1688
static bool
1689
ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1690
5.45M
{
1691
5.45M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1692
1693
5.45M
  if (COFF0_BADMAG (*internal_f))
1694
5.35M
    return false;
1695
1696
95.4k
  return true;
1697
5.45M
}
Unexecuted instantiation: coff-tic4x.c:ticoff0_bad_format_hook
coff-tic54x.c:ticoff0_bad_format_hook
Line
Count
Source
1690
5.45M
{
1691
5.45M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1692
1693
5.45M
  if (COFF0_BADMAG (*internal_f))
1694
5.35M
    return false;
1695
1696
95.4k
  return true;
1697
5.45M
}
1698
#endif
1699
1700
#ifdef TICOFF
1701
static bool
1702
ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1703
5.41M
{
1704
5.41M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1705
1706
5.41M
  if (COFF1_BADMAG (*internal_f))
1707
5.41M
    return false;
1708
1709
3.33k
  return true;
1710
5.41M
}
Unexecuted instantiation: coff-tic4x.c:ticoff1_bad_format_hook
coff-tic54x.c:ticoff1_bad_format_hook
Line
Count
Source
1703
5.41M
{
1704
5.41M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1705
1706
5.41M
  if (COFF1_BADMAG (*internal_f))
1707
5.41M
    return false;
1708
1709
3.33k
  return true;
1710
5.41M
}
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
84.9M
{
1722
84.9M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
84.9M
  unsigned int i;
1724
1725
481M
  for (i = 0; i < table_size; ++i)
1726
397M
    {
1727
397M
      const char *secname = bfd_section_name (section);
1728
1729
397M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
397M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
397M
    : strncmp (alignment_table[i].name, secname,
1732
217M
         alignment_table[i].comparison_length) == 0)
1733
641k
  break;
1734
397M
    }
1735
84.9M
  if (i >= table_size)
1736
84.3M
    return;
1737
1738
641k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
641k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
228k
    return;
1741
1742
412k
  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
412k
      )
1747
0
    return;
1748
1749
412k
  section->alignment_power = alignment_table[i].alignment_power;
1750
412k
}
pei-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
336k
{
1722
336k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
336k
  unsigned int i;
1724
1725
3.06M
  for (i = 0; i < table_size; ++i)
1726
2.76M
    {
1727
2.76M
      const char *secname = bfd_section_name (section);
1728
1729
2.76M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
2.76M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
2.76M
    : strncmp (alignment_table[i].name, secname,
1732
1.86M
         alignment_table[i].comparison_length) == 0)
1733
41.5k
  break;
1734
2.76M
    }
1735
336k
  if (i >= table_size)
1736
294k
    return;
1737
1738
41.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
41.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.14k
    return;
1741
1742
35.3k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
35.3k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
35.3k
      && default_alignment > alignment_table[i].default_alignment_max
1745
35.3k
#endif
1746
35.3k
      )
1747
0
    return;
1748
1749
35.3k
  section->alignment_power = alignment_table[i].alignment_power;
1750
35.3k
}
pe-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
659k
{
1722
659k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
659k
  unsigned int i;
1724
1725
9.62M
  for (i = 0; i < table_size; ++i)
1726
9.01M
    {
1727
9.01M
      const char *secname = bfd_section_name (section);
1728
1729
9.01M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
9.01M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
9.01M
    : strncmp (alignment_table[i].name, secname,
1732
6.45M
         alignment_table[i].comparison_length) == 0)
1733
41.4k
  break;
1734
9.01M
    }
1735
659k
  if (i >= table_size)
1736
617k
    return;
1737
1738
41.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
41.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
11.5k
    return;
1741
1742
29.8k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
29.8k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
29.8k
      && default_alignment > alignment_table[i].default_alignment_max
1745
29.8k
#endif
1746
29.8k
      )
1747
0
    return;
1748
1749
29.8k
  section->alignment_power = alignment_table[i].alignment_power;
1750
29.8k
}
pei-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
316k
{
1722
316k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
316k
  unsigned int i;
1724
1725
4.09M
  for (i = 0; i < table_size; ++i)
1726
3.82M
    {
1727
3.82M
      const char *secname = bfd_section_name (section);
1728
1729
3.82M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.82M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.82M
    : strncmp (alignment_table[i].name, secname,
1732
2.69M
         alignment_table[i].comparison_length) == 0)
1733
52.0k
  break;
1734
3.82M
    }
1735
316k
  if (i >= table_size)
1736
263k
    return;
1737
1738
52.0k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
52.0k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
15.5k
    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-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
10.9M
{
1722
10.9M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
10.9M
  unsigned int i;
1724
1725
54.4M
  for (i = 0; i < table_size; ++i)
1726
43.5M
    {
1727
43.5M
      const char *secname = bfd_section_name (section);
1728
1729
43.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
43.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
43.5M
    : strncmp (alignment_table[i].name, secname,
1732
21.7M
         alignment_table[i].comparison_length) == 0)
1733
35.2k
  break;
1734
43.5M
    }
1735
10.9M
  if (i >= table_size)
1736
10.8M
    return;
1737
1738
35.2k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
35.2k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
23.7k
    return;
1741
1742
11.5k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
11.5k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
11.5k
      && default_alignment > alignment_table[i].default_alignment_max
1745
11.5k
#endif
1746
11.5k
      )
1747
0
    return;
1748
1749
11.5k
  section->alignment_power = alignment_table[i].alignment_power;
1750
11.5k
}
coff64-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1721
2.00M
{
1722
2.00M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
2.00M
  unsigned int i;
1724
1725
10.0M
  for (i = 0; i < table_size; ++i)
1726
8.01M
    {
1727
8.01M
      const char *secname = bfd_section_name (section);
1728
1729
8.01M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
8.01M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
8.01M
    : strncmp (alignment_table[i].name, secname,
1732
4.01M
         alignment_table[i].comparison_length) == 0)
1733
13.4k
  break;
1734
8.01M
    }
1735
2.00M
  if (i >= table_size)
1736
1.99M
    return;
1737
1738
13.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
13.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
13.4k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
13.4k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
13.4k
      && default_alignment > alignment_table[i].default_alignment_max
1745
13.4k
#endif
1746
13.4k
      )
1747
0
    return;
1748
1749
13.4k
  section->alignment_power = alignment_table[i].alignment_power;
1750
13.4k
}
pe-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
199k
{
1722
199k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
199k
  unsigned int i;
1724
1725
2.76M
  for (i = 0; i < table_size; ++i)
1726
2.57M
    {
1727
2.57M
      const char *secname = bfd_section_name (section);
1728
1729
2.57M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
2.57M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
2.57M
    : strncmp (alignment_table[i].name, secname,
1732
1.18M
         alignment_table[i].comparison_length) == 0)
1733
5.11k
  break;
1734
2.57M
    }
1735
199k
  if (i >= table_size)
1736
194k
    return;
1737
1738
5.11k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
5.11k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
1.60k
    return;
1741
1742
3.51k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
3.51k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
3.51k
      && default_alignment > alignment_table[i].default_alignment_max
1745
3.51k
#endif
1746
3.51k
      )
1747
0
    return;
1748
1749
3.51k
  section->alignment_power = alignment_table[i].alignment_power;
1750
3.51k
}
pei-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
293k
{
1722
293k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
293k
  unsigned int i;
1724
1725
3.87M
  for (i = 0; i < table_size; ++i)
1726
3.61M
    {
1727
3.61M
      const char *secname = bfd_section_name (section);
1728
1729
3.61M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.61M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.61M
    : strncmp (alignment_table[i].name, secname,
1732
1.64M
         alignment_table[i].comparison_length) == 0)
1733
28.6k
  break;
1734
3.61M
    }
1735
293k
  if (i >= table_size)
1736
264k
    return;
1737
1738
28.6k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
28.6k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.40k
    return;
1741
1742
25.2k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
25.2k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
25.2k
      && default_alignment > alignment_table[i].default_alignment_max
1745
25.2k
#endif
1746
25.2k
      )
1747
0
    return;
1748
1749
25.2k
  section->alignment_power = alignment_table[i].alignment_power;
1750
25.2k
}
pei-ia64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
246k
{
1722
246k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
246k
  unsigned int i;
1724
1725
1.20M
  for (i = 0; i < table_size; ++i)
1726
968k
    {
1727
968k
      const char *secname = bfd_section_name (section);
1728
1729
968k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
968k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
968k
    : strncmp (alignment_table[i].name, secname,
1732
490k
         alignment_table[i].comparison_length) == 0)
1733
8.18k
  break;
1734
968k
    }
1735
246k
  if (i >= table_size)
1736
237k
    return;
1737
1738
8.18k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
8.18k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.25k
    return;
1741
1742
1.93k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
1.93k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
1.93k
      && default_alignment > alignment_table[i].default_alignment_max
1745
1.93k
#endif
1746
1.93k
      )
1747
0
    return;
1748
1749
1.93k
  section->alignment_power = alignment_table[i].alignment_power;
1750
1.93k
}
pei-loongarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
253k
{
1722
253k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
253k
  unsigned int i;
1724
1725
3.36M
  for (i = 0; i < table_size; ++i)
1726
3.13M
    {
1727
3.13M
      const char *secname = bfd_section_name (section);
1728
1729
3.13M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.13M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.13M
    : strncmp (alignment_table[i].name, secname,
1732
1.42M
         alignment_table[i].comparison_length) == 0)
1733
25.2k
  break;
1734
3.13M
    }
1735
253k
  if (i >= table_size)
1736
228k
    return;
1737
1738
25.2k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
25.2k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.74k
    return;
1741
1742
21.4k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
21.4k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
21.4k
      && default_alignment > alignment_table[i].default_alignment_max
1745
21.4k
#endif
1746
21.4k
      )
1747
0
    return;
1748
1749
21.4k
  section->alignment_power = alignment_table[i].alignment_power;
1750
21.4k
}
pei-riscv64.c:coff_set_custom_section_alignment
Line
Count
Source
1721
245k
{
1722
245k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
245k
  unsigned int i;
1724
1725
3.20M
  for (i = 0; i < table_size; ++i)
1726
2.98M
    {
1727
2.98M
      const char *secname = bfd_section_name (section);
1728
1729
2.98M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
2.98M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
2.98M
    : strncmp (alignment_table[i].name, secname,
1732
1.34M
         alignment_table[i].comparison_length) == 0)
1733
29.3k
  break;
1734
2.98M
    }
1735
245k
  if (i >= table_size)
1736
216k
    return;
1737
1738
29.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
29.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
3.09k
    return;
1741
1742
26.2k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
26.2k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
26.2k
      && default_alignment > alignment_table[i].default_alignment_max
1745
26.2k
#endif
1746
26.2k
      )
1747
0
    return;
1748
1749
26.2k
  section->alignment_power = alignment_table[i].alignment_power;
1750
26.2k
}
cf-i386lynx.c:coff_set_custom_section_alignment
Line
Count
Source
1721
4.37M
{
1722
4.37M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
4.37M
  unsigned int i;
1724
1725
21.8M
  for (i = 0; i < table_size; ++i)
1726
17.4M
    {
1727
17.4M
      const char *secname = bfd_section_name (section);
1728
1729
17.4M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
17.4M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
17.4M
    : strncmp (alignment_table[i].name, secname,
1732
8.74M
         alignment_table[i].comparison_length) == 0)
1733
15.0k
  break;
1734
17.4M
    }
1735
4.37M
  if (i >= table_size)
1736
4.35M
    return;
1737
1738
15.0k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
15.0k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
9.73k
    return;
1741
1742
5.36k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
5.36k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
5.36k
      && default_alignment > alignment_table[i].default_alignment_max
1745
5.36k
#endif
1746
5.36k
      )
1747
0
    return;
1748
1749
5.36k
  section->alignment_power = alignment_table[i].alignment_power;
1750
5.36k
}
coff-go32.c:coff_set_custom_section_alignment
Line
Count
Source
1721
2.85M
{
1722
2.85M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
2.85M
  unsigned int i;
1724
1725
45.3M
  for (i = 0; i < table_size; ++i)
1726
42.5M
    {
1727
42.5M
      const char *secname = bfd_section_name (section);
1728
1729
42.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
42.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
42.5M
    : strncmp (alignment_table[i].name, secname,
1732
36.8M
         alignment_table[i].comparison_length) == 0)
1733
28.9k
  break;
1734
42.5M
    }
1735
2.85M
  if (i >= table_size)
1736
2.82M
    return;
1737
1738
28.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
28.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.38k
    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
}
coff-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
3.87M
{
1722
3.87M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
3.87M
  unsigned int i;
1724
1725
19.3M
  for (i = 0; i < table_size; ++i)
1726
15.4M
    {
1727
15.4M
      const char *secname = bfd_section_name (section);
1728
1729
15.4M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
15.4M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
15.4M
    : strncmp (alignment_table[i].name, secname,
1732
7.75M
         alignment_table[i].comparison_length) == 0)
1733
11.4k
  break;
1734
15.4M
    }
1735
3.87M
  if (i >= table_size)
1736
3.86M
    return;
1737
1738
11.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
11.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
7.87k
    return;
1741
1742
3.59k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
3.59k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
3.59k
      && default_alignment > alignment_table[i].default_alignment_max
1745
3.59k
#endif
1746
3.59k
      )
1747
0
    return;
1748
1749
3.59k
  section->alignment_power = alignment_table[i].alignment_power;
1750
3.59k
}
coff-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1721
22.3M
{
1722
22.3M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
22.3M
  unsigned int i;
1724
1725
111M
  for (i = 0; i < table_size; ++i)
1726
89.4M
    {
1727
89.4M
      const char *secname = bfd_section_name (section);
1728
1729
89.4M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
89.4M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
89.4M
    : strncmp (alignment_table[i].name, secname,
1732
44.7M
         alignment_table[i].comparison_length) == 0)
1733
38.7k
  break;
1734
89.4M
    }
1735
22.3M
  if (i >= table_size)
1736
22.3M
    return;
1737
1738
38.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
38.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
38.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
38.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
38.7k
      && default_alignment > alignment_table[i].default_alignment_max
1745
38.7k
#endif
1746
38.7k
      )
1747
0
    return;
1748
1749
38.7k
  section->alignment_power = alignment_table[i].alignment_power;
1750
38.7k
}
coff-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
6.73M
{
1722
6.73M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
6.73M
  unsigned int i;
1724
1725
33.6M
  for (i = 0; i < table_size; ++i)
1726
26.8M
    {
1727
26.8M
      const char *secname = bfd_section_name (section);
1728
1729
26.8M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
26.8M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
26.8M
    : strncmp (alignment_table[i].name, secname,
1732
13.4M
         alignment_table[i].comparison_length) == 0)
1733
19.9k
  break;
1734
26.8M
    }
1735
6.73M
  if (i >= table_size)
1736
6.71M
    return;
1737
1738
19.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
19.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
0
    return;
1741
1742
19.9k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
19.9k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
19.9k
      && default_alignment > alignment_table[i].default_alignment_max
1745
19.9k
#endif
1746
19.9k
      )
1747
0
    return;
1748
1749
19.9k
  section->alignment_power = alignment_table[i].alignment_power;
1750
19.9k
}
coff-stgo32.c:coff_set_custom_section_alignment
Line
Count
Source
1721
513k
{
1722
513k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
513k
  unsigned int i;
1724
1725
4.59M
  for (i = 0; i < table_size; ++i)
1726
4.08M
    {
1727
4.08M
      const char *secname = bfd_section_name (section);
1728
1729
4.08M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
4.08M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
4.08M
    : strncmp (alignment_table[i].name, secname,
1732
2.04M
         alignment_table[i].comparison_length) == 0)
1733
5.77k
  break;
1734
4.08M
    }
1735
513k
  if (i >= table_size)
1736
507k
    return;
1737
1738
5.77k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
5.77k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
1.89k
    return;
1741
1742
3.88k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
3.88k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
3.88k
      && default_alignment > alignment_table[i].default_alignment_max
1745
3.88k
#endif
1746
3.88k
      )
1747
0
    return;
1748
1749
3.88k
  section->alignment_power = alignment_table[i].alignment_power;
1750
3.88k
}
coff-tic30.c:coff_set_custom_section_alignment
Line
Count
Source
1721
4.73M
{
1722
4.73M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
4.73M
  unsigned int i;
1724
1725
23.6M
  for (i = 0; i < table_size; ++i)
1726
18.8M
    {
1727
18.8M
      const char *secname = bfd_section_name (section);
1728
1729
18.8M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
18.8M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
18.8M
    : strncmp (alignment_table[i].name, secname,
1732
9.45M
         alignment_table[i].comparison_length) == 0)
1733
21.4k
  break;
1734
18.8M
    }
1735
4.73M
  if (i >= table_size)
1736
4.71M
    return;
1737
1738
21.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
21.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
14.6k
    return;
1741
1742
6.85k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
6.85k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
6.85k
      && default_alignment > alignment_table[i].default_alignment_max
1745
6.85k
#endif
1746
6.85k
      )
1747
0
    return;
1748
1749
6.85k
  section->alignment_power = alignment_table[i].alignment_power;
1750
6.85k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_custom_section_alignment
coff-tic54x.c:coff_set_custom_section_alignment
Line
Count
Source
1721
7.89M
{
1722
7.89M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
7.89M
  unsigned int i;
1724
1725
39.3M
  for (i = 0; i < table_size; ++i)
1726
31.5M
    {
1727
31.5M
      const char *secname = bfd_section_name (section);
1728
1729
31.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
31.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
31.5M
    : strncmp (alignment_table[i].name, secname,
1732
15.7M
         alignment_table[i].comparison_length) == 0)
1733
24.9k
  break;
1734
31.5M
    }
1735
7.89M
  if (i >= table_size)
1736
7.86M
    return;
1737
1738
24.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
24.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
24.9k
    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.20M
{
1722
1.20M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
1.20M
  unsigned int i;
1724
1725
5.97M
  for (i = 0; i < table_size; ++i)
1726
4.78M
    {
1727
4.78M
      const char *secname = bfd_section_name (section);
1728
1729
4.78M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
4.78M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
4.78M
    : strncmp (alignment_table[i].name, secname,
1732
2.40M
         alignment_table[i].comparison_length) == 0)
1733
14.3k
  break;
1734
4.78M
    }
1735
1.20M
  if (i >= table_size)
1736
1.18M
    return;
1737
1738
14.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
14.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
14.3k
    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
13.4M
{
1722
13.4M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
13.4M
  unsigned int i;
1724
1725
66.9M
  for (i = 0; i < table_size; ++i)
1726
53.5M
    {
1727
53.5M
      const char *secname = bfd_section_name (section);
1728
1729
53.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
53.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
53.5M
    : strncmp (alignment_table[i].name, secname,
1732
26.8M
         alignment_table[i].comparison_length) == 0)
1733
49.3k
  break;
1734
53.5M
    }
1735
13.4M
  if (i >= table_size)
1736
13.3M
    return;
1737
1738
49.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
49.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
30.1k
    return;
1741
1742
19.1k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
19.1k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
19.1k
      && default_alignment > alignment_table[i].default_alignment_max
1745
19.1k
#endif
1746
19.1k
      )
1747
0
    return;
1748
1749
19.1k
  section->alignment_power = alignment_table[i].alignment_power;
1750
19.1k
}
pe-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1721
59.1k
{
1722
59.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
59.1k
  unsigned int i;
1724
1725
835k
  for (i = 0; i < table_size; ++i)
1726
785k
    {
1727
785k
      const char *secname = bfd_section_name (section);
1728
1729
785k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
785k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
785k
    : strncmp (alignment_table[i].name, secname,
1732
390k
         alignment_table[i].comparison_length) == 0)
1733
9.60k
  break;
1734
785k
    }
1735
59.1k
  if (i >= table_size)
1736
49.5k
    return;
1737
1738
9.60k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
9.60k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
2.80k
    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
}
pe-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1721
59.1k
{
1722
59.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
59.1k
  unsigned int i;
1724
1725
835k
  for (i = 0; i < table_size; ++i)
1726
785k
    {
1727
785k
      const char *secname = bfd_section_name (section);
1728
1729
785k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
785k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
785k
    : strncmp (alignment_table[i].name, secname,
1732
390k
         alignment_table[i].comparison_length) == 0)
1733
9.60k
  break;
1734
785k
    }
1735
59.1k
  if (i >= table_size)
1736
49.5k
    return;
1737
1738
9.60k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
9.60k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
2.80k
    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
}
pe-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1721
130k
{
1722
130k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
130k
  unsigned int i;
1724
1725
1.36M
  for (i = 0; i < table_size; ++i)
1726
1.25M
    {
1727
1.25M
      const char *secname = bfd_section_name (section);
1728
1729
1.25M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
1.25M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
1.25M
    : strncmp (alignment_table[i].name, secname,
1732
887k
         alignment_table[i].comparison_length) == 0)
1733
16.0k
  break;
1734
1.25M
    }
1735
130k
  if (i >= table_size)
1736
114k
    return;
1737
1738
16.0k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
16.0k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
6.59k
    return;
1741
1742
9.45k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
9.45k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
9.45k
      && default_alignment > alignment_table[i].default_alignment_max
1745
9.45k
#endif
1746
9.45k
      )
1747
0
    return;
1748
1749
9.45k
  section->alignment_power = alignment_table[i].alignment_power;
1750
9.45k
}
pe-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1721
170k
{
1722
170k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
170k
  unsigned int i;
1724
1725
829k
  for (i = 0; i < table_size; ++i)
1726
666k
    {
1727
666k
      const char *secname = bfd_section_name (section);
1728
1729
666k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
666k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
666k
    : strncmp (alignment_table[i].name, secname,
1732
338k
         alignment_table[i].comparison_length) == 0)
1733
7.46k
  break;
1734
666k
    }
1735
170k
  if (i >= table_size)
1736
162k
    return;
1737
1738
7.46k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
7.46k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
5.93k
    return;
1741
1742
1.53k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
1.53k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
1.53k
      && default_alignment > alignment_table[i].default_alignment_max
1745
1.53k
#endif
1746
1.53k
      )
1747
0
    return;
1748
1749
1.53k
  section->alignment_power = alignment_table[i].alignment_power;
1750
1.53k
}
pe-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
121k
{
1722
121k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
121k
  unsigned int i;
1724
1725
592k
  for (i = 0; i < table_size; ++i)
1726
475k
    {
1727
475k
      const char *secname = bfd_section_name (section);
1728
1729
475k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
475k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
475k
    : strncmp (alignment_table[i].name, secname,
1732
241k
         alignment_table[i].comparison_length) == 0)
1733
4.85k
  break;
1734
475k
    }
1735
121k
  if (i >= table_size)
1736
116k
    return;
1737
1738
4.85k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
4.85k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.03k
    return;
1741
1742
825
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
825
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
825
      && default_alignment > alignment_table[i].default_alignment_max
1745
825
#endif
1746
825
      )
1747
0
    return;
1748
1749
825
  section->alignment_power = alignment_table[i].alignment_power;
1750
825
}
pei-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1721
213k
{
1722
213k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
213k
  unsigned int i;
1724
1725
2.92M
  for (i = 0; i < table_size; ++i)
1726
2.72M
    {
1727
2.72M
      const char *secname = bfd_section_name (section);
1728
1729
2.72M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
2.72M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
2.72M
    : strncmp (alignment_table[i].name, secname,
1732
1.25M
         alignment_table[i].comparison_length) == 0)
1733
11.9k
  break;
1734
2.72M
    }
1735
213k
  if (i >= table_size)
1736
201k
    return;
1737
1738
11.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
11.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.50k
    return;
1741
1742
7.44k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
7.44k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
7.44k
      && default_alignment > alignment_table[i].default_alignment_max
1745
7.44k
#endif
1746
7.44k
      )
1747
0
    return;
1748
1749
7.44k
  section->alignment_power = alignment_table[i].alignment_power;
1750
7.44k
}
pei-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1721
316k
{
1722
316k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
316k
  unsigned int i;
1724
1725
3.96M
  for (i = 0; i < table_size; ++i)
1726
3.70M
    {
1727
3.70M
      const char *secname = bfd_section_name (section);
1728
1729
3.70M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
3.70M
    ? strcmp (alignment_table[i].name, secname) == 0
1731
3.70M
    : strncmp (alignment_table[i].name, secname,
1732
1.65M
         alignment_table[i].comparison_length) == 0)
1733
56.4k
  break;
1734
3.70M
    }
1735
316k
  if (i >= table_size)
1736
259k
    return;
1737
1738
56.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
56.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
5.61k
    return;
1741
1742
50.8k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
50.8k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
50.8k
      && default_alignment > alignment_table[i].default_alignment_max
1745
50.8k
#endif
1746
50.8k
      )
1747
0
    return;
1748
1749
50.8k
  section->alignment_power = alignment_table[i].alignment_power;
1750
50.8k
}
pei-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1721
203k
{
1722
203k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
203k
  unsigned int i;
1724
1725
992k
  for (i = 0; i < table_size; ++i)
1726
797k
    {
1727
797k
      const char *secname = bfd_section_name (section);
1728
1729
797k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
797k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
797k
    : strncmp (alignment_table[i].name, secname,
1732
404k
         alignment_table[i].comparison_length) == 0)
1733
7.60k
  break;
1734
797k
    }
1735
203k
  if (i >= table_size)
1736
195k
    return;
1737
1738
7.60k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
7.60k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
5.98k
    return;
1741
1742
1.62k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
1.62k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
1.62k
      && default_alignment > alignment_table[i].default_alignment_max
1745
1.62k
#endif
1746
1.62k
      )
1747
0
    return;
1748
1749
1.62k
  section->alignment_power = alignment_table[i].alignment_power;
1750
1.62k
}
pei-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1721
252k
{
1722
252k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1723
252k
  unsigned int i;
1724
1725
1.24M
  for (i = 0; i < table_size; ++i)
1726
995k
    {
1727
995k
      const char *secname = bfd_section_name (section);
1728
1729
995k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1730
995k
    ? strcmp (alignment_table[i].name, secname) == 0
1731
995k
    : strncmp (alignment_table[i].name, secname,
1732
503k
         alignment_table[i].comparison_length) == 0)
1733
7.17k
  break;
1734
995k
    }
1735
252k
  if (i >= table_size)
1736
245k
    return;
1737
1738
7.17k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1739
7.17k
      && default_alignment < alignment_table[i].default_alignment_min)
1740
4.97k
    return;
1741
1742
2.20k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1743
2.20k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1744
2.20k
      && default_alignment > alignment_table[i].default_alignment_max
1745
2.20k
#endif
1746
2.20k
      )
1747
0
    return;
1748
1749
2.20k
  section->alignment_power = alignment_table[i].alignment_power;
1750
2.20k
}
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
84.9M
{
1782
84.9M
  combined_entry_type *native;
1783
84.9M
  size_t amt;
1784
84.9M
  unsigned char sclass = C_STAT;
1785
1786
84.9M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
#ifdef RS6000COFF_C
1789
24.3M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
24.3M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
33.2k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
24.3M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
24.3M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
21.8k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
24.3M
  else
1796
24.3M
    {
1797
24.3M
      int i;
1798
1799
291M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
267M
  if (strcmp (bfd_section_name (section),
1801
267M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
11.2k
    {
1803
11.2k
      section->alignment_power = 0;
1804
11.2k
      sclass = C_DWARF;
1805
11.2k
      break;
1806
11.2k
    }
1807
24.3M
    }
1808
#endif
1809
1810
  /* Set up the section symbol.  */
1811
84.9M
  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
84.9M
  amt = sizeof (combined_entry_type) * 10;
1820
84.9M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
84.9M
  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
84.9M
  native->is_sym = true;
1831
84.9M
  native->u.syment.n_type = T_NULL;
1832
84.9M
  native->u.syment.n_sclass = sclass;
1833
1834
84.9M
  coffsymbol (section->symbol)->native = native;
1835
1836
84.9M
  coff_set_custom_section_alignment (abfd, section,
1837
84.9M
             coff_section_alignment_table,
1838
84.9M
             coff_section_alignment_table_size);
1839
1840
84.9M
  return true;
1841
84.9M
}
pei-i386.c:coff_new_section_hook
Line
Count
Source
1781
336k
{
1782
336k
  combined_entry_type *native;
1783
336k
  size_t amt;
1784
336k
  unsigned char sclass = C_STAT;
1785
1786
336k
  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
336k
  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
336k
  amt = sizeof (combined_entry_type) * 10;
1820
336k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
336k
  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
336k
  native->is_sym = true;
1831
336k
  native->u.syment.n_type = T_NULL;
1832
336k
  native->u.syment.n_sclass = sclass;
1833
1834
336k
  coffsymbol (section->symbol)->native = native;
1835
1836
336k
  coff_set_custom_section_alignment (abfd, section,
1837
336k
             coff_section_alignment_table,
1838
336k
             coff_section_alignment_table_size);
1839
1840
336k
  return true;
1841
336k
}
pe-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
659k
{
1782
659k
  combined_entry_type *native;
1783
659k
  size_t amt;
1784
659k
  unsigned char sclass = C_STAT;
1785
1786
659k
  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
659k
  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
659k
  amt = sizeof (combined_entry_type) * 10;
1820
659k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
659k
  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
659k
  native->is_sym = true;
1831
659k
  native->u.syment.n_type = T_NULL;
1832
659k
  native->u.syment.n_sclass = sclass;
1833
1834
659k
  coffsymbol (section->symbol)->native = native;
1835
1836
659k
  coff_set_custom_section_alignment (abfd, section,
1837
659k
             coff_section_alignment_table,
1838
659k
             coff_section_alignment_table_size);
1839
1840
659k
  return true;
1841
659k
}
pei-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
316k
{
1782
316k
  combined_entry_type *native;
1783
316k
  size_t amt;
1784
316k
  unsigned char sclass = C_STAT;
1785
1786
316k
  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
316k
  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
316k
  amt = sizeof (combined_entry_type) * 10;
1820
316k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
316k
  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
316k
  native->is_sym = true;
1831
316k
  native->u.syment.n_type = T_NULL;
1832
316k
  native->u.syment.n_sclass = sclass;
1833
1834
316k
  coffsymbol (section->symbol)->native = native;
1835
1836
316k
  coff_set_custom_section_alignment (abfd, section,
1837
316k
             coff_section_alignment_table,
1838
316k
             coff_section_alignment_table_size);
1839
1840
316k
  return true;
1841
316k
}
coff-x86_64.c:coff_new_section_hook
Line
Count
Source
1781
10.9M
{
1782
10.9M
  combined_entry_type *native;
1783
10.9M
  size_t amt;
1784
10.9M
  unsigned char sclass = C_STAT;
1785
1786
10.9M
  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.9M
  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.9M
  amt = sizeof (combined_entry_type) * 10;
1820
10.9M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
10.9M
  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.9M
  native->is_sym = true;
1831
10.9M
  native->u.syment.n_type = T_NULL;
1832
10.9M
  native->u.syment.n_sclass = sclass;
1833
1834
10.9M
  coffsymbol (section->symbol)->native = native;
1835
1836
10.9M
  coff_set_custom_section_alignment (abfd, section,
1837
10.9M
             coff_section_alignment_table,
1838
10.9M
             coff_section_alignment_table_size);
1839
1840
10.9M
  return true;
1841
10.9M
}
coff64-rs6000.c:coff_new_section_hook
Line
Count
Source
1781
2.00M
{
1782
2.00M
  combined_entry_type *native;
1783
2.00M
  size_t amt;
1784
2.00M
  unsigned char sclass = C_STAT;
1785
1786
2.00M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
2.00M
#ifdef RS6000COFF_C
1789
2.00M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
2.00M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
6.50k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
2.00M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
2.00M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
5.20k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
1.99M
  else
1796
1.99M
    {
1797
1.99M
      int i;
1798
1799
23.9M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
21.9M
  if (strcmp (bfd_section_name (section),
1801
21.9M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
2.96k
    {
1803
2.96k
      section->alignment_power = 0;
1804
2.96k
      sclass = C_DWARF;
1805
2.96k
      break;
1806
2.96k
    }
1807
1.99M
    }
1808
2.00M
#endif
1809
1810
  /* Set up the section symbol.  */
1811
2.00M
  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
2.00M
  amt = sizeof (combined_entry_type) * 10;
1820
2.00M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
2.00M
  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
2.00M
  native->is_sym = true;
1831
2.00M
  native->u.syment.n_type = T_NULL;
1832
2.00M
  native->u.syment.n_sclass = sclass;
1833
1834
2.00M
  coffsymbol (section->symbol)->native = native;
1835
1836
2.00M
  coff_set_custom_section_alignment (abfd, section,
1837
2.00M
             coff_section_alignment_table,
1838
2.00M
             coff_section_alignment_table_size);
1839
1840
2.00M
  return true;
1841
2.00M
}
pe-aarch64.c:coff_new_section_hook
Line
Count
Source
1781
199k
{
1782
199k
  combined_entry_type *native;
1783
199k
  size_t amt;
1784
199k
  unsigned char sclass = C_STAT;
1785
1786
199k
  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
199k
  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
199k
  amt = sizeof (combined_entry_type) * 10;
1820
199k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
199k
  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
199k
  native->is_sym = true;
1831
199k
  native->u.syment.n_type = T_NULL;
1832
199k
  native->u.syment.n_sclass = sclass;
1833
1834
199k
  coffsymbol (section->symbol)->native = native;
1835
1836
199k
  coff_set_custom_section_alignment (abfd, section,
1837
199k
             coff_section_alignment_table,
1838
199k
             coff_section_alignment_table_size);
1839
1840
199k
  return true;
1841
199k
}
pei-aarch64.c:coff_new_section_hook
Line
Count
Source
1781
293k
{
1782
293k
  combined_entry_type *native;
1783
293k
  size_t amt;
1784
293k
  unsigned char sclass = C_STAT;
1785
1786
293k
  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
293k
  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
293k
  amt = sizeof (combined_entry_type) * 10;
1820
293k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
293k
  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
293k
  native->is_sym = true;
1831
293k
  native->u.syment.n_type = T_NULL;
1832
293k
  native->u.syment.n_sclass = sclass;
1833
1834
293k
  coffsymbol (section->symbol)->native = native;
1835
1836
293k
  coff_set_custom_section_alignment (abfd, section,
1837
293k
             coff_section_alignment_table,
1838
293k
             coff_section_alignment_table_size);
1839
1840
293k
  return true;
1841
293k
}
pei-ia64.c:coff_new_section_hook
Line
Count
Source
1781
246k
{
1782
246k
  combined_entry_type *native;
1783
246k
  size_t amt;
1784
246k
  unsigned char sclass = C_STAT;
1785
1786
246k
  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
246k
  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
246k
  amt = sizeof (combined_entry_type) * 10;
1820
246k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
246k
  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
246k
  native->is_sym = true;
1831
246k
  native->u.syment.n_type = T_NULL;
1832
246k
  native->u.syment.n_sclass = sclass;
1833
1834
246k
  coffsymbol (section->symbol)->native = native;
1835
1836
246k
  coff_set_custom_section_alignment (abfd, section,
1837
246k
             coff_section_alignment_table,
1838
246k
             coff_section_alignment_table_size);
1839
1840
246k
  return true;
1841
246k
}
pei-loongarch64.c:coff_new_section_hook
Line
Count
Source
1781
253k
{
1782
253k
  combined_entry_type *native;
1783
253k
  size_t amt;
1784
253k
  unsigned char sclass = C_STAT;
1785
1786
253k
  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
253k
  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
253k
  amt = sizeof (combined_entry_type) * 10;
1820
253k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
253k
  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
253k
  native->is_sym = true;
1831
253k
  native->u.syment.n_type = T_NULL;
1832
253k
  native->u.syment.n_sclass = sclass;
1833
1834
253k
  coffsymbol (section->symbol)->native = native;
1835
1836
253k
  coff_set_custom_section_alignment (abfd, section,
1837
253k
             coff_section_alignment_table,
1838
253k
             coff_section_alignment_table_size);
1839
1840
253k
  return true;
1841
253k
}
pei-riscv64.c:coff_new_section_hook
Line
Count
Source
1781
245k
{
1782
245k
  combined_entry_type *native;
1783
245k
  size_t amt;
1784
245k
  unsigned char sclass = C_STAT;
1785
1786
245k
  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
245k
  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
245k
  amt = sizeof (combined_entry_type) * 10;
1820
245k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
245k
  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
245k
  native->is_sym = true;
1831
245k
  native->u.syment.n_type = T_NULL;
1832
245k
  native->u.syment.n_sclass = sclass;
1833
1834
245k
  coffsymbol (section->symbol)->native = native;
1835
1836
245k
  coff_set_custom_section_alignment (abfd, section,
1837
245k
             coff_section_alignment_table,
1838
245k
             coff_section_alignment_table_size);
1839
1840
245k
  return true;
1841
245k
}
cf-i386lynx.c:coff_new_section_hook
Line
Count
Source
1781
4.37M
{
1782
4.37M
  combined_entry_type *native;
1783
4.37M
  size_t amt;
1784
4.37M
  unsigned char sclass = C_STAT;
1785
1786
4.37M
  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
4.37M
  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
4.37M
  amt = sizeof (combined_entry_type) * 10;
1820
4.37M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
4.37M
  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
4.37M
  native->is_sym = true;
1831
4.37M
  native->u.syment.n_type = T_NULL;
1832
4.37M
  native->u.syment.n_sclass = sclass;
1833
1834
4.37M
  coffsymbol (section->symbol)->native = native;
1835
1836
4.37M
  coff_set_custom_section_alignment (abfd, section,
1837
4.37M
             coff_section_alignment_table,
1838
4.37M
             coff_section_alignment_table_size);
1839
1840
4.37M
  return true;
1841
4.37M
}
coff-go32.c:coff_new_section_hook
Line
Count
Source
1781
2.85M
{
1782
2.85M
  combined_entry_type *native;
1783
2.85M
  size_t amt;
1784
2.85M
  unsigned char sclass = C_STAT;
1785
1786
2.85M
  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
2.85M
  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
2.85M
  amt = sizeof (combined_entry_type) * 10;
1820
2.85M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
2.85M
  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
2.85M
  native->is_sym = true;
1831
2.85M
  native->u.syment.n_type = T_NULL;
1832
2.85M
  native->u.syment.n_sclass = sclass;
1833
1834
2.85M
  coffsymbol (section->symbol)->native = native;
1835
1836
2.85M
  coff_set_custom_section_alignment (abfd, section,
1837
2.85M
             coff_section_alignment_table,
1838
2.85M
             coff_section_alignment_table_size);
1839
1840
2.85M
  return true;
1841
2.85M
}
coff-i386.c:coff_new_section_hook
Line
Count
Source
1781
3.87M
{
1782
3.87M
  combined_entry_type *native;
1783
3.87M
  size_t amt;
1784
3.87M
  unsigned char sclass = C_STAT;
1785
1786
3.87M
  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
3.87M
  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.87M
  amt = sizeof (combined_entry_type) * 10;
1820
3.87M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
3.87M
  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.87M
  native->is_sym = true;
1831
3.87M
  native->u.syment.n_type = T_NULL;
1832
3.87M
  native->u.syment.n_sclass = sclass;
1833
1834
3.87M
  coffsymbol (section->symbol)->native = native;
1835
1836
3.87M
  coff_set_custom_section_alignment (abfd, section,
1837
3.87M
             coff_section_alignment_table,
1838
3.87M
             coff_section_alignment_table_size);
1839
1840
3.87M
  return true;
1841
3.87M
}
coff-rs6000.c:coff_new_section_hook
Line
Count
Source
1781
22.3M
{
1782
22.3M
  combined_entry_type *native;
1783
22.3M
  size_t amt;
1784
22.3M
  unsigned char sclass = C_STAT;
1785
1786
22.3M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1787
1788
22.3M
#ifdef RS6000COFF_C
1789
22.3M
  if (bfd_xcoff_text_align_power (abfd) != 0
1790
22.3M
      && strcmp (bfd_section_name (section), ".text") == 0)
1791
26.7k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1792
22.3M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1793
22.3M
      && strcmp (bfd_section_name (section), ".data") == 0)
1794
16.6k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1795
22.3M
  else
1796
22.3M
    {
1797
22.3M
      int i;
1798
1799
267M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1800
245M
  if (strcmp (bfd_section_name (section),
1801
245M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1802
8.26k
    {
1803
8.26k
      section->alignment_power = 0;
1804
8.26k
      sclass = C_DWARF;
1805
8.26k
      break;
1806
8.26k
    }
1807
22.3M
    }
1808
22.3M
#endif
1809
1810
  /* Set up the section symbol.  */
1811
22.3M
  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
22.3M
  amt = sizeof (combined_entry_type) * 10;
1820
22.3M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
22.3M
  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
22.3M
  native->is_sym = true;
1831
22.3M
  native->u.syment.n_type = T_NULL;
1832
22.3M
  native->u.syment.n_sclass = sclass;
1833
1834
22.3M
  coffsymbol (section->symbol)->native = native;
1835
1836
22.3M
  coff_set_custom_section_alignment (abfd, section,
1837
22.3M
             coff_section_alignment_table,
1838
22.3M
             coff_section_alignment_table_size);
1839
1840
22.3M
  return true;
1841
22.3M
}
coff-sh.c:coff_new_section_hook
Line
Count
Source
1781
6.73M
{
1782
6.73M
  combined_entry_type *native;
1783
6.73M
  size_t amt;
1784
6.73M
  unsigned char sclass = C_STAT;
1785
1786
6.73M
  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.73M
  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.73M
  amt = sizeof (combined_entry_type) * 10;
1820
6.73M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
6.73M
  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.73M
  native->is_sym = true;
1831
6.73M
  native->u.syment.n_type = T_NULL;
1832
6.73M
  native->u.syment.n_sclass = sclass;
1833
1834
6.73M
  coffsymbol (section->symbol)->native = native;
1835
1836
6.73M
  coff_set_custom_section_alignment (abfd, section,
1837
6.73M
             coff_section_alignment_table,
1838
6.73M
             coff_section_alignment_table_size);
1839
1840
6.73M
  return true;
1841
6.73M
}
coff-stgo32.c:coff_new_section_hook
Line
Count
Source
1781
513k
{
1782
513k
  combined_entry_type *native;
1783
513k
  size_t amt;
1784
513k
  unsigned char sclass = C_STAT;
1785
1786
513k
  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
513k
  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
513k
  amt = sizeof (combined_entry_type) * 10;
1820
513k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
513k
  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
513k
  native->is_sym = true;
1831
513k
  native->u.syment.n_type = T_NULL;
1832
513k
  native->u.syment.n_sclass = sclass;
1833
1834
513k
  coffsymbol (section->symbol)->native = native;
1835
1836
513k
  coff_set_custom_section_alignment (abfd, section,
1837
513k
             coff_section_alignment_table,
1838
513k
             coff_section_alignment_table_size);
1839
1840
513k
  return true;
1841
513k
}
coff-tic30.c:coff_new_section_hook
Line
Count
Source
1781
4.73M
{
1782
4.73M
  combined_entry_type *native;
1783
4.73M
  size_t amt;
1784
4.73M
  unsigned char sclass = C_STAT;
1785
1786
4.73M
  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
4.73M
  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
4.73M
  amt = sizeof (combined_entry_type) * 10;
1820
4.73M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
4.73M
  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
4.73M
  native->is_sym = true;
1831
4.73M
  native->u.syment.n_type = T_NULL;
1832
4.73M
  native->u.syment.n_sclass = sclass;
1833
1834
4.73M
  coffsymbol (section->symbol)->native = native;
1835
1836
4.73M
  coff_set_custom_section_alignment (abfd, section,
1837
4.73M
             coff_section_alignment_table,
1838
4.73M
             coff_section_alignment_table_size);
1839
1840
4.73M
  return true;
1841
4.73M
}
Unexecuted instantiation: coff-tic4x.c:coff_new_section_hook
coff-tic54x.c:coff_new_section_hook
Line
Count
Source
1781
7.89M
{
1782
7.89M
  combined_entry_type *native;
1783
7.89M
  size_t amt;
1784
7.89M
  unsigned char sclass = C_STAT;
1785
1786
7.89M
  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.89M
  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.89M
  amt = sizeof (combined_entry_type) * 10;
1820
7.89M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
7.89M
  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.89M
  native->is_sym = true;
1831
7.89M
  native->u.syment.n_type = T_NULL;
1832
7.89M
  native->u.syment.n_sclass = sclass;
1833
1834
7.89M
  coffsymbol (section->symbol)->native = native;
1835
1836
7.89M
  coff_set_custom_section_alignment (abfd, section,
1837
7.89M
             coff_section_alignment_table,
1838
7.89M
             coff_section_alignment_table_size);
1839
1840
7.89M
  return true;
1841
7.89M
}
coff-z80.c:coff_new_section_hook
Line
Count
Source
1781
1.20M
{
1782
1.20M
  combined_entry_type *native;
1783
1.20M
  size_t amt;
1784
1.20M
  unsigned char sclass = C_STAT;
1785
1786
1.20M
  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.20M
  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.20M
  amt = sizeof (combined_entry_type) * 10;
1820
1.20M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
1.20M
  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.20M
  native->is_sym = true;
1831
1.20M
  native->u.syment.n_type = T_NULL;
1832
1.20M
  native->u.syment.n_sclass = sclass;
1833
1834
1.20M
  coffsymbol (section->symbol)->native = native;
1835
1836
1.20M
  coff_set_custom_section_alignment (abfd, section,
1837
1.20M
             coff_section_alignment_table,
1838
1.20M
             coff_section_alignment_table_size);
1839
1840
1.20M
  return true;
1841
1.20M
}
coff-z8k.c:coff_new_section_hook
Line
Count
Source
1781
13.4M
{
1782
13.4M
  combined_entry_type *native;
1783
13.4M
  size_t amt;
1784
13.4M
  unsigned char sclass = C_STAT;
1785
1786
13.4M
  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.4M
  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.4M
  amt = sizeof (combined_entry_type) * 10;
1820
13.4M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
13.4M
  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.4M
  native->is_sym = true;
1831
13.4M
  native->u.syment.n_type = T_NULL;
1832
13.4M
  native->u.syment.n_sclass = sclass;
1833
1834
13.4M
  coffsymbol (section->symbol)->native = native;
1835
1836
13.4M
  coff_set_custom_section_alignment (abfd, section,
1837
13.4M
             coff_section_alignment_table,
1838
13.4M
             coff_section_alignment_table_size);
1839
1840
13.4M
  return true;
1841
13.4M
}
pe-arm-wince.c:coff_new_section_hook
Line
Count
Source
1781
59.1k
{
1782
59.1k
  combined_entry_type *native;
1783
59.1k
  size_t amt;
1784
59.1k
  unsigned char sclass = C_STAT;
1785
1786
59.1k
  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
59.1k
  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
59.1k
  amt = sizeof (combined_entry_type) * 10;
1820
59.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
59.1k
  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
59.1k
  native->is_sym = true;
1831
59.1k
  native->u.syment.n_type = T_NULL;
1832
59.1k
  native->u.syment.n_sclass = sclass;
1833
1834
59.1k
  coffsymbol (section->symbol)->native = native;
1835
1836
59.1k
  coff_set_custom_section_alignment (abfd, section,
1837
59.1k
             coff_section_alignment_table,
1838
59.1k
             coff_section_alignment_table_size);
1839
1840
59.1k
  return true;
1841
59.1k
}
pe-arm.c:coff_new_section_hook
Line
Count
Source
1781
59.1k
{
1782
59.1k
  combined_entry_type *native;
1783
59.1k
  size_t amt;
1784
59.1k
  unsigned char sclass = C_STAT;
1785
1786
59.1k
  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
59.1k
  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
59.1k
  amt = sizeof (combined_entry_type) * 10;
1820
59.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
59.1k
  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
59.1k
  native->is_sym = true;
1831
59.1k
  native->u.syment.n_type = T_NULL;
1832
59.1k
  native->u.syment.n_sclass = sclass;
1833
1834
59.1k
  coffsymbol (section->symbol)->native = native;
1835
1836
59.1k
  coff_set_custom_section_alignment (abfd, section,
1837
59.1k
             coff_section_alignment_table,
1838
59.1k
             coff_section_alignment_table_size);
1839
1840
59.1k
  return true;
1841
59.1k
}
pe-i386.c:coff_new_section_hook
Line
Count
Source
1781
130k
{
1782
130k
  combined_entry_type *native;
1783
130k
  size_t amt;
1784
130k
  unsigned char sclass = C_STAT;
1785
1786
130k
  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
130k
  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
130k
  amt = sizeof (combined_entry_type) * 10;
1820
130k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
130k
  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
130k
  native->is_sym = true;
1831
130k
  native->u.syment.n_type = T_NULL;
1832
130k
  native->u.syment.n_sclass = sclass;
1833
1834
130k
  coffsymbol (section->symbol)->native = native;
1835
1836
130k
  coff_set_custom_section_alignment (abfd, section,
1837
130k
             coff_section_alignment_table,
1838
130k
             coff_section_alignment_table_size);
1839
1840
130k
  return true;
1841
130k
}
pe-mcore.c:coff_new_section_hook
Line
Count
Source
1781
170k
{
1782
170k
  combined_entry_type *native;
1783
170k
  size_t amt;
1784
170k
  unsigned char sclass = C_STAT;
1785
1786
170k
  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
170k
  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
170k
  amt = sizeof (combined_entry_type) * 10;
1820
170k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
170k
  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
170k
  native->is_sym = true;
1831
170k
  native->u.syment.n_type = T_NULL;
1832
170k
  native->u.syment.n_sclass = sclass;
1833
1834
170k
  coffsymbol (section->symbol)->native = native;
1835
1836
170k
  coff_set_custom_section_alignment (abfd, section,
1837
170k
             coff_section_alignment_table,
1838
170k
             coff_section_alignment_table_size);
1839
1840
170k
  return true;
1841
170k
}
pe-sh.c:coff_new_section_hook
Line
Count
Source
1781
121k
{
1782
121k
  combined_entry_type *native;
1783
121k
  size_t amt;
1784
121k
  unsigned char sclass = C_STAT;
1785
1786
121k
  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
121k
  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
121k
  amt = sizeof (combined_entry_type) * 10;
1820
121k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
121k
  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
121k
  native->is_sym = true;
1831
121k
  native->u.syment.n_type = T_NULL;
1832
121k
  native->u.syment.n_sclass = sclass;
1833
1834
121k
  coffsymbol (section->symbol)->native = native;
1835
1836
121k
  coff_set_custom_section_alignment (abfd, section,
1837
121k
             coff_section_alignment_table,
1838
121k
             coff_section_alignment_table_size);
1839
1840
121k
  return true;
1841
121k
}
pei-arm-wince.c:coff_new_section_hook
Line
Count
Source
1781
213k
{
1782
213k
  combined_entry_type *native;
1783
213k
  size_t amt;
1784
213k
  unsigned char sclass = C_STAT;
1785
1786
213k
  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
213k
  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
213k
  amt = sizeof (combined_entry_type) * 10;
1820
213k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
213k
  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
213k
  native->is_sym = true;
1831
213k
  native->u.syment.n_type = T_NULL;
1832
213k
  native->u.syment.n_sclass = sclass;
1833
1834
213k
  coffsymbol (section->symbol)->native = native;
1835
1836
213k
  coff_set_custom_section_alignment (abfd, section,
1837
213k
             coff_section_alignment_table,
1838
213k
             coff_section_alignment_table_size);
1839
1840
213k
  return true;
1841
213k
}
pei-arm.c:coff_new_section_hook
Line
Count
Source
1781
316k
{
1782
316k
  combined_entry_type *native;
1783
316k
  size_t amt;
1784
316k
  unsigned char sclass = C_STAT;
1785
1786
316k
  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
316k
  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
316k
  amt = sizeof (combined_entry_type) * 10;
1820
316k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
316k
  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
316k
  native->is_sym = true;
1831
316k
  native->u.syment.n_type = T_NULL;
1832
316k
  native->u.syment.n_sclass = sclass;
1833
1834
316k
  coffsymbol (section->symbol)->native = native;
1835
1836
316k
  coff_set_custom_section_alignment (abfd, section,
1837
316k
             coff_section_alignment_table,
1838
316k
             coff_section_alignment_table_size);
1839
1840
316k
  return true;
1841
316k
}
pei-mcore.c:coff_new_section_hook
Line
Count
Source
1781
203k
{
1782
203k
  combined_entry_type *native;
1783
203k
  size_t amt;
1784
203k
  unsigned char sclass = C_STAT;
1785
1786
203k
  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
203k
  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
203k
  amt = sizeof (combined_entry_type) * 10;
1820
203k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
203k
  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
203k
  native->is_sym = true;
1831
203k
  native->u.syment.n_type = T_NULL;
1832
203k
  native->u.syment.n_sclass = sclass;
1833
1834
203k
  coffsymbol (section->symbol)->native = native;
1835
1836
203k
  coff_set_custom_section_alignment (abfd, section,
1837
203k
             coff_section_alignment_table,
1838
203k
             coff_section_alignment_table_size);
1839
1840
203k
  return true;
1841
203k
}
pei-sh.c:coff_new_section_hook
Line
Count
Source
1781
252k
{
1782
252k
  combined_entry_type *native;
1783
252k
  size_t amt;
1784
252k
  unsigned char sclass = C_STAT;
1785
1786
252k
  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
252k
  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
252k
  amt = sizeof (combined_entry_type) * 10;
1820
252k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1821
252k
  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
252k
  native->is_sym = true;
1831
252k
  native->u.syment.n_type = T_NULL;
1832
252k
  native->u.syment.n_sclass = sclass;
1833
1834
252k
  coffsymbol (section->symbol)->native = native;
1835
1836
252k
  coff_set_custom_section_alignment (abfd, section,
1837
252k
             coff_section_alignment_table,
1838
252k
             coff_section_alignment_table_size);
1839
1840
252k
  return true;
1841
252k
}
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
9.09M
{
1852
9.09M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
9.09M
  unsigned int i;
1854
1855
9.09M
#ifdef COFF_DECODE_ALIGNMENT
1856
9.09M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
9.09M
#endif
1858
9.09M
  section->alignment_power = i;
1859
1860
#ifdef coff_set_section_load_page
1861
7.89M
  coff_set_section_load_page (section, hdr->s_page);
1862
#endif
1863
9.09M
}
Unexecuted instantiation: coff-tic4x.c:coff_set_alignment_hook
coff-tic54x.c:coff_set_alignment_hook
Line
Count
Source
1851
7.89M
{
1852
7.89M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
7.89M
  unsigned int i;
1854
1855
7.89M
#ifdef COFF_DECODE_ALIGNMENT
1856
7.89M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
7.89M
#endif
1858
7.89M
  section->alignment_power = i;
1859
1860
7.89M
#ifdef coff_set_section_load_page
1861
7.89M
  coff_set_section_load_page (section, hdr->s_page);
1862
7.89M
#endif
1863
7.89M
}
coff-z80.c:coff_set_alignment_hook
Line
Count
Source
1851
1.20M
{
1852
1.20M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1853
1.20M
  unsigned int i;
1854
1855
1.20M
#ifdef COFF_DECODE_ALIGNMENT
1856
1.20M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1857
1.20M
#endif
1858
1.20M
  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.20M
}
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
3.77M
{
1873
3.77M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
3.77M
  size_t amt;
1875
3.77M
  unsigned int alignment_power_const
1876
3.77M
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
3.77M
  switch (alignment_power_const)
1879
3.77M
    {
1880
119k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
148k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
227k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
256k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
330k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
377k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
452k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
522k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
649k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
731k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
815k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
964k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
1.22M
    case IMAGE_SCN_ALIGN_2BYTES:
1893
1.29M
    case IMAGE_SCN_ALIGN_1BYTES:
1894
1.29M
      section->alignment_power
1895
1.29M
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
1.29M
      break;
1897
2.47M
    default:
1898
2.47M
      break;
1899
3.77M
    }
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
3.77M
  if (coff_section_data (abfd, section) == NULL)
1906
3.77M
    {
1907
3.77M
      amt = sizeof (struct coff_section_tdata);
1908
3.77M
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
3.77M
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
3.77M
    }
1913
1914
3.77M
  if (pei_section_data (abfd, section) == NULL)
1915
3.77M
    {
1916
3.77M
      amt = sizeof (struct pei_section_tdata);
1917
3.77M
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
3.77M
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
3.77M
    }
1922
3.77M
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
3.77M
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
3.77M
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
3.77M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
708k
    {
1930
708k
      struct external_reloc dst;
1931
708k
      struct internal_reloc n;
1932
708k
      file_ptr oldpos = bfd_tell (abfd);
1933
708k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
708k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
708k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
485k
  return;
1939
1940
223k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
223k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
223k
      if (n.r_vaddr < 0x10000)
1944
65.6k
  {
1945
65.6k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
65.6k
    bfd_set_error (bfd_error_bad_value);
1947
65.6k
    return;
1948
65.6k
  }
1949
157k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
157k
      section->rel_filepos += relsz;
1951
157k
    }
1952
3.06M
  else if (hdr->s_nreloc == 0xffff)
1953
33.7k
    _bfd_error_handler
1954
33.7k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
33.7k
       abfd);
1956
3.77M
}
pei-i386.c:coff_set_alignment_hook
Line
Count
Source
1872
301k
{
1873
301k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
301k
  size_t amt;
1875
301k
  unsigned int alignment_power_const
1876
301k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
301k
  switch (alignment_power_const)
1879
301k
    {
1880
8.70k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
10.0k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
14.5k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
15.3k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
22.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
27.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
32.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
37.3k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
46.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
53.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
60.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
74.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
95.3k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
99.9k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
99.9k
      section->alignment_power
1895
99.9k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
99.9k
      break;
1897
201k
    default:
1898
201k
      break;
1899
301k
    }
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
301k
  if (coff_section_data (abfd, section) == NULL)
1906
301k
    {
1907
301k
      amt = sizeof (struct coff_section_tdata);
1908
301k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
301k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
301k
    }
1913
1914
301k
  if (pei_section_data (abfd, section) == NULL)
1915
301k
    {
1916
301k
      amt = sizeof (struct pei_section_tdata);
1917
301k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
301k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
301k
    }
1922
301k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
301k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
301k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
301k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
48.8k
    {
1930
48.8k
      struct external_reloc dst;
1931
48.8k
      struct internal_reloc n;
1932
48.8k
      file_ptr oldpos = bfd_tell (abfd);
1933
48.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
48.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
48.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
30.6k
  return;
1939
1940
18.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
18.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
18.2k
      if (n.r_vaddr < 0x10000)
1944
4.35k
  {
1945
4.35k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
4.35k
    bfd_set_error (bfd_error_bad_value);
1947
4.35k
    return;
1948
4.35k
  }
1949
13.8k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
13.8k
      section->rel_filepos += relsz;
1951
13.8k
    }
1952
252k
  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
301k
}
pe-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1872
642k
{
1873
642k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
642k
  size_t amt;
1875
642k
  unsigned int alignment_power_const
1876
642k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
642k
  switch (alignment_power_const)
1879
642k
    {
1880
6.94k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
10.3k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
16.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
19.2k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
24.1k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
31.7k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
35.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
43.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
63.2k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
73.5k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
83.2k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
116k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
142k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
148k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
148k
      section->alignment_power
1895
148k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
148k
      break;
1897
494k
    default:
1898
494k
      break;
1899
642k
    }
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
642k
  if (coff_section_data (abfd, section) == NULL)
1906
642k
    {
1907
642k
      amt = sizeof (struct coff_section_tdata);
1908
642k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
642k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
642k
    }
1913
1914
642k
  if (pei_section_data (abfd, section) == NULL)
1915
642k
    {
1916
642k
      amt = sizeof (struct pei_section_tdata);
1917
642k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
642k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
642k
    }
1922
642k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
642k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
642k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
642k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
82.7k
    {
1930
82.7k
      struct external_reloc dst;
1931
82.7k
      struct internal_reloc n;
1932
82.7k
      file_ptr oldpos = bfd_tell (abfd);
1933
82.7k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
82.7k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
82.7k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
61.8k
  return;
1939
1940
20.9k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
20.9k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
20.9k
      if (n.r_vaddr < 0x10000)
1944
3.76k
  {
1945
3.76k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.76k
    bfd_set_error (bfd_error_bad_value);
1947
3.76k
    return;
1948
3.76k
  }
1949
17.1k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
17.1k
      section->rel_filepos += relsz;
1951
17.1k
    }
1952
560k
  else if (hdr->s_nreloc == 0xffff)
1953
16.5k
    _bfd_error_handler
1954
16.5k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
16.5k
       abfd);
1956
642k
}
pei-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1872
286k
{
1873
286k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
286k
  size_t amt;
1875
286k
  unsigned int alignment_power_const
1876
286k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
286k
  switch (alignment_power_const)
1879
286k
    {
1880
5.81k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
7.86k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
11.3k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
13.5k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
26.6k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
27.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
31.0k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
37.1k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
44.0k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
53.6k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
56.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
63.8k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
84.0k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
95.9k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
95.9k
      section->alignment_power
1895
95.9k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
95.9k
      break;
1897
190k
    default:
1898
190k
      break;
1899
286k
    }
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
286k
  if (coff_section_data (abfd, section) == NULL)
1906
286k
    {
1907
286k
      amt = sizeof (struct coff_section_tdata);
1908
286k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
286k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
286k
    }
1913
1914
286k
  if (pei_section_data (abfd, section) == NULL)
1915
286k
    {
1916
286k
      amt = sizeof (struct pei_section_tdata);
1917
286k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
286k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
286k
    }
1922
286k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
286k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
286k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
286k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
45.3k
    {
1930
45.3k
      struct external_reloc dst;
1931
45.3k
      struct internal_reloc n;
1932
45.3k
      file_ptr oldpos = bfd_tell (abfd);
1933
45.3k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
45.3k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
45.3k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
26.1k
  return;
1939
1940
19.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
19.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
19.2k
      if (n.r_vaddr < 0x10000)
1944
3.61k
  {
1945
3.61k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.61k
    bfd_set_error (bfd_error_bad_value);
1947
3.61k
    return;
1948
3.61k
  }
1949
15.6k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
15.6k
      section->rel_filepos += relsz;
1951
15.6k
    }
1952
240k
  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
286k
}
pe-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
197k
{
1873
197k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
197k
  size_t amt;
1875
197k
  unsigned int alignment_power_const
1876
197k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
197k
  switch (alignment_power_const)
1879
197k
    {
1880
4.39k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
6.16k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
7.96k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
8.73k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
12.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
14.8k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
18.8k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
24.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
28.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
31.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
34.4k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
39.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
46.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
50.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
50.1k
      section->alignment_power
1895
50.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
50.1k
      break;
1897
146k
    default:
1898
146k
      break;
1899
197k
    }
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
197k
  if (coff_section_data (abfd, section) == NULL)
1906
197k
    {
1907
197k
      amt = sizeof (struct coff_section_tdata);
1908
197k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
197k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
197k
    }
1913
1914
197k
  if (pei_section_data (abfd, section) == NULL)
1915
197k
    {
1916
197k
      amt = sizeof (struct pei_section_tdata);
1917
197k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
197k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
197k
    }
1922
197k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
197k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
197k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
197k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
32.2k
    {
1930
32.2k
      struct external_reloc dst;
1931
32.2k
      struct internal_reloc n;
1932
32.2k
      file_ptr oldpos = bfd_tell (abfd);
1933
32.2k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
32.2k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
32.2k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
22.6k
  return;
1939
1940
9.59k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
9.59k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
9.59k
      if (n.r_vaddr < 0x10000)
1944
3.10k
  {
1945
3.10k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
3.10k
    bfd_set_error (bfd_error_bad_value);
1947
3.10k
    return;
1948
3.10k
  }
1949
6.49k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
6.49k
      section->rel_filepos += relsz;
1951
6.49k
    }
1952
164k
  else if (hdr->s_nreloc == 0xffff)
1953
2.83k
    _bfd_error_handler
1954
2.83k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
2.83k
       abfd);
1956
197k
}
pei-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
258k
{
1873
258k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
258k
  size_t amt;
1875
258k
  unsigned int alignment_power_const
1876
258k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
258k
  switch (alignment_power_const)
1879
258k
    {
1880
8.20k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
10.2k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
13.2k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
14.2k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
18.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
19.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
31.3k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
32.7k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
41.1k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
45.0k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
49.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
55.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
69.5k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
72.2k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
72.2k
      section->alignment_power
1895
72.2k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
72.2k
      break;
1897
185k
    default:
1898
185k
      break;
1899
258k
    }
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
258k
  if (coff_section_data (abfd, section) == NULL)
1906
258k
    {
1907
258k
      amt = sizeof (struct coff_section_tdata);
1908
258k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
258k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
258k
    }
1913
1914
258k
  if (pei_section_data (abfd, section) == NULL)
1915
258k
    {
1916
258k
      amt = sizeof (struct pei_section_tdata);
1917
258k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
258k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
258k
    }
1922
258k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
258k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
258k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
258k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
45.5k
    {
1930
45.5k
      struct external_reloc dst;
1931
45.5k
      struct internal_reloc n;
1932
45.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
45.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
45.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
45.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
23.5k
  return;
1939
1940
21.9k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
21.9k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
21.9k
      if (n.r_vaddr < 0x10000)
1944
13.1k
  {
1945
13.1k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
13.1k
    bfd_set_error (bfd_error_bad_value);
1947
13.1k
    return;
1948
13.1k
  }
1949
8.83k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
8.83k
      section->rel_filepos += relsz;
1951
8.83k
    }
1952
212k
  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
258k
}
pei-ia64.c:coff_set_alignment_hook
Line
Count
Source
1872
230k
{
1873
230k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
230k
  size_t amt;
1875
230k
  unsigned int alignment_power_const
1876
230k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
230k
  switch (alignment_power_const)
1879
230k
    {
1880
10.2k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
11.6k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
18.7k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
19.9k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
24.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
29.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
36.3k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
40.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
47.7k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
52.4k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
56.4k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
65.7k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
86.8k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
90.4k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
90.4k
      section->alignment_power
1895
90.4k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
90.4k
      break;
1897
139k
    default:
1898
139k
      break;
1899
230k
    }
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
230k
  if (coff_section_data (abfd, section) == NULL)
1906
230k
    {
1907
230k
      amt = sizeof (struct coff_section_tdata);
1908
230k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
230k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
230k
    }
1913
1914
230k
  if (pei_section_data (abfd, section) == NULL)
1915
230k
    {
1916
230k
      amt = sizeof (struct pei_section_tdata);
1917
230k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
230k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
230k
    }
1922
230k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
230k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
230k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
230k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
43.5k
    {
1930
43.5k
      struct external_reloc dst;
1931
43.5k
      struct internal_reloc n;
1932
43.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
43.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
43.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
43.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
30.8k
  return;
1939
1940
12.7k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
12.7k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
12.7k
      if (n.r_vaddr < 0x10000)
1944
2.30k
  {
1945
2.30k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.30k
    bfd_set_error (bfd_error_bad_value);
1947
2.30k
    return;
1948
2.30k
  }
1949
10.3k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
10.3k
      section->rel_filepos += relsz;
1951
10.3k
    }
1952
186k
  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
230k
}
pei-loongarch64.c:coff_set_alignment_hook
Line
Count
Source
1872
229k
{
1873
229k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
229k
  size_t amt;
1875
229k
  unsigned int alignment_power_const
1876
229k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
229k
  switch (alignment_power_const)
1879
229k
    {
1880
12.1k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
13.0k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
18.6k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
20.1k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
25.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
27.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
32.7k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
36.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
45.0k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
50.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
56.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
65.9k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
81.7k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
86.9k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
86.9k
      section->alignment_power
1895
86.9k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
86.9k
      break;
1897
142k
    default:
1898
142k
      break;
1899
229k
    }
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
229k
  if (coff_section_data (abfd, section) == NULL)
1906
229k
    {
1907
229k
      amt = sizeof (struct coff_section_tdata);
1908
229k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
229k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
229k
    }
1913
1914
229k
  if (pei_section_data (abfd, section) == NULL)
1915
229k
    {
1916
229k
      amt = sizeof (struct pei_section_tdata);
1917
229k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
229k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
229k
    }
1922
229k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
229k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
229k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
229k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
38.5k
    {
1930
38.5k
      struct external_reloc dst;
1931
38.5k
      struct internal_reloc n;
1932
38.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
38.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
38.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
38.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
25.5k
  return;
1939
1940
13.0k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
13.0k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
13.0k
      if (n.r_vaddr < 0x10000)
1944
1.84k
  {
1945
1.84k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
1.84k
    bfd_set_error (bfd_error_bad_value);
1947
1.84k
    return;
1948
1.84k
  }
1949
11.1k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
11.1k
      section->rel_filepos += relsz;
1951
11.1k
    }
1952
191k
  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
229k
}
pei-riscv64.c:coff_set_alignment_hook
Line
Count
Source
1872
210k
{
1873
210k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
210k
  size_t amt;
1875
210k
  unsigned int alignment_power_const
1876
210k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
210k
  switch (alignment_power_const)
1879
210k
    {
1880
2.46k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
3.09k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
6.97k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
8.70k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
11.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
14.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
18.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
23.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
32.4k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
39.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
43.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
49.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
59.2k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
62.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
62.1k
      section->alignment_power
1895
62.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
62.1k
      break;
1897
148k
    default:
1898
148k
      break;
1899
210k
    }
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
210k
  if (coff_section_data (abfd, section) == NULL)
1906
210k
    {
1907
210k
      amt = sizeof (struct coff_section_tdata);
1908
210k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
210k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
210k
    }
1913
1914
210k
  if (pei_section_data (abfd, section) == NULL)
1915
210k
    {
1916
210k
      amt = sizeof (struct pei_section_tdata);
1917
210k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
210k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
210k
    }
1922
210k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
210k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
210k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
210k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
32.8k
    {
1930
32.8k
      struct external_reloc dst;
1931
32.8k
      struct internal_reloc n;
1932
32.8k
      file_ptr oldpos = bfd_tell (abfd);
1933
32.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
32.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
32.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
20.4k
  return;
1939
1940
12.4k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
12.4k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
12.4k
      if (n.r_vaddr < 0x10000)
1944
6.61k
  {
1945
6.61k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
6.61k
    bfd_set_error (bfd_error_bad_value);
1947
6.61k
    return;
1948
6.61k
  }
1949
5.81k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
5.81k
      section->rel_filepos += relsz;
1951
5.81k
    }
1952
178k
  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
210k
}
pe-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1872
56.8k
{
1873
56.8k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
56.8k
  size_t amt;
1875
56.8k
  unsigned int alignment_power_const
1876
56.8k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
56.8k
  switch (alignment_power_const)
1879
56.8k
    {
1880
2.25k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
3.35k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
4.89k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
6.10k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
7.67k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
8.49k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
9.13k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
11.3k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
13.9k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
16.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
18.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
21.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
25.2k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
26.8k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
26.8k
      section->alignment_power
1895
26.8k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
26.8k
      break;
1897
30.0k
    default:
1898
30.0k
      break;
1899
56.8k
    }
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
56.8k
  if (coff_section_data (abfd, section) == NULL)
1906
56.8k
    {
1907
56.8k
      amt = sizeof (struct coff_section_tdata);
1908
56.8k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
56.8k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
56.8k
    }
1913
1914
56.8k
  if (pei_section_data (abfd, section) == NULL)
1915
56.8k
    {
1916
56.8k
      amt = sizeof (struct pei_section_tdata);
1917
56.8k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
56.8k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
56.8k
    }
1922
56.8k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
56.8k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
56.8k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
56.8k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
17.5k
    {
1930
17.5k
      struct external_reloc dst;
1931
17.5k
      struct internal_reloc n;
1932
17.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
17.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
17.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
17.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
12.9k
  return;
1939
1940
4.63k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
4.63k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
4.63k
      if (n.r_vaddr < 0x10000)
1944
961
  {
1945
961
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
961
    bfd_set_error (bfd_error_bad_value);
1947
961
    return;
1948
961
  }
1949
3.66k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
3.66k
      section->rel_filepos += relsz;
1951
3.66k
    }
1952
39.3k
  else if (hdr->s_nreloc == 0xffff)
1953
1.80k
    _bfd_error_handler
1954
1.80k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
1.80k
       abfd);
1956
56.8k
}
pe-arm.c:coff_set_alignment_hook
Line
Count
Source
1872
56.8k
{
1873
56.8k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
56.8k
  size_t amt;
1875
56.8k
  unsigned int alignment_power_const
1876
56.8k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
56.8k
  switch (alignment_power_const)
1879
56.8k
    {
1880
2.25k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
3.35k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
4.89k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
6.10k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
7.67k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
8.49k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
9.13k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
11.3k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
13.9k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
16.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
18.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
21.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
25.2k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
26.8k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
26.8k
      section->alignment_power
1895
26.8k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
26.8k
      break;
1897
30.0k
    default:
1898
30.0k
      break;
1899
56.8k
    }
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
56.8k
  if (coff_section_data (abfd, section) == NULL)
1906
56.8k
    {
1907
56.8k
      amt = sizeof (struct coff_section_tdata);
1908
56.8k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
56.8k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
56.8k
    }
1913
1914
56.8k
  if (pei_section_data (abfd, section) == NULL)
1915
56.8k
    {
1916
56.8k
      amt = sizeof (struct pei_section_tdata);
1917
56.8k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
56.8k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
56.8k
    }
1922
56.8k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
56.8k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
56.8k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
56.8k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
17.5k
    {
1930
17.5k
      struct external_reloc dst;
1931
17.5k
      struct internal_reloc n;
1932
17.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
17.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
17.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
17.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
12.9k
  return;
1939
1940
4.63k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
4.63k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
4.63k
      if (n.r_vaddr < 0x10000)
1944
961
  {
1945
961
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
961
    bfd_set_error (bfd_error_bad_value);
1947
961
    return;
1948
961
  }
1949
3.66k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
3.66k
      section->rel_filepos += relsz;
1951
3.66k
    }
1952
39.3k
  else if (hdr->s_nreloc == 0xffff)
1953
1.80k
    _bfd_error_handler
1954
1.80k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
1.80k
       abfd);
1956
56.8k
}
pe-i386.c:coff_set_alignment_hook
Line
Count
Source
1872
128k
{
1873
128k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
128k
  size_t amt;
1875
128k
  unsigned int alignment_power_const
1876
128k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
128k
  switch (alignment_power_const)
1879
128k
    {
1880
4.02k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
5.33k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
7.35k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
8.43k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
10.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
13.8k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
16.3k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
21.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
25.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
27.4k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
30.5k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
37.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
50.5k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
52.5k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
52.5k
      section->alignment_power
1895
52.5k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
52.5k
      break;
1897
76.0k
    default:
1898
76.0k
      break;
1899
128k
    }
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
128k
  if (coff_section_data (abfd, section) == NULL)
1906
128k
    {
1907
128k
      amt = sizeof (struct coff_section_tdata);
1908
128k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
128k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
128k
    }
1913
1914
128k
  if (pei_section_data (abfd, section) == NULL)
1915
128k
    {
1916
128k
      amt = sizeof (struct pei_section_tdata);
1917
128k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
128k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
128k
    }
1922
128k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
128k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
128k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
128k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
32.1k
    {
1930
32.1k
      struct external_reloc dst;
1931
32.1k
      struct internal_reloc n;
1932
32.1k
      file_ptr oldpos = bfd_tell (abfd);
1933
32.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
32.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
32.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
23.5k
  return;
1939
1940
8.65k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
8.65k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
8.65k
      if (n.r_vaddr < 0x10000)
1944
2.33k
  {
1945
2.33k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.33k
    bfd_set_error (bfd_error_bad_value);
1947
2.33k
    return;
1948
2.33k
  }
1949
6.31k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
6.31k
      section->rel_filepos += relsz;
1951
6.31k
    }
1952
96.3k
  else if (hdr->s_nreloc == 0xffff)
1953
3.12k
    _bfd_error_handler
1954
3.12k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
3.12k
       abfd);
1956
128k
}
pe-mcore.c:coff_set_alignment_hook
Line
Count
Source
1872
168k
{
1873
168k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
168k
  size_t amt;
1875
168k
  unsigned int alignment_power_const
1876
168k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
168k
  switch (alignment_power_const)
1879
168k
    {
1880
9.23k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
10.5k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
16.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
17.9k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
23.5k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
27.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
32.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
35.1k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
42.8k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
46.0k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
54.7k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
59.2k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
71.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
74.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
74.1k
      section->alignment_power
1895
74.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
74.1k
      break;
1897
93.9k
    default:
1898
93.9k
      break;
1899
168k
    }
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
168k
  if (coff_section_data (abfd, section) == NULL)
1906
168k
    {
1907
168k
      amt = sizeof (struct coff_section_tdata);
1908
168k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
168k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
168k
    }
1913
1914
168k
  if (pei_section_data (abfd, section) == NULL)
1915
168k
    {
1916
168k
      amt = sizeof (struct pei_section_tdata);
1917
168k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
168k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
168k
    }
1922
168k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
168k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
168k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
168k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
27.1k
    {
1930
27.1k
      struct external_reloc dst;
1931
27.1k
      struct internal_reloc n;
1932
27.1k
      file_ptr oldpos = bfd_tell (abfd);
1933
27.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
27.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
27.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
17.8k
  return;
1939
1940
9.33k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
9.33k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
9.33k
      if (n.r_vaddr < 0x10000)
1944
2.94k
  {
1945
2.94k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.94k
    bfd_set_error (bfd_error_bad_value);
1947
2.94k
    return;
1948
2.94k
  }
1949
6.39k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
6.39k
      section->rel_filepos += relsz;
1951
6.39k
    }
1952
141k
  else if (hdr->s_nreloc == 0xffff)
1953
4.32k
    _bfd_error_handler
1954
4.32k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
4.32k
       abfd);
1956
168k
}
pe-sh.c:coff_set_alignment_hook
Line
Count
Source
1872
118k
{
1873
118k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
118k
  size_t amt;
1875
118k
  unsigned int alignment_power_const
1876
118k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
118k
  switch (alignment_power_const)
1879
118k
    {
1880
5.55k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
7.75k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
10.2k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
11.4k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
12.6k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
14.2k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
15.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
17.7k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
23.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
28.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
29.6k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
36.5k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
43.4k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
44.5k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
44.5k
      section->alignment_power
1895
44.5k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
44.5k
      break;
1897
73.7k
    default:
1898
73.7k
      break;
1899
118k
    }
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
118k
  if (coff_section_data (abfd, section) == NULL)
1906
118k
    {
1907
118k
      amt = sizeof (struct coff_section_tdata);
1908
118k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
118k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
118k
    }
1913
1914
118k
  if (pei_section_data (abfd, section) == NULL)
1915
118k
    {
1916
118k
      amt = sizeof (struct pei_section_tdata);
1917
118k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
118k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
118k
    }
1922
118k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
118k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
118k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
118k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
25.8k
    {
1930
25.8k
      struct external_reloc dst;
1931
25.8k
      struct internal_reloc n;
1932
25.8k
      file_ptr oldpos = bfd_tell (abfd);
1933
25.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
25.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
25.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
18.0k
  return;
1939
1940
7.80k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
7.80k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
7.80k
      if (n.r_vaddr < 0x10000)
1944
2.12k
  {
1945
2.12k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.12k
    bfd_set_error (bfd_error_bad_value);
1947
2.12k
    return;
1948
2.12k
  }
1949
5.68k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
5.68k
      section->rel_filepos += relsz;
1951
5.68k
    }
1952
92.4k
  else if (hdr->s_nreloc == 0xffff)
1953
3.28k
    _bfd_error_handler
1954
3.28k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1955
3.28k
       abfd);
1956
118k
}
pei-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1872
204k
{
1873
204k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
204k
  size_t amt;
1875
204k
  unsigned int alignment_power_const
1876
204k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
204k
  switch (alignment_power_const)
1879
204k
    {
1880
6.92k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
8.94k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
16.8k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
19.1k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
22.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
25.4k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
28.8k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
33.2k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
40.0k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
45.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
51.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
60.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
79.9k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
86.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
86.1k
      section->alignment_power
1895
86.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
86.1k
      break;
1897
118k
    default:
1898
118k
      break;
1899
204k
    }
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
204k
  if (coff_section_data (abfd, section) == NULL)
1906
204k
    {
1907
204k
      amt = sizeof (struct coff_section_tdata);
1908
204k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
204k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
204k
    }
1913
1914
204k
  if (pei_section_data (abfd, section) == NULL)
1915
204k
    {
1916
204k
      amt = sizeof (struct pei_section_tdata);
1917
204k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
204k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
204k
    }
1922
204k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
204k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
204k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
204k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
55.3k
    {
1930
55.3k
      struct external_reloc dst;
1931
55.3k
      struct internal_reloc n;
1932
55.3k
      file_ptr oldpos = bfd_tell (abfd);
1933
55.3k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
55.3k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
55.3k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
41.8k
  return;
1939
1940
13.5k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
13.5k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
13.5k
      if (n.r_vaddr < 0x10000)
1944
4.64k
  {
1945
4.64k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
4.64k
    bfd_set_error (bfd_error_bad_value);
1947
4.64k
    return;
1948
4.64k
  }
1949
8.88k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
8.88k
      section->rel_filepos += relsz;
1951
8.88k
    }
1952
149k
  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
204k
}
pei-arm.c:coff_set_alignment_hook
Line
Count
Source
1872
265k
{
1873
265k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
265k
  size_t amt;
1875
265k
  unsigned int alignment_power_const
1876
265k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
265k
  switch (alignment_power_const)
1879
265k
    {
1880
9.05k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
11.5k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
24.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
27.2k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
30.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
34.7k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
41.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
47.2k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
56.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
62.6k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
70.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
80.7k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
104k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
111k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
111k
      section->alignment_power
1895
111k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
111k
      break;
1897
154k
    default:
1898
154k
      break;
1899
265k
    }
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
265k
  if (coff_section_data (abfd, section) == NULL)
1906
265k
    {
1907
265k
      amt = sizeof (struct coff_section_tdata);
1908
265k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
265k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
265k
    }
1913
1914
265k
  if (pei_section_data (abfd, section) == NULL)
1915
265k
    {
1916
265k
      amt = sizeof (struct pei_section_tdata);
1917
265k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
265k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
265k
    }
1922
265k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
265k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
265k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
265k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
65.7k
    {
1930
65.7k
      struct external_reloc dst;
1931
65.7k
      struct internal_reloc n;
1932
65.7k
      file_ptr oldpos = bfd_tell (abfd);
1933
65.7k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
65.7k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
65.7k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
48.6k
  return;
1939
1940
17.1k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
17.1k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
17.1k
      if (n.r_vaddr < 0x10000)
1944
5.35k
  {
1945
5.35k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
5.35k
    bfd_set_error (bfd_error_bad_value);
1947
5.35k
    return;
1948
5.35k
  }
1949
11.8k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
11.8k
      section->rel_filepos += relsz;
1951
11.8k
    }
1952
199k
  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
265k
}
pei-mcore.c:coff_set_alignment_hook
Line
Count
Source
1872
199k
{
1873
199k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
199k
  size_t amt;
1875
199k
  unsigned int alignment_power_const
1876
199k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
199k
  switch (alignment_power_const)
1879
199k
    {
1880
14.9k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
15.5k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
20.2k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
22.0k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
26.8k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
29.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
34.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
36.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
45.0k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
47.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
50.9k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
58.9k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
79.4k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
82.7k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
82.7k
      section->alignment_power
1895
82.7k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
82.7k
      break;
1897
116k
    default:
1898
116k
      break;
1899
199k
    }
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
199k
  if (coff_section_data (abfd, section) == NULL)
1906
199k
    {
1907
199k
      amt = sizeof (struct coff_section_tdata);
1908
199k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
199k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
199k
    }
1913
1914
199k
  if (pei_section_data (abfd, section) == NULL)
1915
199k
    {
1916
199k
      amt = sizeof (struct pei_section_tdata);
1917
199k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
199k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
199k
    }
1922
199k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
199k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
199k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
199k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
42.6k
    {
1930
42.6k
      struct external_reloc dst;
1931
42.6k
      struct internal_reloc n;
1932
42.6k
      file_ptr oldpos = bfd_tell (abfd);
1933
42.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
42.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
42.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
29.2k
  return;
1939
1940
13.3k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
13.3k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
13.3k
      if (n.r_vaddr < 0x10000)
1944
4.74k
  {
1945
4.74k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
4.74k
    bfd_set_error (bfd_error_bad_value);
1947
4.74k
    return;
1948
4.74k
  }
1949
8.57k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
8.57k
      section->rel_filepos += relsz;
1951
8.57k
    }
1952
156k
  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
199k
}
pei-sh.c:coff_set_alignment_hook
Line
Count
Source
1872
218k
{
1873
218k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1874
218k
  size_t amt;
1875
218k
  unsigned int alignment_power_const
1876
218k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1877
1878
218k
  switch (alignment_power_const)
1879
218k
    {
1880
6.52k
    case IMAGE_SCN_ALIGN_8192BYTES:
1881
9.12k
    case IMAGE_SCN_ALIGN_4096BYTES:
1882
14.9k
    case IMAGE_SCN_ALIGN_2048BYTES:
1883
18.5k
    case IMAGE_SCN_ALIGN_1024BYTES:
1884
23.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1885
25.2k
    case IMAGE_SCN_ALIGN_256BYTES:
1886
28.2k
    case IMAGE_SCN_ALIGN_128BYTES:
1887
31.4k
    case IMAGE_SCN_ALIGN_64BYTES:
1888
38.8k
    case IMAGE_SCN_ALIGN_32BYTES:
1889
42.8k
    case IMAGE_SCN_ALIGN_16BYTES:
1890
50.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1891
60.6k
    case IMAGE_SCN_ALIGN_4BYTES:
1892
79.3k
    case IMAGE_SCN_ALIGN_2BYTES:
1893
84.2k
    case IMAGE_SCN_ALIGN_1BYTES:
1894
84.2k
      section->alignment_power
1895
84.2k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1896
84.2k
      break;
1897
134k
    default:
1898
134k
      break;
1899
218k
    }
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
218k
  if (coff_section_data (abfd, section) == NULL)
1906
218k
    {
1907
218k
      amt = sizeof (struct coff_section_tdata);
1908
218k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1909
218k
      if (section->used_by_bfd == NULL)
1910
  /* FIXME: Return error.  */
1911
0
  abort ();
1912
218k
    }
1913
1914
218k
  if (pei_section_data (abfd, section) == NULL)
1915
218k
    {
1916
218k
      amt = sizeof (struct pei_section_tdata);
1917
218k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1918
218k
      if (coff_section_data (abfd, section)->tdata == NULL)
1919
  /* FIXME: Return error.  */
1920
0
  abort ();
1921
218k
    }
1922
218k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1923
218k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1924
1925
218k
  section->lma = hdr->s_vaddr;
1926
1927
  /* Check for extended relocs.  */
1928
218k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1929
54.5k
    {
1930
54.5k
      struct external_reloc dst;
1931
54.5k
      struct internal_reloc n;
1932
54.5k
      file_ptr oldpos = bfd_tell (abfd);
1933
54.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1934
1935
54.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1936
0
  return;
1937
54.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1938
38.4k
  return;
1939
1940
16.1k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1941
16.1k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1942
0
  return;
1943
16.1k
      if (n.r_vaddr < 0x10000)
1944
2.83k
  {
1945
2.83k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1946
2.83k
    bfd_set_error (bfd_error_bad_value);
1947
2.83k
    return;
1948
2.83k
  }
1949
13.2k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1950
13.2k
      section->rel_filepos += relsz;
1951
13.2k
    }
1952
163k
  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
218k
}
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
24.3M
{
1970
24.3M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
24.3M
  asection *real_sec;
1972
1973
24.3M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
19.9M
    return;
1975
1976
4.40M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
4.40M
  if (real_sec == NULL)
1978
0
    return;
1979
1980
4.40M
  real_sec->reloc_count = hdr->s_paddr;
1981
4.40M
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
4.40M
  if (!bfd_section_removed_from_list (abfd, section))
1984
4.40M
    {
1985
4.40M
      bfd_section_list_remove (abfd, section);
1986
4.40M
      --abfd->section_count;
1987
4.40M
    }
1988
4.40M
}
coff64-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1969
2.00M
{
1970
2.00M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
2.00M
  asection *real_sec;
1972
1973
2.00M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
1.62M
    return;
1975
1976
379k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
379k
  if (real_sec == NULL)
1978
0
    return;
1979
1980
379k
  real_sec->reloc_count = hdr->s_paddr;
1981
379k
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
379k
  if (!bfd_section_removed_from_list (abfd, section))
1984
379k
    {
1985
379k
      bfd_section_list_remove (abfd, section);
1986
379k
      --abfd->section_count;
1987
379k
    }
1988
379k
}
coff-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1969
22.3M
{
1970
22.3M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1971
22.3M
  asection *real_sec;
1972
1973
22.3M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1974
18.3M
    return;
1975
1976
4.02M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1977
4.02M
  if (real_sec == NULL)
1978
0
    return;
1979
1980
4.02M
  real_sec->reloc_count = hdr->s_paddr;
1981
4.02M
  real_sec->lineno_count = hdr->s_vaddr;
1982
1983
4.02M
  if (!bfd_section_removed_from_list (abfd, section))
1984
4.02M
    {
1985
4.02M
      bfd_section_list_remove (abfd, section);
1986
4.02M
      --abfd->section_count;
1987
4.02M
    }
1988
4.02M
}
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
3.36M
{
1996
3.36M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
3.36M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
1.00M
    {
2001
1.00M
      struct external_reloc dst;
2002
1.00M
      struct internal_reloc n;
2003
1.00M
      const file_ptr oldpos = bfd_tell (abfd);
2004
1.00M
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
1.00M
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
1.00M
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
847k
  return;
2010
2011
158k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
158k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
158k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
158k
      section->rel_filepos += relsz;
2016
158k
    }
2017
2.35M
  else if (hdr->s_nreloc == 0xffff)
2018
44.8k
    _bfd_error_handler
2019
44.8k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
44.8k
       abfd);
2021
3.36M
}
coff-go32.c:coff_set_alignment_hook
Line
Count
Source
1995
2.85M
{
1996
2.85M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
2.85M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
827k
    {
2001
827k
      struct external_reloc dst;
2002
827k
      struct internal_reloc n;
2003
827k
      const file_ptr oldpos = bfd_tell (abfd);
2004
827k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
827k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
827k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
687k
  return;
2010
2011
140k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
140k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
140k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
140k
      section->rel_filepos += relsz;
2016
140k
    }
2017
2.02M
  else if (hdr->s_nreloc == 0xffff)
2018
37.1k
    _bfd_error_handler
2019
37.1k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
37.1k
       abfd);
2021
2.85M
}
coff-stgo32.c:coff_set_alignment_hook
Line
Count
Source
1995
513k
{
1996
513k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1997
1998
  /* Check for extended relocs.  */
1999
513k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2000
178k
    {
2001
178k
      struct external_reloc dst;
2002
178k
      struct internal_reloc n;
2003
178k
      const file_ptr oldpos = bfd_tell (abfd);
2004
178k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2005
2006
178k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2007
0
  return;
2008
178k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2009
160k
  return;
2010
2011
18.3k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2012
18.3k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2013
0
  return;
2014
18.3k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2015
18.3k
      section->rel_filepos += relsz;
2016
18.3k
    }
2017
334k
  else if (hdr->s_nreloc == 0xffff)
2018
7.66k
    _bfd_error_handler
2019
7.66k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2020
7.66k
       abfd);
2021
513k
}
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
44.0M
{
2030
44.0M
}
coff-x86_64.c:coff_set_alignment_hook
Line
Count
Source
2029
10.9M
{
2030
10.9M
}
cf-i386lynx.c:coff_set_alignment_hook
Line
Count
Source
2029
4.37M
{
2030
4.37M
}
coff-i386.c:coff_set_alignment_hook
Line
Count
Source
2029
3.87M
{
2030
3.87M
}
coff-sh.c:coff_set_alignment_hook
Line
Count
Source
2029
6.73M
{
2030
6.73M
}
coff-tic30.c:coff_set_alignment_hook
Line
Count
Source
2029
4.73M
{
2030
4.73M
}
coff-z8k.c:coff_set_alignment_hook
Line
Count
Source
2029
13.4M
{
2030
13.4M
}
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
549k
{
2042
549k
  coff_data_type *coff;
2043
549k
  size_t amt = sizeof (coff_data_type);
2044
2045
549k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
549k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
549k
  coff = coff_data (abfd);
2050
549k
  coff->symbols = NULL;
2051
549k
  coff->conversion_table = NULL;
2052
549k
  coff->raw_syments = NULL;
2053
549k
  coff->relocbase = 0;
2054
549k
  coff->local_toc_sym_map = 0;
2055
2056
549k
  bfd_coff_long_section_names (abfd)
2057
549k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
549k
  return true;
2062
549k
}
coff-x86_64.c:coff_mkobject
Line
Count
Source
2041
163k
{
2042
163k
  coff_data_type *coff;
2043
163k
  size_t amt = sizeof (coff_data_type);
2044
2045
163k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
163k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
163k
  coff = coff_data (abfd);
2050
163k
  coff->symbols = NULL;
2051
163k
  coff->conversion_table = NULL;
2052
163k
  coff->raw_syments = NULL;
2053
163k
  coff->relocbase = 0;
2054
163k
  coff->local_toc_sym_map = 0;
2055
2056
163k
  bfd_coff_long_section_names (abfd)
2057
163k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
163k
  return true;
2062
163k
}
cf-i386lynx.c:coff_mkobject
Line
Count
Source
2041
55.2k
{
2042
55.2k
  coff_data_type *coff;
2043
55.2k
  size_t amt = sizeof (coff_data_type);
2044
2045
55.2k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
55.2k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
55.2k
  coff = coff_data (abfd);
2050
55.2k
  coff->symbols = NULL;
2051
55.2k
  coff->conversion_table = NULL;
2052
55.2k
  coff->raw_syments = NULL;
2053
55.2k
  coff->relocbase = 0;
2054
55.2k
  coff->local_toc_sym_map = 0;
2055
2056
55.2k
  bfd_coff_long_section_names (abfd)
2057
55.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
55.2k
  return true;
2062
55.2k
}
coff-i386.c:coff_mkobject
Line
Count
Source
2041
53.4k
{
2042
53.4k
  coff_data_type *coff;
2043
53.4k
  size_t amt = sizeof (coff_data_type);
2044
2045
53.4k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
53.4k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
53.4k
  coff = coff_data (abfd);
2050
53.4k
  coff->symbols = NULL;
2051
53.4k
  coff->conversion_table = NULL;
2052
53.4k
  coff->raw_syments = NULL;
2053
53.4k
  coff->relocbase = 0;
2054
53.4k
  coff->local_toc_sym_map = 0;
2055
2056
53.4k
  bfd_coff_long_section_names (abfd)
2057
53.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
53.4k
  return true;
2062
53.4k
}
coff-sh.c:coff_mkobject
Line
Count
Source
2041
60.8k
{
2042
60.8k
  coff_data_type *coff;
2043
60.8k
  size_t amt = sizeof (coff_data_type);
2044
2045
60.8k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
60.8k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
60.8k
  coff = coff_data (abfd);
2050
60.8k
  coff->symbols = NULL;
2051
60.8k
  coff->conversion_table = NULL;
2052
60.8k
  coff->raw_syments = NULL;
2053
60.8k
  coff->relocbase = 0;
2054
60.8k
  coff->local_toc_sym_map = 0;
2055
2056
60.8k
  bfd_coff_long_section_names (abfd)
2057
60.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
60.8k
  return true;
2062
60.8k
}
coff-tic30.c:coff_mkobject
Line
Count
Source
2041
40.9k
{
2042
40.9k
  coff_data_type *coff;
2043
40.9k
  size_t amt = sizeof (coff_data_type);
2044
2045
40.9k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
40.9k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
40.9k
  coff = coff_data (abfd);
2050
40.9k
  coff->symbols = NULL;
2051
40.9k
  coff->conversion_table = NULL;
2052
40.9k
  coff->raw_syments = NULL;
2053
40.9k
  coff->relocbase = 0;
2054
40.9k
  coff->local_toc_sym_map = 0;
2055
2056
40.9k
  bfd_coff_long_section_names (abfd)
2057
40.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
40.9k
  return true;
2062
40.9k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject
coff-tic54x.c:coff_mkobject
Line
Count
Source
2041
96.2k
{
2042
96.2k
  coff_data_type *coff;
2043
96.2k
  size_t amt = sizeof (coff_data_type);
2044
2045
96.2k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
96.2k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
96.2k
  coff = coff_data (abfd);
2050
96.2k
  coff->symbols = NULL;
2051
96.2k
  coff->conversion_table = NULL;
2052
96.2k
  coff->raw_syments = NULL;
2053
96.2k
  coff->relocbase = 0;
2054
96.2k
  coff->local_toc_sym_map = 0;
2055
2056
96.2k
  bfd_coff_long_section_names (abfd)
2057
96.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
96.2k
  return true;
2062
96.2k
}
coff-z80.c:coff_mkobject
Line
Count
Source
2041
35.8k
{
2042
35.8k
  coff_data_type *coff;
2043
35.8k
  size_t amt = sizeof (coff_data_type);
2044
2045
35.8k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
35.8k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
35.8k
  coff = coff_data (abfd);
2050
35.8k
  coff->symbols = NULL;
2051
35.8k
  coff->conversion_table = NULL;
2052
35.8k
  coff->raw_syments = NULL;
2053
35.8k
  coff->relocbase = 0;
2054
35.8k
  coff->local_toc_sym_map = 0;
2055
2056
35.8k
  bfd_coff_long_section_names (abfd)
2057
35.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
35.8k
  return true;
2062
35.8k
}
coff-z8k.c:coff_mkobject
Line
Count
Source
2041
43.3k
{
2042
43.3k
  coff_data_type *coff;
2043
43.3k
  size_t amt = sizeof (coff_data_type);
2044
2045
43.3k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2046
43.3k
  if (abfd->tdata.coff_obj_data == NULL)
2047
0
    return false;
2048
2049
43.3k
  coff = coff_data (abfd);
2050
43.3k
  coff->symbols = NULL;
2051
43.3k
  coff->conversion_table = NULL;
2052
43.3k
  coff->raw_syments = NULL;
2053
43.3k
  coff->relocbase = 0;
2054
43.3k
  coff->local_toc_sym_map = 0;
2055
2056
43.3k
  bfd_coff_long_section_names (abfd)
2057
43.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2058
2059
/*  make_abs_section(abfd);*/
2060
2061
43.3k
  return true;
2062
43.3k
}
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
753k
{
2073
753k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
753k
  coff_data_type *coff;
2075
2076
753k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
753k
  coff = coff_data (abfd);
2080
2081
753k
  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
753k
  coff->local_n_btmask = N_BTMASK;
2087
753k
  coff->local_n_btshft = N_BTSHFT;
2088
753k
  coff->local_n_tmask = N_TMASK;
2089
753k
  coff->local_n_tshift = N_TSHIFT;
2090
753k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
753k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
753k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
753k
  coff->timestamp = internal_f->f_timdat;
2095
2096
753k
  obj_raw_syment_count (abfd) =
2097
753k
    obj_conv_table_size (abfd) =
2098
753k
      internal_f->f_nsyms;
2099
2100
#ifdef RS6000COFF_C
2101
148k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
46.2k
    abfd->flags |= DYNAMIC;
2103
148k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
36.1k
    {
2105
36.1k
      struct internal_aouthdr *internal_a =
2106
36.1k
  (struct internal_aouthdr *) aouthdr;
2107
36.1k
      struct xcoff_tdata *xcoff;
2108
2109
36.1k
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
18.9k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
36.1k
      xcoff->full_aouthdr = true;
2116
36.1k
      xcoff->toc = internal_a->o_toc;
2117
36.1k
      xcoff->sntoc = internal_a->o_sntoc;
2118
36.1k
      xcoff->snentry = internal_a->o_snentry;
2119
36.1k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
36.1k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
36.1k
      xcoff->modtype = internal_a->o_modtype;
2122
36.1k
      xcoff->cputype = internal_a->o_cputype;
2123
36.1k
      xcoff->maxdata = internal_a->o_maxdata;
2124
36.1k
      xcoff->maxstack = internal_a->o_maxstack;
2125
36.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
753k
  return coff;
2142
753k
}
coff-x86_64.c:coff_mkobject_hook
Line
Count
Source
2072
163k
{
2073
163k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
163k
  coff_data_type *coff;
2075
2076
163k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
163k
  coff = coff_data (abfd);
2080
2081
163k
  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
163k
  coff->local_n_btmask = N_BTMASK;
2087
163k
  coff->local_n_btshft = N_BTSHFT;
2088
163k
  coff->local_n_tmask = N_TMASK;
2089
163k
  coff->local_n_tshift = N_TSHIFT;
2090
163k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
163k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
163k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
163k
  coff->timestamp = internal_f->f_timdat;
2095
2096
163k
  obj_raw_syment_count (abfd) =
2097
163k
    obj_conv_table_size (abfd) =
2098
163k
      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
163k
  return coff;
2142
163k
}
coff64-rs6000.c:coff_mkobject_hook
Line
Count
Source
2072
75.7k
{
2073
75.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
75.7k
  coff_data_type *coff;
2075
2076
75.7k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
75.7k
  coff = coff_data (abfd);
2080
2081
75.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
75.7k
  coff->local_n_btmask = N_BTMASK;
2087
75.7k
  coff->local_n_btshft = N_BTSHFT;
2088
75.7k
  coff->local_n_tmask = N_TMASK;
2089
75.7k
  coff->local_n_tshift = N_TSHIFT;
2090
75.7k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
75.7k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
75.7k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
75.7k
  coff->timestamp = internal_f->f_timdat;
2095
2096
75.7k
  obj_raw_syment_count (abfd) =
2097
75.7k
    obj_conv_table_size (abfd) =
2098
75.7k
      internal_f->f_nsyms;
2099
2100
75.7k
#ifdef RS6000COFF_C
2101
75.7k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
24.4k
    abfd->flags |= DYNAMIC;
2103
75.7k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
18.9k
    {
2105
18.9k
      struct internal_aouthdr *internal_a =
2106
18.9k
  (struct internal_aouthdr *) aouthdr;
2107
18.9k
      struct xcoff_tdata *xcoff;
2108
2109
18.9k
      xcoff = xcoff_data (abfd);
2110
18.9k
# ifdef U803XTOCMAGIC
2111
18.9k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
      xcoff->xcoff64 = 0;
2114
# endif
2115
18.9k
      xcoff->full_aouthdr = true;
2116
18.9k
      xcoff->toc = internal_a->o_toc;
2117
18.9k
      xcoff->sntoc = internal_a->o_sntoc;
2118
18.9k
      xcoff->snentry = internal_a->o_snentry;
2119
18.9k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
18.9k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
18.9k
      xcoff->modtype = internal_a->o_modtype;
2122
18.9k
      xcoff->cputype = internal_a->o_cputype;
2123
18.9k
      xcoff->maxdata = internal_a->o_maxdata;
2124
18.9k
      xcoff->maxstack = internal_a->o_maxstack;
2125
18.9k
    }
2126
75.7k
#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
75.7k
  return coff;
2142
75.7k
}
cf-i386lynx.c:coff_mkobject_hook
Line
Count
Source
2072
55.2k
{
2073
55.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
55.2k
  coff_data_type *coff;
2075
2076
55.2k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
55.2k
  coff = coff_data (abfd);
2080
2081
55.2k
  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
55.2k
  coff->local_n_btmask = N_BTMASK;
2087
55.2k
  coff->local_n_btshft = N_BTSHFT;
2088
55.2k
  coff->local_n_tmask = N_TMASK;
2089
55.2k
  coff->local_n_tshift = N_TSHIFT;
2090
55.2k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
55.2k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
55.2k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
55.2k
  coff->timestamp = internal_f->f_timdat;
2095
2096
55.2k
  obj_raw_syment_count (abfd) =
2097
55.2k
    obj_conv_table_size (abfd) =
2098
55.2k
      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
55.2k
  return coff;
2142
55.2k
}
coff-go32.c:coff_mkobject_hook
Line
Count
Source
2072
53.4k
{
2073
53.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
53.4k
  coff_data_type *coff;
2075
2076
53.4k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
53.4k
  coff = coff_data (abfd);
2080
2081
53.4k
  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
53.4k
  coff->local_n_btmask = N_BTMASK;
2087
53.4k
  coff->local_n_btshft = N_BTSHFT;
2088
53.4k
  coff->local_n_tmask = N_TMASK;
2089
53.4k
  coff->local_n_tshift = N_TSHIFT;
2090
53.4k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
53.4k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
53.4k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
53.4k
  coff->timestamp = internal_f->f_timdat;
2095
2096
53.4k
  obj_raw_syment_count (abfd) =
2097
53.4k
    obj_conv_table_size (abfd) =
2098
53.4k
      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
53.4k
  return coff;
2142
53.4k
}
coff-i386.c:coff_mkobject_hook
Line
Count
Source
2072
53.4k
{
2073
53.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
53.4k
  coff_data_type *coff;
2075
2076
53.4k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
53.4k
  coff = coff_data (abfd);
2080
2081
53.4k
  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
53.4k
  coff->local_n_btmask = N_BTMASK;
2087
53.4k
  coff->local_n_btshft = N_BTSHFT;
2088
53.4k
  coff->local_n_tmask = N_TMASK;
2089
53.4k
  coff->local_n_tshift = N_TSHIFT;
2090
53.4k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
53.4k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
53.4k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
53.4k
  coff->timestamp = internal_f->f_timdat;
2095
2096
53.4k
  obj_raw_syment_count (abfd) =
2097
53.4k
    obj_conv_table_size (abfd) =
2098
53.4k
      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
53.4k
  return coff;
2142
53.4k
}
coff-rs6000.c:coff_mkobject_hook
Line
Count
Source
2072
72.4k
{
2073
72.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
72.4k
  coff_data_type *coff;
2075
2076
72.4k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
72.4k
  coff = coff_data (abfd);
2080
2081
72.4k
  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.4k
  coff->local_n_btmask = N_BTMASK;
2087
72.4k
  coff->local_n_btshft = N_BTSHFT;
2088
72.4k
  coff->local_n_tmask = N_TMASK;
2089
72.4k
  coff->local_n_tshift = N_TSHIFT;
2090
72.4k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
72.4k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
72.4k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
72.4k
  coff->timestamp = internal_f->f_timdat;
2095
2096
72.4k
  obj_raw_syment_count (abfd) =
2097
72.4k
    obj_conv_table_size (abfd) =
2098
72.4k
      internal_f->f_nsyms;
2099
2100
72.4k
#ifdef RS6000COFF_C
2101
72.4k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2102
21.7k
    abfd->flags |= DYNAMIC;
2103
72.4k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2104
17.2k
    {
2105
17.2k
      struct internal_aouthdr *internal_a =
2106
17.2k
  (struct internal_aouthdr *) aouthdr;
2107
17.2k
      struct xcoff_tdata *xcoff;
2108
2109
17.2k
      xcoff = xcoff_data (abfd);
2110
# ifdef U803XTOCMAGIC
2111
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2112
# else
2113
17.2k
      xcoff->xcoff64 = 0;
2114
17.2k
# endif
2115
17.2k
      xcoff->full_aouthdr = true;
2116
17.2k
      xcoff->toc = internal_a->o_toc;
2117
17.2k
      xcoff->sntoc = internal_a->o_sntoc;
2118
17.2k
      xcoff->snentry = internal_a->o_snentry;
2119
17.2k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2120
17.2k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2121
17.2k
      xcoff->modtype = internal_a->o_modtype;
2122
17.2k
      xcoff->cputype = internal_a->o_cputype;
2123
17.2k
      xcoff->maxdata = internal_a->o_maxdata;
2124
17.2k
      xcoff->maxstack = internal_a->o_maxstack;
2125
17.2k
    }
2126
72.4k
#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.4k
  return coff;
2142
72.4k
}
coff-sh.c:coff_mkobject_hook
Line
Count
Source
2072
60.7k
{
2073
60.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
60.7k
  coff_data_type *coff;
2075
2076
60.7k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
60.7k
  coff = coff_data (abfd);
2080
2081
60.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
60.7k
  coff->local_n_btmask = N_BTMASK;
2087
60.7k
  coff->local_n_btshft = N_BTSHFT;
2088
60.7k
  coff->local_n_tmask = N_TMASK;
2089
60.7k
  coff->local_n_tshift = N_TSHIFT;
2090
60.7k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
60.7k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
60.7k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
60.7k
  coff->timestamp = internal_f->f_timdat;
2095
2096
60.7k
  obj_raw_syment_count (abfd) =
2097
60.7k
    obj_conv_table_size (abfd) =
2098
60.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
60.7k
  return coff;
2142
60.7k
}
coff-stgo32.c:coff_mkobject_hook
Line
Count
Source
2072
2.04k
{
2073
2.04k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
2.04k
  coff_data_type *coff;
2075
2076
2.04k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
2.04k
  coff = coff_data (abfd);
2080
2081
2.04k
  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
2.04k
  coff->local_n_btmask = N_BTMASK;
2087
2.04k
  coff->local_n_btshft = N_BTSHFT;
2088
2.04k
  coff->local_n_tmask = N_TMASK;
2089
2.04k
  coff->local_n_tshift = N_TSHIFT;
2090
2.04k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
2.04k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
2.04k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
2.04k
  coff->timestamp = internal_f->f_timdat;
2095
2096
2.04k
  obj_raw_syment_count (abfd) =
2097
2.04k
    obj_conv_table_size (abfd) =
2098
2.04k
      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
2.04k
  return coff;
2142
2.04k
}
coff-tic30.c:coff_mkobject_hook
Line
Count
Source
2072
40.8k
{
2073
40.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
40.8k
  coff_data_type *coff;
2075
2076
40.8k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
40.8k
  coff = coff_data (abfd);
2080
2081
40.8k
  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
40.8k
  coff->local_n_btmask = N_BTMASK;
2087
40.8k
  coff->local_n_btshft = N_BTSHFT;
2088
40.8k
  coff->local_n_tmask = N_TMASK;
2089
40.8k
  coff->local_n_tshift = N_TSHIFT;
2090
40.8k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
40.8k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
40.8k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
40.8k
  coff->timestamp = internal_f->f_timdat;
2095
2096
40.8k
  obj_raw_syment_count (abfd) =
2097
40.8k
    obj_conv_table_size (abfd) =
2098
40.8k
      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
40.8k
  return coff;
2142
40.8k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject_hook
coff-tic54x.c:coff_mkobject_hook
Line
Count
Source
2072
96.2k
{
2073
96.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
96.2k
  coff_data_type *coff;
2075
2076
96.2k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
96.2k
  coff = coff_data (abfd);
2080
2081
96.2k
  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
96.2k
  coff->local_n_btmask = N_BTMASK;
2087
96.2k
  coff->local_n_btshft = N_BTSHFT;
2088
96.2k
  coff->local_n_tmask = N_TMASK;
2089
96.2k
  coff->local_n_tshift = N_TSHIFT;
2090
96.2k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
96.2k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
96.2k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
96.2k
  coff->timestamp = internal_f->f_timdat;
2095
2096
96.2k
  obj_raw_syment_count (abfd) =
2097
96.2k
    obj_conv_table_size (abfd) =
2098
96.2k
      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
96.2k
  return coff;
2142
96.2k
}
coff-z80.c:coff_mkobject_hook
Line
Count
Source
2072
35.7k
{
2073
35.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
35.7k
  coff_data_type *coff;
2075
2076
35.7k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
35.7k
  coff = coff_data (abfd);
2080
2081
35.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
35.7k
  coff->local_n_btmask = N_BTMASK;
2087
35.7k
  coff->local_n_btshft = N_BTSHFT;
2088
35.7k
  coff->local_n_tmask = N_TMASK;
2089
35.7k
  coff->local_n_tshift = N_TSHIFT;
2090
35.7k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
35.7k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
35.7k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
35.7k
  coff->timestamp = internal_f->f_timdat;
2095
2096
35.7k
  obj_raw_syment_count (abfd) =
2097
35.7k
    obj_conv_table_size (abfd) =
2098
35.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
35.7k
  return coff;
2142
35.7k
}
coff-z8k.c:coff_mkobject_hook
Line
Count
Source
2072
43.3k
{
2073
43.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2074
43.3k
  coff_data_type *coff;
2075
2076
43.3k
  if (! coff_mkobject (abfd))
2077
0
    return NULL;
2078
2079
43.3k
  coff = coff_data (abfd);
2080
2081
43.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
43.3k
  coff->local_n_btmask = N_BTMASK;
2087
43.3k
  coff->local_n_btshft = N_BTSHFT;
2088
43.3k
  coff->local_n_tmask = N_TMASK;
2089
43.3k
  coff->local_n_tshift = N_TSHIFT;
2090
43.3k
  coff->local_symesz = bfd_coff_symesz (abfd);
2091
43.3k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2092
43.3k
  coff->local_linesz = bfd_coff_linesz (abfd);
2093
2094
43.3k
  coff->timestamp = internal_f->f_timdat;
2095
2096
43.3k
  obj_raw_syment_count (abfd) =
2097
43.3k
    obj_conv_table_size (abfd) =
2098
43.3k
      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
43.3k
  return coff;
2142
43.3k
}
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.18M
{
2155
2.18M
  unsigned long machine;
2156
2.18M
  enum bfd_architecture arch;
2157
2.18M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
2.18M
  machine = 0;
2161
2.18M
  switch (internal_f->f_magic)
2162
2.18M
    {
2163
#ifdef I386MAGIC
2164
227k
    case I386MAGIC:
2165
246k
    case I386PTXMAGIC:
2166
265k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
351k
    case LYNXCOFFMAGIC:
2168
353k
    case I386_APPLE_MAGIC:
2169
353k
    case I386_FREEBSD_MAGIC:
2170
353k
    case I386_LINUX_MAGIC:
2171
360k
    case I386_NETBSD_MAGIC:
2172
360k
      arch = bfd_arch_i386;
2173
360k
      break;
2174
0
#endif
2175
#ifdef AMD64MAGIC
2176
53.0k
    case AMD64MAGIC:
2177
443k
    case AMD64_APPLE_MAGIC:
2178
445k
    case AMD64_FREEBSD_MAGIC:
2179
495k
    case AMD64_LINUX_MAGIC:
2180
496k
    case AMD64_NETBSD_MAGIC:
2181
496k
      arch = bfd_arch_i386;
2182
496k
      machine = bfd_mach_x86_64;
2183
496k
      break;
2184
0
#endif
2185
#ifdef IA64MAGIC
2186
97.1k
    case IA64MAGIC:
2187
97.1k
      arch = bfd_arch_ia64;
2188
97.1k
      break;
2189
0
#endif
2190
#ifdef ARMMAGIC
2191
195k
    case ARMMAGIC:
2192
215k
    case ARMPEMAGIC:
2193
241k
    case THUMBPEMAGIC:
2194
241k
      arch = bfd_arch_arm;
2195
241k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
241k
      if (machine == bfd_mach_arm_unknown)
2197
241k
  {
2198
241k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
241k
      {
2200
13.9k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
19.5k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
20.6k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
117k
      default:
2204
125k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
14.9k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
14.2k
      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
32.4k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
241k
      }
2214
241k
  }
2215
241k
      break;
2216
241k
#endif
2217
#ifdef AARCH64MAGIC
2218
148k
    case AARCH64MAGIC:
2219
148k
      arch = bfd_arch_aarch64;
2220
148k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
148k
      break;
2222
0
#endif
2223
#ifdef LOONGARCH64MAGIC
2224
80.4k
    case LOONGARCH64MAGIC:
2225
80.4k
      arch = bfd_arch_loongarch;
2226
80.4k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
80.4k
      break;
2228
0
#endif
2229
#ifdef RISCV64MAGIC
2230
75.8k
    case RISCV64MAGIC:
2231
75.8k
      arch = bfd_arch_riscv;
2232
75.8k
      machine = bfd_mach_riscv64;
2233
75.8k
      break;
2234
0
#endif
2235
#ifdef Z80MAGIC
2236
35.4k
    case Z80MAGIC:
2237
35.4k
      arch = bfd_arch_z80;
2238
35.4k
      switch (internal_f->f_flags & F_MACHMASK)
2239
35.4k
  {
2240
3.25k
  case bfd_mach_z80strict << 12:
2241
7.22k
  case bfd_mach_z80 << 12:
2242
11.0k
  case bfd_mach_z80n << 12:
2243
14.9k
  case bfd_mach_z80full << 12:
2244
21.0k
  case bfd_mach_r800 << 12:
2245
24.3k
  case bfd_mach_gbz80 << 12:
2246
28.0k
  case bfd_mach_z180 << 12:
2247
31.4k
  case bfd_mach_ez80_z80 << 12:
2248
34.9k
  case bfd_mach_ez80_adl << 12:
2249
34.9k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
34.9k
    break;
2251
513
  default:
2252
513
    return false;
2253
35.4k
  }
2254
34.9k
      break;
2255
34.9k
#endif
2256
#ifdef Z8KMAGIC
2257
42.9k
    case Z8KMAGIC:
2258
42.9k
      arch = bfd_arch_z8k;
2259
42.9k
      switch (internal_f->f_flags & F_MACHMASK)
2260
42.9k
  {
2261
13.6k
  case F_Z8001:
2262
13.6k
    machine = bfd_mach_z8001;
2263
13.6k
    break;
2264
28.7k
  case F_Z8002:
2265
28.7k
    machine = bfd_mach_z8002;
2266
28.7k
    break;
2267
617
  default:
2268
617
    return false;
2269
42.9k
  }
2270
42.3k
      break;
2271
42.3k
#endif
2272
2273
#ifdef RS6000COFF_C
2274
#ifdef XCOFF64
2275
65.7k
    case U64_TOCMAGIC:
2276
74.8k
    case U803XTOCMAGIC:
2277
#else
2278
28.6k
    case U802ROMAGIC:
2279
39.8k
    case U802WRMAGIC:
2280
71.6k
    case U802TOCMAGIC:
2281
#endif
2282
71.6k
      {
2283
71.6k
  int cputype;
2284
2285
146k
  if (xcoff_data (abfd)->cputype != -1)
2286
35.3k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
111k
  else
2288
111k
    {
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
111k
      if (obj_raw_syment_count (abfd) == 0)
2294
57.6k
        cputype = 0;
2295
53.4k
      else
2296
53.4k
        {
2297
53.4k
    bfd_byte *buf;
2298
53.4k
    struct internal_syment sym;
2299
53.4k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
53.4k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
545
      return false;
2303
52.8k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
52.8k
    if (buf == NULL)
2305
1.51k
      return false;
2306
51.3k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
51.3k
    if (sym.n_sclass == C_FILE)
2308
2.30k
      cputype = sym.n_type & 0xff;
2309
49.0k
    else
2310
49.0k
      cputype = 0;
2311
51.3k
    free (buf);
2312
51.3k
        }
2313
111k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
144k
  switch (cputype)
2317
144k
    {
2318
20.3k
    default:
2319
134k
    case 0:
2320
134k
      arch = bfd_xcoff_architecture (abfd);
2321
134k
      machine = bfd_xcoff_machine (abfd);
2322
134k
      break;
2323
2324
3.50k
    case 1:
2325
3.50k
      arch = bfd_arch_powerpc;
2326
3.50k
      machine = bfd_mach_ppc_601;
2327
3.50k
      break;
2328
1.89k
    case 2: /* 64 bit PowerPC */
2329
1.89k
      arch = bfd_arch_powerpc;
2330
1.89k
      machine = bfd_mach_ppc_620;
2331
1.89k
      break;
2332
1.80k
    case 3:
2333
1.80k
      arch = bfd_arch_powerpc;
2334
1.80k
      machine = bfd_mach_ppc;
2335
1.80k
      break;
2336
2.69k
    case 4:
2337
2.69k
      arch = bfd_arch_rs6000;
2338
2.69k
      machine = bfd_mach_rs6k;
2339
2.69k
      break;
2340
144k
    }
2341
144k
      }
2342
144k
      break;
2343
144k
#endif
2344
2345
#ifdef SH_ARCH_MAGIC_BIG
2346
125k
    case SH_ARCH_MAGIC_BIG:
2347
139k
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
127k
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
127k
      arch = bfd_arch_sh;
2352
127k
      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
40.3k
    case TIC30MAGIC:
2372
40.3k
      arch = bfd_arch_tic30;
2373
40.3k
      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
86.8k
    case TICOFF0MAGIC:
2380
86.8k
      arch = TICOFF_TARGET_ARCH;
2381
86.8k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
86.8k
      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
3.22k
    case TICOFF1MAGIC:
2390
3.70k
    case TICOFF2MAGIC:
2391
3.70k
      switch (internal_f->f_target_id)
2392
3.70k
  {
2393
0
#ifdef TI_TARGET_ID
2394
3.70k
  case TI_TARGET_ID:
2395
3.70k
    arch = TICOFF_TARGET_ARCH;
2396
3.70k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
3.70k
    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
3.70k
  }
2406
3.70k
      break;
2407
3.70k
#endif
2408
2409
#ifdef MCOREMAGIC
2410
133k
    case MCOREMAGIC:
2411
133k
      arch = bfd_arch_mcore;
2412
133k
      break;
2413
0
#endif
2414
2415
34.6k
    default:      /* Unreadable input file type.  */
2416
34.6k
      arch = bfd_arch_obscure;
2417
34.6k
      break;
2418
2.18M
    }
2419
2420
2.18M
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
2.18M
  return true;
2422
2.18M
}
pei-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
131k
{
2155
131k
  unsigned long machine;
2156
131k
  enum bfd_architecture arch;
2157
131k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
131k
  machine = 0;
2161
131k
  switch (internal_f->f_magic)
2162
131k
    {
2163
0
#ifdef I386MAGIC
2164
58.2k
    case I386MAGIC:
2165
64.5k
    case I386PTXMAGIC:
2166
76.1k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
126k
    case LYNXCOFFMAGIC:
2168
127k
    case I386_APPLE_MAGIC:
2169
127k
    case I386_FREEBSD_MAGIC:
2170
127k
    case I386_LINUX_MAGIC:
2171
131k
    case I386_NETBSD_MAGIC:
2172
131k
      arch = bfd_arch_i386;
2173
131k
      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
131k
    }
2419
2420
131k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
131k
  return true;
2422
131k
}
pe-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
211k
{
2155
211k
  unsigned long machine;
2156
211k
  enum bfd_architecture arch;
2157
211k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
211k
  machine = 0;
2161
211k
  switch (internal_f->f_magic)
2162
211k
    {
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
6.18k
    case AMD64MAGIC:
2177
202k
    case AMD64_APPLE_MAGIC:
2178
203k
    case AMD64_FREEBSD_MAGIC:
2179
211k
    case AMD64_LINUX_MAGIC:
2180
211k
    case AMD64_NETBSD_MAGIC:
2181
211k
      arch = bfd_arch_i386;
2182
211k
      machine = bfd_mach_x86_64;
2183
211k
      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
211k
    }
2419
2420
211k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
211k
  return true;
2422
211k
}
pei-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
122k
{
2155
122k
  unsigned long machine;
2156
122k
  enum bfd_architecture arch;
2157
122k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
122k
  machine = 0;
2161
122k
  switch (internal_f->f_magic)
2162
122k
    {
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
42.3k
    case AMD64MAGIC:
2177
84.7k
    case AMD64_APPLE_MAGIC:
2178
84.7k
    case AMD64_FREEBSD_MAGIC:
2179
122k
    case AMD64_LINUX_MAGIC:
2180
122k
    case AMD64_NETBSD_MAGIC:
2181
122k
      arch = bfd_arch_i386;
2182
122k
      machine = bfd_mach_x86_64;
2183
122k
      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
122k
    }
2419
2420
122k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
122k
  return true;
2422
122k
}
coff-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
162k
{
2155
162k
  unsigned long machine;
2156
162k
  enum bfd_architecture arch;
2157
162k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
162k
  machine = 0;
2161
162k
  switch (internal_f->f_magic)
2162
162k
    {
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
4.49k
    case AMD64MAGIC:
2177
156k
    case AMD64_APPLE_MAGIC:
2178
157k
    case AMD64_FREEBSD_MAGIC:
2179
161k
    case AMD64_LINUX_MAGIC:
2180
162k
    case AMD64_NETBSD_MAGIC:
2181
162k
      arch = bfd_arch_i386;
2182
162k
      machine = bfd_mach_x86_64;
2183
162k
      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
162k
    }
2419
2420
162k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
162k
  return true;
2422
162k
}
coff64-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2154
74.8k
{
2155
74.8k
  unsigned long machine;
2156
74.8k
  enum bfd_architecture arch;
2157
74.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
74.8k
  machine = 0;
2161
74.8k
  switch (internal_f->f_magic)
2162
74.8k
    {
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
65.7k
    case U64_TOCMAGIC:
2276
74.8k
    case U803XTOCMAGIC:
2277
#else
2278
    case U802ROMAGIC:
2279
    case U802WRMAGIC:
2280
    case U802TOCMAGIC:
2281
#endif
2282
74.8k
      {
2283
74.8k
  int cputype;
2284
2285
74.8k
  if (xcoff_data (abfd)->cputype != -1)
2286
18.3k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
56.4k
  else
2288
56.4k
    {
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
56.4k
      if (obj_raw_syment_count (abfd) == 0)
2294
35.5k
        cputype = 0;
2295
20.9k
      else
2296
20.9k
        {
2297
20.9k
    bfd_byte *buf;
2298
20.9k
    struct internal_syment sym;
2299
20.9k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
20.9k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
545
      return false;
2303
20.3k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
20.3k
    if (buf == NULL)
2305
528
      return false;
2306
19.8k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
19.8k
    if (sym.n_sclass == C_FILE)
2308
1.35k
      cputype = sym.n_type & 0xff;
2309
18.4k
    else
2310
18.4k
      cputype = 0;
2311
19.8k
    free (buf);
2312
19.8k
        }
2313
56.4k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
73.7k
  switch (cputype)
2317
73.7k
    {
2318
10.6k
    default:
2319
68.0k
    case 0:
2320
68.0k
      arch = bfd_xcoff_architecture (abfd);
2321
68.0k
      machine = bfd_xcoff_machine (abfd);
2322
68.0k
      break;
2323
2324
2.25k
    case 1:
2325
2.25k
      arch = bfd_arch_powerpc;
2326
2.25k
      machine = bfd_mach_ppc_601;
2327
2.25k
      break;
2328
778
    case 2: /* 64 bit PowerPC */
2329
778
      arch = bfd_arch_powerpc;
2330
778
      machine = bfd_mach_ppc_620;
2331
778
      break;
2332
1.12k
    case 3:
2333
1.12k
      arch = bfd_arch_powerpc;
2334
1.12k
      machine = bfd_mach_ppc;
2335
1.12k
      break;
2336
1.55k
    case 4:
2337
1.55k
      arch = bfd_arch_rs6000;
2338
1.55k
      machine = bfd_mach_rs6k;
2339
1.55k
      break;
2340
73.7k
    }
2341
73.7k
      }
2342
73.7k
      break;
2343
73.7k
#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
73.7k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
74.8k
    }
2419
2420
73.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
73.7k
  return true;
2422
74.8k
}
pe-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
58.9k
{
2155
58.9k
  unsigned long machine;
2156
58.9k
  enum bfd_architecture arch;
2157
58.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
58.9k
  machine = 0;
2161
58.9k
  switch (internal_f->f_magic)
2162
58.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
58.9k
    case AARCH64MAGIC:
2219
58.9k
      arch = bfd_arch_aarch64;
2220
58.9k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
58.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
58.9k
    }
2419
2420
58.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
58.9k
  return true;
2422
58.9k
}
pei-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
89.0k
{
2155
89.0k
  unsigned long machine;
2156
89.0k
  enum bfd_architecture arch;
2157
89.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
89.0k
  machine = 0;
2161
89.0k
  switch (internal_f->f_magic)
2162
89.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
0
#ifdef AARCH64MAGIC
2218
89.0k
    case AARCH64MAGIC:
2219
89.0k
      arch = bfd_arch_aarch64;
2220
89.0k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2221
89.0k
      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
89.0k
    }
2419
2420
89.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
89.0k
  return true;
2422
89.0k
}
pei-ia64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
97.1k
{
2155
97.1k
  unsigned long machine;
2156
97.1k
  enum bfd_architecture arch;
2157
97.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
97.1k
  machine = 0;
2161
97.1k
  switch (internal_f->f_magic)
2162
97.1k
    {
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
97.1k
    case IA64MAGIC:
2187
97.1k
      arch = bfd_arch_ia64;
2188
97.1k
      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
97.1k
    }
2419
2420
97.1k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
97.1k
  return true;
2422
97.1k
}
pei-loongarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
80.4k
{
2155
80.4k
  unsigned long machine;
2156
80.4k
  enum bfd_architecture arch;
2157
80.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
80.4k
  machine = 0;
2161
80.4k
  switch (internal_f->f_magic)
2162
80.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
0
#ifdef LOONGARCH64MAGIC
2224
80.4k
    case LOONGARCH64MAGIC:
2225
80.4k
      arch = bfd_arch_loongarch;
2226
80.4k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2227
80.4k
      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
80.4k
    }
2419
2420
80.4k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
80.4k
  return true;
2422
80.4k
}
pei-riscv64.c:coff_set_arch_mach_hook
Line
Count
Source
2154
75.8k
{
2155
75.8k
  unsigned long machine;
2156
75.8k
  enum bfd_architecture arch;
2157
75.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
75.8k
  machine = 0;
2161
75.8k
  switch (internal_f->f_magic)
2162
75.8k
    {
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
75.8k
    case RISCV64MAGIC:
2231
75.8k
      arch = bfd_arch_riscv;
2232
75.8k
      machine = bfd_mach_riscv64;
2233
75.8k
      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
75.8k
    }
2419
2420
75.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
75.8k
  return true;
2422
75.8k
}
cf-i386lynx.c:coff_set_arch_mach_hook
Line
Count
Source
2154
54.0k
{
2155
54.0k
  unsigned long machine;
2156
54.0k
  enum bfd_architecture arch;
2157
54.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
54.0k
  machine = 0;
2161
54.0k
  switch (internal_f->f_magic)
2162
54.0k
    {
2163
0
#ifdef I386MAGIC
2164
39.9k
    case I386MAGIC:
2165
43.1k
    case I386PTXMAGIC:
2166
44.7k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
53.3k
    case LYNXCOFFMAGIC:
2168
53.5k
    case I386_APPLE_MAGIC:
2169
53.5k
    case I386_FREEBSD_MAGIC:
2170
53.6k
    case I386_LINUX_MAGIC:
2171
54.0k
    case I386_NETBSD_MAGIC:
2172
54.0k
      arch = bfd_arch_i386;
2173
54.0k
      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
54.0k
    }
2419
2420
54.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
54.0k
  return true;
2422
54.0k
}
coff-go32.c:coff_set_arch_mach_hook
Line
Count
Source
2154
52.2k
{
2155
52.2k
  unsigned long machine;
2156
52.2k
  enum bfd_architecture arch;
2157
52.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
52.2k
  machine = 0;
2161
52.2k
  switch (internal_f->f_magic)
2162
52.2k
    {
2163
0
#ifdef I386MAGIC
2164
38.9k
    case I386MAGIC:
2165
41.7k
    case I386PTXMAGIC:
2166
43.2k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
51.8k
    case LYNXCOFFMAGIC:
2168
52.0k
    case I386_APPLE_MAGIC:
2169
52.0k
    case I386_FREEBSD_MAGIC:
2170
52.0k
    case I386_LINUX_MAGIC:
2171
52.2k
    case I386_NETBSD_MAGIC:
2172
52.2k
      arch = bfd_arch_i386;
2173
52.2k
      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
52.2k
    }
2419
2420
52.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
52.2k
  return true;
2422
52.2k
}
coff-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
52.2k
{
2155
52.2k
  unsigned long machine;
2156
52.2k
  enum bfd_architecture arch;
2157
52.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
52.2k
  machine = 0;
2161
52.2k
  switch (internal_f->f_magic)
2162
52.2k
    {
2163
0
#ifdef I386MAGIC
2164
38.9k
    case I386MAGIC:
2165
41.7k
    case I386PTXMAGIC:
2166
43.2k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
51.8k
    case LYNXCOFFMAGIC:
2168
52.0k
    case I386_APPLE_MAGIC:
2169
52.0k
    case I386_FREEBSD_MAGIC:
2170
52.0k
    case I386_LINUX_MAGIC:
2171
52.2k
    case I386_NETBSD_MAGIC:
2172
52.2k
      arch = bfd_arch_i386;
2173
52.2k
      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
52.2k
    }
2419
2420
52.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
52.2k
  return true;
2422
52.2k
}
coff-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2154
71.6k
{
2155
71.6k
  unsigned long machine;
2156
71.6k
  enum bfd_architecture arch;
2157
71.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
71.6k
  machine = 0;
2161
71.6k
  switch (internal_f->f_magic)
2162
71.6k
    {
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
28.6k
    case U802ROMAGIC:
2279
39.8k
    case U802WRMAGIC:
2280
71.6k
    case U802TOCMAGIC:
2281
71.6k
#endif
2282
71.6k
      {
2283
71.6k
  int cputype;
2284
2285
71.6k
  if (xcoff_data (abfd)->cputype != -1)
2286
17.0k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2287
54.5k
  else
2288
54.5k
    {
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
54.5k
      if (obj_raw_syment_count (abfd) == 0)
2294
22.0k
        cputype = 0;
2295
32.5k
      else
2296
32.5k
        {
2297
32.5k
    bfd_byte *buf;
2298
32.5k
    struct internal_syment sym;
2299
32.5k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2300
2301
32.5k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2302
0
      return false;
2303
32.5k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2304
32.5k
    if (buf == NULL)
2305
982
      return false;
2306
31.5k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2307
31.5k
    if (sym.n_sclass == C_FILE)
2308
951
      cputype = sym.n_type & 0xff;
2309
30.5k
    else
2310
30.5k
      cputype = 0;
2311
31.5k
    free (buf);
2312
31.5k
        }
2313
54.5k
    }
2314
2315
  /* FIXME: We don't handle all cases here.  */
2316
70.6k
  switch (cputype)
2317
70.6k
    {
2318
9.73k
    default:
2319
66.4k
    case 0:
2320
66.4k
      arch = bfd_xcoff_architecture (abfd);
2321
66.4k
      machine = bfd_xcoff_machine (abfd);
2322
66.4k
      break;
2323
2324
1.24k
    case 1:
2325
1.24k
      arch = bfd_arch_powerpc;
2326
1.24k
      machine = bfd_mach_ppc_601;
2327
1.24k
      break;
2328
1.11k
    case 2: /* 64 bit PowerPC */
2329
1.11k
      arch = bfd_arch_powerpc;
2330
1.11k
      machine = bfd_mach_ppc_620;
2331
1.11k
      break;
2332
679
    case 3:
2333
679
      arch = bfd_arch_powerpc;
2334
679
      machine = bfd_mach_ppc;
2335
679
      break;
2336
1.14k
    case 4:
2337
1.14k
      arch = bfd_arch_rs6000;
2338
1.14k
      machine = bfd_mach_rs6k;
2339
1.14k
      break;
2340
70.6k
    }
2341
70.6k
      }
2342
70.6k
      break;
2343
70.6k
#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
70.6k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
71.6k
    }
2419
2420
70.6k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
70.6k
  return true;
2422
71.6k
}
coff-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
57.6k
{
2155
57.6k
  unsigned long machine;
2156
57.6k
  enum bfd_architecture arch;
2157
57.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
57.6k
  machine = 0;
2161
57.6k
  switch (internal_f->f_magic)
2162
57.6k
    {
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
37.9k
    case SH_ARCH_MAGIC_BIG:
2347
38.9k
    case SH_ARCH_MAGIC_LITTLE:
2348
#ifdef COFF_WITH_PE
2349
    case SH_ARCH_MAGIC_WINCE:
2350
#endif
2351
38.9k
      arch = bfd_arch_sh;
2352
38.9k
      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
18.6k
    default:      /* Unreadable input file type.  */
2416
18.6k
      arch = bfd_arch_obscure;
2417
18.6k
      break;
2418
57.6k
    }
2419
2420
57.6k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
57.6k
  return true;
2422
57.6k
}
coff-stgo32.c:coff_set_arch_mach_hook
Line
Count
Source
2154
2.00k
{
2155
2.00k
  unsigned long machine;
2156
2.00k
  enum bfd_architecture arch;
2157
2.00k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
2.00k
  machine = 0;
2161
2.00k
  switch (internal_f->f_magic)
2162
2.00k
    {
2163
0
#ifdef I386MAGIC
2164
1.10k
    case I386MAGIC:
2165
1.48k
    case I386PTXMAGIC:
2166
1.56k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
1.63k
    case LYNXCOFFMAGIC:
2168
1.63k
    case I386_APPLE_MAGIC:
2169
1.64k
    case I386_FREEBSD_MAGIC:
2170
1.69k
    case I386_LINUX_MAGIC:
2171
2.00k
    case I386_NETBSD_MAGIC:
2172
2.00k
      arch = bfd_arch_i386;
2173
2.00k
      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
2.00k
    }
2419
2420
2.00k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
2.00k
  return true;
2422
2.00k
}
coff-tic30.c:coff_set_arch_mach_hook
Line
Count
Source
2154
40.3k
{
2155
40.3k
  unsigned long machine;
2156
40.3k
  enum bfd_architecture arch;
2157
40.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
40.3k
  machine = 0;
2161
40.3k
  switch (internal_f->f_magic)
2162
40.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
#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
40.3k
    case TIC30MAGIC:
2372
40.3k
      arch = bfd_arch_tic30;
2373
40.3k
      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
40.3k
    }
2419
2420
40.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
40.3k
  return true;
2422
40.3k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach_hook
coff-tic54x.c:coff_set_arch_mach_hook
Line
Count
Source
2154
90.5k
{
2155
90.5k
  unsigned long machine;
2156
90.5k
  enum bfd_architecture arch;
2157
90.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
90.5k
  machine = 0;
2161
90.5k
  switch (internal_f->f_magic)
2162
90.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
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
86.8k
    case TICOFF0MAGIC:
2380
86.8k
      arch = TICOFF_TARGET_ARCH;
2381
86.8k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2382
86.8k
      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
3.22k
    case TICOFF1MAGIC:
2390
3.70k
    case TICOFF2MAGIC:
2391
3.70k
      switch (internal_f->f_target_id)
2392
3.70k
  {
2393
0
#ifdef TI_TARGET_ID
2394
3.70k
  case TI_TARGET_ID:
2395
3.70k
    arch = TICOFF_TARGET_ARCH;
2396
3.70k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2397
3.70k
    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
3.70k
  }
2406
3.70k
      break;
2407
3.70k
#endif
2408
2409
#ifdef MCOREMAGIC
2410
    case MCOREMAGIC:
2411
      arch = bfd_arch_mcore;
2412
      break;
2413
#endif
2414
2415
3.70k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
90.5k
    }
2419
2420
90.5k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
90.5k
  return true;
2422
90.5k
}
coff-z80.c:coff_set_arch_mach_hook
Line
Count
Source
2154
35.4k
{
2155
35.4k
  unsigned long machine;
2156
35.4k
  enum bfd_architecture arch;
2157
35.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
35.4k
  machine = 0;
2161
35.4k
  switch (internal_f->f_magic)
2162
35.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
35.4k
    case Z80MAGIC:
2237
35.4k
      arch = bfd_arch_z80;
2238
35.4k
      switch (internal_f->f_flags & F_MACHMASK)
2239
35.4k
  {
2240
3.25k
  case bfd_mach_z80strict << 12:
2241
7.22k
  case bfd_mach_z80 << 12:
2242
11.0k
  case bfd_mach_z80n << 12:
2243
14.9k
  case bfd_mach_z80full << 12:
2244
21.0k
  case bfd_mach_r800 << 12:
2245
24.3k
  case bfd_mach_gbz80 << 12:
2246
28.0k
  case bfd_mach_z180 << 12:
2247
31.4k
  case bfd_mach_ez80_z80 << 12:
2248
34.9k
  case bfd_mach_ez80_adl << 12:
2249
34.9k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2250
34.9k
    break;
2251
513
  default:
2252
513
    return false;
2253
35.4k
  }
2254
34.9k
      break;
2255
34.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
34.9k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
35.4k
    }
2419
2420
34.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
34.9k
  return true;
2422
35.4k
}
coff-z8k.c:coff_set_arch_mach_hook
Line
Count
Source
2154
42.9k
{
2155
42.9k
  unsigned long machine;
2156
42.9k
  enum bfd_architecture arch;
2157
42.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
42.9k
  machine = 0;
2161
42.9k
  switch (internal_f->f_magic)
2162
42.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
0
#ifdef Z8KMAGIC
2257
42.9k
    case Z8KMAGIC:
2258
42.9k
      arch = bfd_arch_z8k;
2259
42.9k
      switch (internal_f->f_flags & F_MACHMASK)
2260
42.9k
  {
2261
13.6k
  case F_Z8001:
2262
13.6k
    machine = bfd_mach_z8001;
2263
13.6k
    break;
2264
28.7k
  case F_Z8002:
2265
28.7k
    machine = bfd_mach_z8002;
2266
28.7k
    break;
2267
617
  default:
2268
617
    return false;
2269
42.9k
  }
2270
42.3k
      break;
2271
42.3k
#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
42.3k
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
42.9k
    }
2419
2420
42.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
42.3k
  return true;
2422
42.9k
}
pe-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2154
26.2k
{
2155
26.2k
  unsigned long machine;
2156
26.2k
  enum bfd_architecture arch;
2157
26.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
26.2k
  machine = 0;
2161
26.2k
  switch (internal_f->f_magic)
2162
26.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
0
#ifdef ARMMAGIC
2191
19.7k
    case ARMMAGIC:
2192
21.7k
    case ARMPEMAGIC:
2193
25.3k
    case THUMBPEMAGIC:
2194
25.3k
      arch = bfd_arch_arm;
2195
25.3k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
25.3k
      if (machine == bfd_mach_arm_unknown)
2197
25.3k
  {
2198
25.3k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
25.3k
      {
2200
3.33k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
4.83k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
1.88k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
10.4k
      default:
2204
10.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
1.40k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
1.16k
      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
1.75k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
25.3k
      }
2214
25.3k
  }
2215
25.3k
      break;
2216
25.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
25.3k
    default:      /* Unreadable input file type.  */
2416
914
      arch = bfd_arch_obscure;
2417
914
      break;
2418
26.2k
    }
2419
2420
26.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
26.2k
  return true;
2422
26.2k
}
pe-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2154
26.2k
{
2155
26.2k
  unsigned long machine;
2156
26.2k
  enum bfd_architecture arch;
2157
26.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
26.2k
  machine = 0;
2161
26.2k
  switch (internal_f->f_magic)
2162
26.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
0
#ifdef ARMMAGIC
2191
19.7k
    case ARMMAGIC:
2192
21.7k
    case ARMPEMAGIC:
2193
25.3k
    case THUMBPEMAGIC:
2194
25.3k
      arch = bfd_arch_arm;
2195
25.3k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
25.3k
      if (machine == bfd_mach_arm_unknown)
2197
25.3k
  {
2198
25.3k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
25.3k
      {
2200
3.33k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
4.83k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
1.88k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
10.4k
      default:
2204
10.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
1.40k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
1.16k
      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
1.75k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
25.3k
      }
2214
25.3k
  }
2215
25.3k
      break;
2216
25.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
25.3k
    default:      /* Unreadable input file type.  */
2416
914
      arch = bfd_arch_obscure;
2417
914
      break;
2418
26.2k
    }
2419
2420
26.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
26.2k
  return true;
2422
26.2k
}
pe-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2154
67.8k
{
2155
67.8k
  unsigned long machine;
2156
67.8k
  enum bfd_architecture arch;
2157
67.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
67.8k
  machine = 0;
2161
67.8k
  switch (internal_f->f_magic)
2162
67.8k
    {
2163
0
#ifdef I386MAGIC
2164
50.3k
    case I386MAGIC:
2165
53.8k
    case I386PTXMAGIC:
2166
56.8k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2167
66.1k
    case LYNXCOFFMAGIC:
2168
67.1k
    case I386_APPLE_MAGIC:
2169
67.1k
    case I386_FREEBSD_MAGIC:
2170
67.2k
    case I386_LINUX_MAGIC:
2171
67.8k
    case I386_NETBSD_MAGIC:
2172
67.8k
      arch = bfd_arch_i386;
2173
67.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
67.8k
    }
2419
2420
67.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
67.8k
  return true;
2422
67.8k
}
pe-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2154
62.0k
{
2155
62.0k
  unsigned long machine;
2156
62.0k
  enum bfd_architecture arch;
2157
62.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
62.0k
  machine = 0;
2161
62.0k
  switch (internal_f->f_magic)
2162
62.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
#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
62.0k
    case MCOREMAGIC:
2411
62.0k
      arch = bfd_arch_mcore;
2412
62.0k
      break;
2413
0
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
62.0k
    }
2419
2420
62.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
62.0k
  return true;
2422
62.0k
}
pe-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
47.7k
{
2155
47.7k
  unsigned long machine;
2156
47.7k
  enum bfd_architecture arch;
2157
47.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
47.7k
  machine = 0;
2161
47.7k
  switch (internal_f->f_magic)
2162
47.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
#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
37.2k
    case SH_ARCH_MAGIC_BIG:
2347
38.0k
    case SH_ARCH_MAGIC_LITTLE:
2348
38.0k
#ifdef COFF_WITH_PE
2349
47.7k
    case SH_ARCH_MAGIC_WINCE:
2350
47.7k
#endif
2351
47.7k
      arch = bfd_arch_sh;
2352
47.7k
      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
47.7k
    }
2419
2420
47.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
47.7k
  return true;
2422
47.7k
}
pei-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2154
83.7k
{
2155
83.7k
  unsigned long machine;
2156
83.7k
  enum bfd_architecture arch;
2157
83.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
83.7k
  machine = 0;
2161
83.7k
  switch (internal_f->f_magic)
2162
83.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
0
#ifdef ARMMAGIC
2191
68.2k
    case ARMMAGIC:
2192
70.2k
    case ARMPEMAGIC:
2193
78.0k
    case THUMBPEMAGIC:
2194
78.0k
      arch = bfd_arch_arm;
2195
78.0k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
78.0k
      if (machine == bfd_mach_arm_unknown)
2197
78.0k
  {
2198
78.0k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
78.0k
      {
2200
2.73k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
4.01k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
8.01k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
36.6k
      default:
2204
38.3k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
5.45k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
6.20k
      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
13.3k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
78.0k
      }
2214
78.0k
  }
2215
78.0k
      break;
2216
78.0k
#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
78.0k
    default:      /* Unreadable input file type.  */
2416
5.67k
      arch = bfd_arch_obscure;
2417
5.67k
      break;
2418
83.7k
    }
2419
2420
83.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
83.7k
  return true;
2422
83.7k
}
pei-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2154
121k
{
2155
121k
  unsigned long machine;
2156
121k
  enum bfd_architecture arch;
2157
121k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
121k
  machine = 0;
2161
121k
  switch (internal_f->f_magic)
2162
121k
    {
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
87.3k
    case ARMMAGIC:
2192
101k
    case ARMPEMAGIC:
2193
112k
    case THUMBPEMAGIC:
2194
112k
      arch = bfd_arch_arm;
2195
112k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2196
112k
      if (machine == bfd_mach_arm_unknown)
2197
112k
  {
2198
112k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2199
112k
      {
2200
4.57k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2201
5.84k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2202
8.82k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2203
60.1k
      default:
2204
65.4k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2205
6.70k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2206
5.74k
      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
15.6k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2213
112k
      }
2214
112k
  }
2215
112k
      break;
2216
112k
#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
112k
    default:      /* Unreadable input file type.  */
2416
8.50k
      arch = bfd_arch_obscure;
2417
8.50k
      break;
2418
121k
    }
2419
2420
121k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
121k
  return true;
2422
121k
}
pei-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2154
71.1k
{
2155
71.1k
  unsigned long machine;
2156
71.1k
  enum bfd_architecture arch;
2157
71.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
71.1k
  machine = 0;
2161
71.1k
  switch (internal_f->f_magic)
2162
71.1k
    {
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
71.1k
    case MCOREMAGIC:
2411
71.1k
      arch = bfd_arch_mcore;
2412
71.1k
      break;
2413
0
#endif
2414
2415
0
    default:      /* Unreadable input file type.  */
2416
0
      arch = bfd_arch_obscure;
2417
0
      break;
2418
71.1k
    }
2419
2420
71.1k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
71.1k
  return true;
2422
71.1k
}
pei-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2154
80.0k
{
2155
80.0k
  unsigned long machine;
2156
80.0k
  enum bfd_architecture arch;
2157
80.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2158
2159
  /* Zero selects the default machine for an arch.  */
2160
80.0k
  machine = 0;
2161
80.0k
  switch (internal_f->f_magic)
2162
80.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
50.5k
    case SH_ARCH_MAGIC_BIG:
2347
62.5k
    case SH_ARCH_MAGIC_LITTLE:
2348
62.5k
#ifdef COFF_WITH_PE
2349
80.0k
    case SH_ARCH_MAGIC_WINCE:
2350
80.0k
#endif
2351
80.0k
      arch = bfd_arch_sh;
2352
80.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
80.0k
    }
2419
2420
80.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2421
80.0k
  return true;
2422
80.0k
}
2423
2424
static bool
2425
symname_in_debug_hook (bfd *abfd ATTRIBUTE_UNUSED,
2426
           struct internal_syment *sym ATTRIBUTE_UNUSED)
2427
1.22M
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
103k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
1.22M
}
pei-i386.c:symname_in_debug_hook
Line
Count
Source
2427
21.5k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
21.5k
  return false;
2432
21.5k
#endif
2433
21.5k
}
pe-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
47.5k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
47.5k
  return false;
2432
47.5k
#endif
2433
47.5k
}
pei-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
33.3k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
33.3k
  return false;
2432
33.3k
#endif
2433
33.3k
}
coff-x86_64.c:symname_in_debug_hook
Line
Count
Source
2427
128k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
128k
  return false;
2432
128k
#endif
2433
128k
}
coff64-rs6000.c:symname_in_debug_hook
Line
Count
Source
2427
81.1k
{
2428
81.1k
#ifdef SYMNAME_IN_DEBUG
2429
81.1k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
81.1k
}
pe-aarch64.c:symname_in_debug_hook
Line
Count
Source
2427
58.3k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
58.3k
  return false;
2432
58.3k
#endif
2433
58.3k
}
pei-aarch64.c:symname_in_debug_hook
Line
Count
Source
2427
34.9k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
34.9k
  return false;
2432
34.9k
#endif
2433
34.9k
}
pei-ia64.c:symname_in_debug_hook
Line
Count
Source
2427
71.3k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
71.3k
  return false;
2432
71.3k
#endif
2433
71.3k
}
pei-loongarch64.c:symname_in_debug_hook
Line
Count
Source
2427
53.6k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
53.6k
  return false;
2432
53.6k
#endif
2433
53.6k
}
pei-riscv64.c:symname_in_debug_hook
Line
Count
Source
2427
66.2k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
66.2k
  return false;
2432
66.2k
#endif
2433
66.2k
}
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
22.8k
{
2428
22.8k
#ifdef SYMNAME_IN_DEBUG
2429
22.8k
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
  return false;
2432
#endif
2433
22.8k
}
coff-sh.c:symname_in_debug_hook
Line
Count
Source
2427
61.4k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
61.4k
  return false;
2432
61.4k
#endif
2433
61.4k
}
Unexecuted instantiation: coff-stgo32.c:symname_in_debug_hook
coff-tic30.c:symname_in_debug_hook
Line
Count
Source
2427
32.0k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
32.0k
  return false;
2432
32.0k
#endif
2433
32.0k
}
Unexecuted instantiation: coff-tic4x.c:symname_in_debug_hook
coff-tic54x.c:symname_in_debug_hook
Line
Count
Source
2427
78.0k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
78.0k
  return false;
2432
78.0k
#endif
2433
78.0k
}
coff-z80.c:symname_in_debug_hook
Line
Count
Source
2427
29.9k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
29.9k
  return false;
2432
29.9k
#endif
2433
29.9k
}
coff-z8k.c:symname_in_debug_hook
Line
Count
Source
2427
67.0k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
67.0k
  return false;
2432
67.0k
#endif
2433
67.0k
}
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
58.7k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
58.7k
  return false;
2432
58.7k
#endif
2433
58.7k
}
pe-mcore.c:symname_in_debug_hook
Line
Count
Source
2427
72.7k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
72.7k
  return false;
2432
72.7k
#endif
2433
72.7k
}
pe-sh.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-wince.c:symname_in_debug_hook
Line
Count
Source
2427
25.7k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
25.7k
  return false;
2432
25.7k
#endif
2433
25.7k
}
pei-arm.c:symname_in_debug_hook
Line
Count
Source
2427
50.8k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
50.8k
  return false;
2432
50.8k
#endif
2433
50.8k
}
pei-mcore.c:symname_in_debug_hook
Line
Count
Source
2427
26.0k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
26.0k
  return false;
2432
26.0k
#endif
2433
26.0k
}
pei-sh.c:symname_in_debug_hook
Line
Count
Source
2427
49.6k
{
2428
#ifdef SYMNAME_IN_DEBUG
2429
  return SYMNAME_IN_DEBUG (sym) != 0;
2430
#else
2431
49.6k
  return false;
2432
49.6k
#endif
2433
49.6k
}
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
5.14M
{
2450
5.14M
  BFD_ASSERT (symbol->is_sym);
2451
5.14M
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
5.14M
  if (CSECT_SYM_P (n_sclass)
2454
5.14M
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
22.7k
    {
2456
22.7k
      BFD_ASSERT (! aux->is_sym);
2457
22.7k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
22.7k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2459
122
  {
2460
122
    aux->u.auxent.x_csect.x_scnlen.p =
2461
122
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2462
122
    aux->fix_scnlen = 1;
2463
122
  }
2464
2465
      /* Return TRUE to indicate that the caller should not do any
2466
   further work on this auxent.  */
2467
22.7k
      return true;
2468
22.7k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
5.11M
  return false;
2473
5.14M
}
coff64-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2449
604k
{
2450
604k
  BFD_ASSERT (symbol->is_sym);
2451
604k
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
604k
  if (CSECT_SYM_P (n_sclass)
2454
604k
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
1.01k
    {
2456
1.01k
      BFD_ASSERT (! aux->is_sym);
2457
1.01k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
1.01k
    && 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.01k
      return true;
2468
1.01k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
603k
  return false;
2473
604k
}
coff-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2449
4.53M
{
2450
4.53M
  BFD_ASSERT (symbol->is_sym);
2451
4.53M
  int n_sclass = symbol->u.syment.n_sclass;
2452
2453
4.53M
  if (CSECT_SYM_P (n_sclass)
2454
4.53M
      && indaux + 1 == symbol->u.syment.n_numaux)
2455
21.7k
    {
2456
21.7k
      BFD_ASSERT (! aux->is_sym);
2457
21.7k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2458
21.7k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2459
122
  {
2460
122
    aux->u.auxent.x_csect.x_scnlen.p =
2461
122
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2462
122
    aux->fix_scnlen = 1;
2463
122
  }
2464
2465
      /* Return TRUE to indicate that the caller should not do any
2466
   further work on this auxent.  */
2467
21.7k
      return true;
2468
21.7k
    }
2469
2470
  /* Return FALSE to indicate that this auxent should be handled by
2471
     the caller.  */
2472
4.51M
  return false;
2473
4.53M
}
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
4
{
2566
4
  asection *s;
2567
2568
42
  for (s = abfd->sections; s != NULL; s = s->next)
2569
38
    {
2570
38
      unsigned int i;
2571
38
      struct external_reloc dst;
2572
38
      arelent **p;
2573
2574
38
#ifndef TARG_AUX
2575
38
      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
38
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
38
      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
38
#endif
2615
2616
38
      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
38
    }
2712
2713
4
  return true;
2714
4
}
pei-i386.c:coff_write_relocs
Line
Count
Source
2565
1
{
2566
1
  asection *s;
2567
2568
10
  for (s = abfd->sections; s != NULL; s = s->next)
2569
9
    {
2570
9
      unsigned int i;
2571
9
      struct external_reloc dst;
2572
9
      arelent **p;
2573
2574
9
#ifndef TARG_AUX
2575
9
      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
9
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
9
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
9
      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
9
#endif
2615
2616
9
      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
9
    }
2712
2713
1
  return true;
2714
1
}
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
}
Unexecuted instantiation: coff-x86_64.c:coff_write_relocs
Unexecuted instantiation: coff64-rs6000.c:coff_write_relocs
Unexecuted instantiation: pe-aarch64.c:coff_write_relocs
Unexecuted instantiation: pei-aarch64.c:coff_write_relocs
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
2
{
2566
2
  asection *s;
2567
2568
10
  for (s = abfd->sections; s != NULL; s = s->next)
2569
8
    {
2570
8
      unsigned int i;
2571
8
      struct external_reloc dst;
2572
8
      arelent **p;
2573
2574
8
#ifndef TARG_AUX
2575
8
      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
8
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2598
0
  return false;
2599
2600
8
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2601
8
      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
8
#endif
2615
2616
8
      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
8
    }
2712
2713
2
  return true;
2714
2
}
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
1.52k
{
2724
1.52k
  switch (bfd_get_arch (abfd))
2725
1.52k
    {
2726
#ifdef Z80MAGIC
2727
48
    case bfd_arch_z80:
2728
48
      *magicp = Z80MAGIC;
2729
48
      switch (bfd_get_mach (abfd))
2730
48
  {
2731
2
  case bfd_mach_z80strict:
2732
2
  case bfd_mach_z80:
2733
17
  case bfd_mach_z80n:
2734
17
  case bfd_mach_z80full:
2735
17
  case bfd_mach_r800:
2736
17
  case bfd_mach_gbz80:
2737
17
  case bfd_mach_z180:
2738
47
  case bfd_mach_ez80_z80:
2739
48
  case bfd_mach_ez80_adl:
2740
48
    *flagsp = bfd_get_mach (abfd) << 12;
2741
48
    break;
2742
0
  default:
2743
0
    return false;
2744
48
  }
2745
48
      return true;
2746
0
#endif
2747
2748
#ifdef Z8KMAGIC
2749
82
    case bfd_arch_z8k:
2750
82
      *magicp = Z8KMAGIC;
2751
2752
82
      switch (bfd_get_mach (abfd))
2753
82
  {
2754
60
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
22
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
0
  default:       return false;
2757
82
  }
2758
82
      return true;
2759
0
#endif
2760
2761
#ifdef TIC30MAGIC
2762
76
    case bfd_arch_tic30:
2763
76
      *magicp = TIC30MAGIC;
2764
76
      return true;
2765
0
#endif
2766
2767
#ifdef TICOFF_DEFAULT_MAGIC
2768
62
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
62
      if (!abfd->xvec )
2771
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
62
      else
2773
62
  {
2774
    /* We may want to output in a different COFF version.  */
2775
62
    switch (abfd->xvec->name[4])
2776
62
      {
2777
62
      case '0':
2778
62
        *magicp = TICOFF0MAGIC;
2779
62
        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
62
      }
2789
62
  }
2790
62
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
62
      return true;
2792
0
#endif
2793
2794
#ifdef AARCH64MAGIC
2795
135
    case bfd_arch_aarch64:
2796
135
      * magicp = AARCH64MAGIC;
2797
135
      return true;
2798
0
#endif
2799
2800
#ifdef LOONGARCH64MAGIC
2801
65
    case bfd_arch_loongarch:
2802
65
      * magicp = LOONGARCH64MAGIC;
2803
65
      return true;
2804
0
#endif
2805
2806
#ifdef RISCV64MAGIC
2807
43
    case bfd_arch_riscv:
2808
43
      * magicp = RISCV64MAGIC;
2809
43
      return true;
2810
0
#endif
2811
2812
#ifdef ARMMAGIC
2813
122
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
122
      * magicp = ARMMAGIC;
2818
122
#endif
2819
122
      * flagsp = 0;
2820
122
      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
122
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
122
      switch (bfd_get_mach (abfd))
2834
122
  {
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
120
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
1
  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
1
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
122
  }
2848
122
      return true;
2849
0
#endif
2850
2851
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2852
416
    case bfd_arch_i386:
2853
#if defined(I386MAGIC)
2854
150
      *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
266
      *magicp = AMD64MAGIC;
2862
#endif
2863
416
      return true;
2864
0
#endif
2865
2866
#ifdef IA64MAGIC
2867
63
    case bfd_arch_ia64:
2868
63
      *magicp = IA64MAGIC;
2869
63
      return true;
2870
0
#endif
2871
2872
#ifdef SH_ARCH_MAGIC_BIG
2873
213
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
67
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
146
      if (bfd_big_endian (abfd))
2878
2
  *magicp = SH_ARCH_MAGIC_BIG;
2879
144
      else
2880
144
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
#endif
2882
213
      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
77
    case bfd_arch_rs6000:
2903
125
    case bfd_arch_powerpc:
2904
125
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
125
      *magicp = bfd_xcoff_magic_number (abfd);
2906
125
      return true;
2907
0
#endif
2908
2909
#ifdef MCOREMAGIC
2910
75
    case bfd_arch_mcore:
2911
75
      * magicp = MCOREMAGIC;
2912
75
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
1.52k
    }
2918
2919
0
  return false;
2920
1.52k
}
pei-i386.c:coff_set_flags
Line
Count
Source
2723
74
{
2724
74
  switch (bfd_get_arch (abfd))
2725
74
    {
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
74
    case bfd_arch_i386:
2853
74
#if defined(I386MAGIC)
2854
74
      *magicp = I386MAGIC;
2855
74
#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
74
      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
74
    }
2918
2919
0
  return false;
2920
74
}
pe-x86_64.c:coff_set_flags
Line
Count
Source
2723
61
{
2724
61
  switch (bfd_get_arch (abfd))
2725
61
    {
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
61
    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
61
#if defined AMD64MAGIC
2861
61
      *magicp = AMD64MAGIC;
2862
61
#endif
2863
61
      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
61
    }
2918
2919
0
  return false;
2920
61
}
pei-x86_64.c:coff_set_flags
Line
Count
Source
2723
91
{
2724
91
  switch (bfd_get_arch (abfd))
2725
91
    {
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
91
    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
91
#if defined AMD64MAGIC
2861
91
      *magicp = AMD64MAGIC;
2862
91
#endif
2863
91
      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
91
    }
2918
2919
0
  return false;
2920
91
}
coff-x86_64.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
#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
114
    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
114
#if defined AMD64MAGIC
2861
114
      *magicp = AMD64MAGIC;
2862
114
#endif
2863
114
      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
114
    }
2918
2919
0
  return false;
2920
114
}
coff64-rs6000.c:coff_set_flags
Line
Count
Source
2723
48
{
2724
48
  switch (bfd_get_arch (abfd))
2725
48
    {
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
48
    case bfd_arch_powerpc:
2904
48
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2905
48
      *magicp = bfd_xcoff_magic_number (abfd);
2906
48
      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
48
    }
2918
2919
0
  return false;
2920
48
}
pe-aarch64.c:coff_set_flags
Line
Count
Source
2723
55
{
2724
55
  switch (bfd_get_arch (abfd))
2725
55
    {
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
55
    case bfd_arch_aarch64:
2796
55
      * magicp = AARCH64MAGIC;
2797
55
      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
55
    }
2918
2919
0
  return false;
2920
55
}
pei-aarch64.c:coff_set_flags
Line
Count
Source
2723
80
{
2724
80
  switch (bfd_get_arch (abfd))
2725
80
    {
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
80
    case bfd_arch_aarch64:
2796
80
      * magicp = AARCH64MAGIC;
2797
80
      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
80
    }
2918
2919
0
  return false;
2920
80
}
pei-ia64.c:coff_set_flags
Line
Count
Source
2723
63
{
2724
63
  switch (bfd_get_arch (abfd))
2725
63
    {
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
63
    case bfd_arch_ia64:
2868
63
      *magicp = IA64MAGIC;
2869
63
      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
63
    }
2918
2919
0
  return false;
2920
63
}
pei-loongarch64.c:coff_set_flags
Line
Count
Source
2723
65
{
2724
65
  switch (bfd_get_arch (abfd))
2725
65
    {
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
65
    case bfd_arch_loongarch:
2802
65
      * magicp = LOONGARCH64MAGIC;
2803
65
      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
65
    }
2918
2919
0
  return false;
2920
65
}
pei-riscv64.c:coff_set_flags
Line
Count
Source
2723
43
{
2724
43
  switch (bfd_get_arch (abfd))
2725
43
    {
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
43
    case bfd_arch_riscv:
2808
43
      * magicp = RISCV64MAGIC;
2809
43
      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
43
    }
2918
2919
0
  return false;
2920
43
}
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
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
77
    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
}
coff-sh.c:coff_set_flags
Line
Count
Source
2723
88
{
2724
88
  switch (bfd_get_arch (abfd))
2725
88
    {
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
88
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
88
      if (bfd_big_endian (abfd))
2878
2
  *magicp = SH_ARCH_MAGIC_BIG;
2879
86
      else
2880
86
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
88
#endif
2882
88
      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
88
    }
2918
2919
0
  return false;
2920
88
}
Unexecuted instantiation: coff-stgo32.c:coff_set_flags
coff-tic30.c:coff_set_flags
Line
Count
Source
2723
76
{
2724
76
  switch (bfd_get_arch (abfd))
2725
76
    {
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
76
    case bfd_arch_tic30:
2763
76
      *magicp = TIC30MAGIC;
2764
76
      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
76
    }
2918
2919
0
  return false;
2920
76
}
Unexecuted instantiation: coff-tic4x.c:coff_set_flags
coff-tic54x.c:coff_set_flags
Line
Count
Source
2723
62
{
2724
62
  switch (bfd_get_arch (abfd))
2725
62
    {
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
62
    case TICOFF_TARGET_ARCH:
2769
      /* If there's no indication of which version we want, use the default.  */
2770
62
      if (!abfd->xvec )
2771
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2772
62
      else
2773
62
  {
2774
    /* We may want to output in a different COFF version.  */
2775
62
    switch (abfd->xvec->name[4])
2776
62
      {
2777
62
      case '0':
2778
62
        *magicp = TICOFF0MAGIC;
2779
62
        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
62
      }
2789
62
  }
2790
62
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2791
62
      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
62
    }
2918
2919
0
  return false;
2920
62
}
coff-z80.c:coff_set_flags
Line
Count
Source
2723
48
{
2724
48
  switch (bfd_get_arch (abfd))
2725
48
    {
2726
0
#ifdef Z80MAGIC
2727
48
    case bfd_arch_z80:
2728
48
      *magicp = Z80MAGIC;
2729
48
      switch (bfd_get_mach (abfd))
2730
48
  {
2731
2
  case bfd_mach_z80strict:
2732
2
  case bfd_mach_z80:
2733
17
  case bfd_mach_z80n:
2734
17
  case bfd_mach_z80full:
2735
17
  case bfd_mach_r800:
2736
17
  case bfd_mach_gbz80:
2737
17
  case bfd_mach_z180:
2738
47
  case bfd_mach_ez80_z80:
2739
48
  case bfd_mach_ez80_adl:
2740
48
    *flagsp = bfd_get_mach (abfd) << 12;
2741
48
    break;
2742
0
  default:
2743
0
    return false;
2744
48
  }
2745
48
      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
48
    }
2918
2919
0
  return false;
2920
48
}
coff-z8k.c:coff_set_flags
Line
Count
Source
2723
82
{
2724
82
  switch (bfd_get_arch (abfd))
2725
82
    {
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
82
    case bfd_arch_z8k:
2750
82
      *magicp = Z8KMAGIC;
2751
2752
82
      switch (bfd_get_mach (abfd))
2753
82
  {
2754
60
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2755
22
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2756
0
  default:       return false;
2757
82
  }
2758
82
      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
82
    }
2918
2919
0
  return false;
2920
82
}
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
76
{
2724
76
  switch (bfd_get_arch (abfd))
2725
76
    {
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
76
    case bfd_arch_i386:
2853
76
#if defined(I386MAGIC)
2854
76
      *magicp = I386MAGIC;
2855
76
#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
76
      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
76
    }
2918
2919
0
  return false;
2920
76
}
pe-mcore.c:coff_set_flags
Line
Count
Source
2723
58
{
2724
58
  switch (bfd_get_arch (abfd))
2725
58
    {
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
58
    case bfd_arch_mcore:
2911
58
      * magicp = MCOREMAGIC;
2912
58
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
58
    }
2918
2919
0
  return false;
2920
58
}
pe-sh.c:coff_set_flags
Line
Count
Source
2723
58
{
2724
58
  switch (bfd_get_arch (abfd))
2725
58
    {
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
58
    case bfd_arch_sh:
2874
#ifdef COFF_IMAGE_WITH_PE
2875
      *magicp = SH_ARCH_MAGIC_WINCE;
2876
#else
2877
58
      if (bfd_big_endian (abfd))
2878
0
  *magicp = SH_ARCH_MAGIC_BIG;
2879
58
      else
2880
58
  *magicp = SH_ARCH_MAGIC_LITTLE;
2881
58
#endif
2882
58
      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
58
    }
2918
2919
0
  return false;
2920
58
}
pei-arm-wince.c:coff_set_flags
Line
Count
Source
2723
48
{
2724
48
  switch (bfd_get_arch (abfd))
2725
48
    {
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
48
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
48
      * magicp = ARMMAGIC;
2818
48
#endif
2819
48
      * flagsp = 0;
2820
48
      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
48
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
48
      switch (bfd_get_mach (abfd))
2834
48
  {
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
48
  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
48
  }
2848
48
      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
48
    }
2918
2919
0
  return false;
2920
48
}
pei-arm.c:coff_set_flags
Line
Count
Source
2723
74
{
2724
74
  switch (bfd_get_arch (abfd))
2725
74
    {
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
74
    case bfd_arch_arm:
2814
#ifdef ARM_WINCE
2815
      * magicp = ARMPEMAGIC;
2816
#else
2817
74
      * magicp = ARMMAGIC;
2818
74
#endif
2819
74
      * flagsp = 0;
2820
74
      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
74
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2832
0
  * flagsp |= F_INTERWORK;
2833
74
      switch (bfd_get_mach (abfd))
2834
74
  {
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
72
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2839
1
  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
1
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2847
74
  }
2848
74
      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
74
    }
2918
2919
0
  return false;
2920
74
}
pei-mcore.c:coff_set_flags
Line
Count
Source
2723
17
{
2724
17
  switch (bfd_get_arch (abfd))
2725
17
    {
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
17
    case bfd_arch_mcore:
2911
17
      * magicp = MCOREMAGIC;
2912
17
      return true;
2913
0
#endif
2914
2915
0
    default:      /* Unknown architecture.  */
2916
0
      break;
2917
17
    }
2918
2919
0
  return false;
2920
17
}
pei-sh.c:coff_set_flags
Line
Count
Source
2723
67
{
2724
67
  switch (bfd_get_arch (abfd))
2725
67
    {
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
67
    case bfd_arch_sh:
2874
67
#ifdef COFF_IMAGE_WITH_PE
2875
67
      *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
67
      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
67
    }
2918
2919
0
  return false;
2920
67
}
2921
2922
static bool
2923
coff_set_arch_mach (bfd * abfd,
2924
        enum bfd_architecture arch,
2925
        unsigned long machine)
2926
1.51k
{
2927
1.51k
  unsigned dummy1;
2928
1.51k
  unsigned short dummy2;
2929
2930
1.51k
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
24
    return false;
2932
2933
1.49k
  if (arch != bfd_arch_unknown
2934
1.49k
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
1.49k
  return true;     /* We're easy...  */
2938
1.49k
}
pei-i386.c:coff_set_arch_mach
Line
Count
Source
2926
63
{
2927
63
  unsigned dummy1;
2928
63
  unsigned short dummy2;
2929
2930
63
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
63
  if (arch != bfd_arch_unknown
2934
63
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
63
  return true;     /* We're easy...  */
2938
63
}
pe-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
61
{
2927
61
  unsigned dummy1;
2928
61
  unsigned short dummy2;
2929
2930
61
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
61
  if (arch != bfd_arch_unknown
2934
61
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
61
  return true;     /* We're easy...  */
2938
61
}
pei-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
83
{
2927
83
  unsigned dummy1;
2928
83
  unsigned short dummy2;
2929
2930
83
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
83
  if (arch != bfd_arch_unknown
2934
83
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
83
  return true;     /* We're easy...  */
2938
83
}
coff-x86_64.c:coff_set_arch_mach
Line
Count
Source
2926
112
{
2927
112
  unsigned dummy1;
2928
112
  unsigned short dummy2;
2929
2930
112
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
112
  if (arch != bfd_arch_unknown
2934
112
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
112
  return true;     /* We're easy...  */
2938
112
}
coff64-rs6000.c:coff_set_arch_mach
Line
Count
Source
2926
48
{
2927
48
  unsigned dummy1;
2928
48
  unsigned short dummy2;
2929
2930
48
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
48
  if (arch != bfd_arch_unknown
2934
48
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
48
  return true;     /* We're easy...  */
2938
48
}
pe-aarch64.c:coff_set_arch_mach
Line
Count
Source
2926
55
{
2927
55
  unsigned dummy1;
2928
55
  unsigned short dummy2;
2929
2930
55
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
55
  if (arch != bfd_arch_unknown
2934
55
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
55
  return true;     /* We're easy...  */
2938
55
}
pei-aarch64.c:coff_set_arch_mach
Line
Count
Source
2926
80
{
2927
80
  unsigned dummy1;
2928
80
  unsigned short dummy2;
2929
2930
80
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
80
  if (arch != bfd_arch_unknown
2934
80
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
80
  return true;     /* We're easy...  */
2938
80
}
pei-ia64.c:coff_set_arch_mach
Line
Count
Source
2926
62
{
2927
62
  unsigned dummy1;
2928
62
  unsigned short dummy2;
2929
2930
62
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
62
  if (arch != bfd_arch_unknown
2934
62
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
62
  return true;     /* We're easy...  */
2938
62
}
pei-loongarch64.c:coff_set_arch_mach
Line
Count
Source
2926
64
{
2927
64
  unsigned dummy1;
2928
64
  unsigned short dummy2;
2929
2930
64
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
64
  if (arch != bfd_arch_unknown
2934
64
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
64
  return true;     /* We're easy...  */
2938
64
}
pei-riscv64.c:coff_set_arch_mach
Line
Count
Source
2926
37
{
2927
37
  unsigned dummy1;
2928
37
  unsigned short dummy2;
2929
2930
37
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
37
  if (arch != bfd_arch_unknown
2934
37
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
37
  return true;     /* We're easy...  */
2938
37
}
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
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
}
coff-sh.c:coff_set_arch_mach
Line
Count
Source
2926
110
{
2927
110
  unsigned dummy1;
2928
110
  unsigned short dummy2;
2929
2930
110
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
22
    return false;
2932
2933
88
  if (arch != bfd_arch_unknown
2934
88
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
88
  return true;     /* We're easy...  */
2938
88
}
Unexecuted instantiation: coff-stgo32.c:coff_set_arch_mach
coff-tic30.c:coff_set_arch_mach
Line
Count
Source
2926
76
{
2927
76
  unsigned dummy1;
2928
76
  unsigned short dummy2;
2929
2930
76
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
76
  if (arch != bfd_arch_unknown
2934
76
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
76
  return true;     /* We're easy...  */
2938
76
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach
coff-tic54x.c:coff_set_arch_mach
Line
Count
Source
2926
62
{
2927
62
  unsigned dummy1;
2928
62
  unsigned short dummy2;
2929
2930
62
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
62
  if (arch != bfd_arch_unknown
2934
62
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
62
  return true;     /* We're easy...  */
2938
62
}
coff-z80.c:coff_set_arch_mach
Line
Count
Source
2926
48
{
2927
48
  unsigned dummy1;
2928
48
  unsigned short dummy2;
2929
2930
48
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
48
  if (arch != bfd_arch_unknown
2934
48
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
48
  return true;     /* We're easy...  */
2938
48
}
coff-z8k.c:coff_set_arch_mach
Line
Count
Source
2926
82
{
2927
82
  unsigned dummy1;
2928
82
  unsigned short dummy2;
2929
2930
82
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
82
  if (arch != bfd_arch_unknown
2934
82
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
82
  return true;     /* We're easy...  */
2938
82
}
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
76
{
2927
76
  unsigned dummy1;
2928
76
  unsigned short dummy2;
2929
2930
76
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
76
  if (arch != bfd_arch_unknown
2934
76
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
76
  return true;     /* We're easy...  */
2938
76
}
pe-mcore.c:coff_set_arch_mach
Line
Count
Source
2926
58
{
2927
58
  unsigned dummy1;
2928
58
  unsigned short dummy2;
2929
2930
58
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
58
  if (arch != bfd_arch_unknown
2934
58
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
58
  return true;     /* We're easy...  */
2938
58
}
pe-sh.c:coff_set_arch_mach
Line
Count
Source
2926
58
{
2927
58
  unsigned dummy1;
2928
58
  unsigned short dummy2;
2929
2930
58
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
58
  if (arch != bfd_arch_unknown
2934
58
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
58
  return true;     /* We're easy...  */
2938
58
}
pei-arm-wince.c:coff_set_arch_mach
Line
Count
Source
2926
47
{
2927
47
  unsigned dummy1;
2928
47
  unsigned short dummy2;
2929
2930
47
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
47
  if (arch != bfd_arch_unknown
2934
47
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
47
  return true;     /* We're easy...  */
2938
47
}
pei-arm.c:coff_set_arch_mach
Line
Count
Source
2926
76
{
2927
76
  unsigned dummy1;
2928
76
  unsigned short dummy2;
2929
2930
76
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
2
    return false;
2932
2933
74
  if (arch != bfd_arch_unknown
2934
74
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
74
  return true;     /* We're easy...  */
2938
74
}
pei-mcore.c:coff_set_arch_mach
Line
Count
Source
2926
17
{
2927
17
  unsigned dummy1;
2928
17
  unsigned short dummy2;
2929
2930
17
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
17
  if (arch != bfd_arch_unknown
2934
17
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
17
  return true;     /* We're easy...  */
2938
17
}
pei-sh.c:coff_set_arch_mach
Line
Count
Source
2926
66
{
2927
66
  unsigned dummy1;
2928
66
  unsigned short dummy2;
2929
2930
66
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2931
0
    return false;
2932
2933
66
  if (arch != bfd_arch_unknown
2934
66
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2935
0
    return false;   /* We can't represent this type.  */
2936
2937
66
  return true;     /* We're easy...  */
2938
66
}
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
158
{
2948
158
  const asection *a = *(const asection **) arg1;
2949
158
  const asection *b = *(const asection **) arg2;
2950
2951
158
  if (a->vma < b->vma)
2952
110
    return -1;
2953
48
  else if (a->vma > b->vma)
2954
21
    return 1;
2955
2956
27
  return 0;
2957
158
}
pei-i386.c:sort_by_secaddr
Line
Count
Source
2947
69
{
2948
69
  const asection *a = *(const asection **) arg1;
2949
69
  const asection *b = *(const asection **) arg2;
2950
2951
69
  if (a->vma < b->vma)
2952
54
    return -1;
2953
15
  else if (a->vma > b->vma)
2954
2
    return 1;
2955
2956
13
  return 0;
2957
69
}
pei-x86_64.c:sort_by_secaddr
Line
Count
Source
2947
76
{
2948
76
  const asection *a = *(const asection **) arg1;
2949
76
  const asection *b = *(const asection **) arg2;
2950
2951
76
  if (a->vma < b->vma)
2952
56
    return -1;
2953
20
  else if (a->vma > b->vma)
2954
19
    return 1;
2955
2956
1
  return 0;
2957
76
}
Unexecuted instantiation: pei-aarch64.c:sort_by_secaddr
Unexecuted instantiation: pei-ia64.c:sort_by_secaddr
pei-loongarch64.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
}
pei-riscv64.c:sort_by_secaddr
Line
Count
Source
2947
11
{
2948
11
  const asection *a = *(const asection **) arg1;
2949
11
  const asection *b = *(const asection **) arg2;
2950
2951
11
  if (a->vma < b->vma)
2952
0
    return -1;
2953
11
  else if (a->vma > b->vma)
2954
0
    return 1;
2955
2956
11
  return 0;
2957
11
}
pei-arm-wince.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-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
35
{
2971
35
  asection *current;
2972
35
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
35
  bool align_adjust;
2974
35
  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
33
  if (coff_data (abfd)->link_info
2984
33
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
32
    {
2986
32
      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
32
      if (page_size == 0)
2991
0
  page_size = 1;
2992
32
    }
2993
1
  else
2994
1
    page_size = PE_DEF_FILE_ALIGNMENT;
2995
#else
2996
#ifdef COFF_PAGE_SIZE
2997
2
  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
35
  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
14
    abfd->flags |= EXEC_P;
3045
3046
35
  if (abfd->flags & EXEC_P)
3047
30
    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
35
  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
35
  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
27
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
27
       || page_size < COFF_PAGE_SIZE)
3086
25
     abfd->flags &= ~D_PAGED;
3087
#endif
3088
3089
    count = 0;
3090
143
    for (current = abfd->sections; current != NULL; current = current->next)
3091
110
      ++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
33
    if (section_list == NULL)
3097
0
      return false;
3098
3099
33
    i = 0;
3100
143
    for (current = abfd->sections; current != NULL; current = current->next)
3101
110
      {
3102
110
  section_list[i] = current;
3103
110
  ++i;
3104
110
      }
3105
33
    section_list[i] = NULL;
3106
3107
33
    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
33
    target_index = 1;
3112
33
    abfd->sections = NULL;
3113
33
    abfd->section_last = NULL;
3114
143
    for (i = 0; i < count; i++)
3115
110
      {
3116
110
  current = section_list[i];
3117
110
  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
110
  if (current->size == 0)
3125
18
    {
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
18
      current->target_index = 1;
3132
18
    }
3133
92
  else
3134
92
    current->target_index = target_index++;
3135
110
      }
3136
3137
33
    free (section_list);
3138
33
  }
3139
#else /* ! COFF_IMAGE_WITH_PE */
3140
  {
3141
    /* Set the target_index field.  */
3142
    target_index = 1;
3143
5
    for (current = abfd->sections; current != NULL; current = current->next)
3144
3
      current->target_index = target_index++;
3145
  }
3146
#endif /* ! COFF_IMAGE_WITH_PE */
3147
3148
35
  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
35
  align_adjust = false;
3158
35
  for (current = abfd->sections;
3159
148
       current != NULL;
3160
113
       current = current->next)
3161
113
    {
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
110
      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
110
      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
110
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
27
  pei_section_data (abfd, current)->virt_size = current->size;
3183
110
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
113
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
21
  continue;
3188
3189
92
      current->rawsize = current->size;
3190
3191
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
89
      if (current->size == 0)
3194
1
  continue;
3195
88
#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
91
      if ((abfd->flags & EXEC_P) != 0)
3201
86
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
86
    old_sofar = sofar;
3205
3206
#ifdef COFF_IMAGE_WITH_PE
3207
86
    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
86
    if (previous != NULL
3251
86
        && (previous->flags & SEC_LOAD) != 0)
3252
55
      previous->size += sofar - old_sofar;
3253
86
  }
3254
3255
88
#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
85
      if ((abfd->flags & D_PAGED) != 0
3261
85
    && (current->flags & SEC_ALLOC) != 0)
3262
1
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
#endif
3264
88
      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
88
      sofar += current->size;
3272
3273
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
91
      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
86
      else
3286
86
  {
3287
86
    old_sofar = sofar;
3288
#ifdef COFF_IMAGE_WITH_PE
3289
86
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
86
    align_adjust = sofar != old_sofar;
3294
86
    current->size += sofar - old_sofar;
3295
86
  }
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
88
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
74
  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
91
      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
88
    }
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
35
  if (align_adjust)
3325
14
    {
3326
14
      bfd_byte b;
3327
3328
14
      b = 0;
3329
14
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
14
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
14
    }
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
35
  sofar = BFD_ALIGN (sofar,
3338
35
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
35
  obj_relocbase (abfd) = sofar;
3341
35
  abfd->output_has_begun = true;
3342
3343
35
  return true;
3344
33
}
pei-i386.c:coff_compute_section_file_positions
Line
Count
Source
2970
14
{
2971
14
  asection *current;
2972
14
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
14
  bool align_adjust;
2974
14
  unsigned int target_index;
2975
14
#ifdef ALIGN_SECTIONS_IN_FILE
2976
14
  asection *previous = NULL;
2977
14
  file_ptr old_sofar;
2978
14
#endif
2979
2980
14
#ifdef COFF_IMAGE_WITH_PE
2981
14
  unsigned int page_size;
2982
2983
14
  if (coff_data (abfd)->link_info
2984
14
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
14
    {
2986
14
      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
14
      if (page_size == 0)
2991
0
  page_size = 1;
2992
14
    }
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
14
  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
8
    abfd->flags |= EXEC_P;
3045
3046
14
  if (abfd->flags & EXEC_P)
3047
14
    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
14
  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
14
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
14
#ifdef COFF_IMAGE_WITH_PE
3069
14
  {
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
14
    unsigned int count;
3077
14
    asection **section_list;
3078
14
    unsigned int i;
3079
14
    bfd_size_type amt;
3080
3081
14
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
14
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
14
       || page_size < COFF_PAGE_SIZE)
3086
13
     abfd->flags &= ~D_PAGED;
3087
14
#endif
3088
3089
14
    count = 0;
3090
66
    for (current = abfd->sections; current != NULL; current = current->next)
3091
52
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
14
    amt = sizeof (struct asection *) * (count + 1);
3095
14
    section_list = (asection **) bfd_malloc (amt);
3096
14
    if (section_list == NULL)
3097
0
      return false;
3098
3099
14
    i = 0;
3100
66
    for (current = abfd->sections; current != NULL; current = current->next)
3101
52
      {
3102
52
  section_list[i] = current;
3103
52
  ++i;
3104
52
      }
3105
14
    section_list[i] = NULL;
3106
3107
14
    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
14
    target_index = 1;
3112
14
    abfd->sections = NULL;
3113
14
    abfd->section_last = NULL;
3114
66
    for (i = 0; i < count; i++)
3115
52
      {
3116
52
  current = section_list[i];
3117
52
  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
52
  if (current->size == 0)
3125
9
    {
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
9
      current->target_index = 1;
3132
9
    }
3133
43
  else
3134
43
    current->target_index = target_index++;
3135
52
      }
3136
3137
14
    free (section_list);
3138
14
  }
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
14
  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
14
  align_adjust = false;
3158
14
  for (current = abfd->sections;
3159
66
       current != NULL;
3160
52
       current = current->next)
3161
52
    {
3162
52
#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
52
      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
52
      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
52
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
9
  pei_section_data (abfd, current)->virt_size = current->size;
3183
52
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
52
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
12
  continue;
3188
3189
40
      current->rawsize = current->size;
3190
3191
40
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
40
      if (current->size == 0)
3194
0
  continue;
3195
40
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
40
#ifdef ALIGN_SECTIONS_IN_FILE
3200
40
      if ((abfd->flags & EXEC_P) != 0)
3201
40
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
40
    old_sofar = sofar;
3205
3206
40
#ifdef COFF_IMAGE_WITH_PE
3207
40
    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
40
    if (previous != NULL
3251
40
        && (previous->flags & SEC_LOAD) != 0)
3252
31
      previous->size += sofar - old_sofar;
3253
40
  }
3254
3255
40
#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
40
#ifdef COFF_PAGE_SIZE
3260
40
      if ((abfd->flags & D_PAGED) != 0
3261
40
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
40
#endif
3264
40
      current->filepos = sofar;
3265
3266
40
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
40
      current->size = (current->size + page_size - 1) & -page_size;
3269
40
#endif
3270
3271
40
      sofar += current->size;
3272
3273
40
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
40
      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
40
      else
3286
40
  {
3287
40
    old_sofar = sofar;
3288
40
#ifdef COFF_IMAGE_WITH_PE
3289
40
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
40
    align_adjust = sofar != old_sofar;
3294
40
    current->size += sofar - old_sofar;
3295
40
  }
3296
40
#endif
3297
3298
40
#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
40
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
39
  align_adjust = true;
3304
40
#endif
3305
3306
40
#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
40
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
40
#endif
3313
3314
40
#ifdef ALIGN_SECTIONS_IN_FILE
3315
40
      previous = current;
3316
40
#endif
3317
40
    }
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
14
  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
14
  sofar = BFD_ALIGN (sofar,
3338
14
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
14
  obj_relocbase (abfd) = sofar;
3341
14
  abfd->output_has_begun = true;
3342
3343
14
  return true;
3344
14
}
Unexecuted instantiation: pe-x86_64.c:coff_compute_section_file_positions
pei-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2970
9
{
2971
9
  asection *current;
2972
9
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
9
  bool align_adjust;
2974
9
  unsigned int target_index;
2975
9
#ifdef ALIGN_SECTIONS_IN_FILE
2976
9
  asection *previous = NULL;
2977
9
  file_ptr old_sofar;
2978
9
#endif
2979
2980
9
#ifdef COFF_IMAGE_WITH_PE
2981
9
  unsigned int page_size;
2982
2983
9
  if (coff_data (abfd)->link_info
2984
9
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2985
9
    {
2986
9
      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
9
      if (page_size == 0)
2991
0
  page_size = 1;
2992
9
    }
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
9
  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
4
    abfd->flags |= EXEC_P;
3045
3046
9
  if (abfd->flags & EXEC_P)
3047
9
    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
9
  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
9
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
9
#ifdef COFF_IMAGE_WITH_PE
3069
9
  {
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
9
    unsigned int count;
3077
9
    asection **section_list;
3078
9
    unsigned int i;
3079
9
    bfd_size_type amt;
3080
3081
9
#ifdef COFF_PAGE_SIZE
3082
    /* Clear D_PAGED if section / file alignment aren't suitable for
3083
       paging at COFF_PAGE_SIZE granularity.  */
3084
9
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3085
9
       || page_size < COFF_PAGE_SIZE)
3086
9
     abfd->flags &= ~D_PAGED;
3087
9
#endif
3088
3089
9
    count = 0;
3090
49
    for (current = abfd->sections; current != NULL; current = current->next)
3091
40
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
9
    amt = sizeof (struct asection *) * (count + 1);
3095
9
    section_list = (asection **) bfd_malloc (amt);
3096
9
    if (section_list == NULL)
3097
0
      return false;
3098
3099
9
    i = 0;
3100
49
    for (current = abfd->sections; current != NULL; current = current->next)
3101
40
      {
3102
40
  section_list[i] = current;
3103
40
  ++i;
3104
40
      }
3105
9
    section_list[i] = NULL;
3106
3107
9
    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
9
    target_index = 1;
3112
9
    abfd->sections = NULL;
3113
9
    abfd->section_last = NULL;
3114
49
    for (i = 0; i < count; i++)
3115
40
      {
3116
40
  current = section_list[i];
3117
40
  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
40
  if (current->size == 0)
3125
1
    {
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
1
      current->target_index = 1;
3132
1
    }
3133
39
  else
3134
39
    current->target_index = target_index++;
3135
40
      }
3136
3137
9
    free (section_list);
3138
9
  }
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
9
  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
9
  align_adjust = false;
3158
9
  for (current = abfd->sections;
3159
49
       current != NULL;
3160
40
       current = current->next)
3161
40
    {
3162
40
#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
40
      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
40
      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
40
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
0
  pei_section_data (abfd, current)->virt_size = current->size;
3183
40
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
40
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
1
  continue;
3188
3189
39
      current->rawsize = current->size;
3190
3191
39
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
39
      if (current->size == 0)
3194
1
  continue;
3195
38
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
38
#ifdef ALIGN_SECTIONS_IN_FILE
3200
38
      if ((abfd->flags & EXEC_P) != 0)
3201
38
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
38
    old_sofar = sofar;
3205
3206
38
#ifdef COFF_IMAGE_WITH_PE
3207
38
    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
38
    if (previous != NULL
3251
38
        && (previous->flags & SEC_LOAD) != 0)
3252
24
      previous->size += sofar - old_sofar;
3253
38
  }
3254
3255
38
#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
38
#ifdef COFF_PAGE_SIZE
3260
38
      if ((abfd->flags & D_PAGED) != 0
3261
38
    && (current->flags & SEC_ALLOC) != 0)
3262
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3263
38
#endif
3264
38
      current->filepos = sofar;
3265
3266
38
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
38
      current->size = (current->size + page_size - 1) & -page_size;
3269
38
#endif
3270
3271
38
      sofar += current->size;
3272
3273
38
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
38
      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
38
      else
3286
38
  {
3287
38
    old_sofar = sofar;
3288
38
#ifdef COFF_IMAGE_WITH_PE
3289
38
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
38
    align_adjust = sofar != old_sofar;
3294
38
    current->size += sofar - old_sofar;
3295
38
  }
3296
38
#endif
3297
3298
38
#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
38
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
29
  align_adjust = true;
3304
38
#endif
3305
3306
38
#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
38
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
38
#endif
3313
3314
38
#ifdef ALIGN_SECTIONS_IN_FILE
3315
38
      previous = current;
3316
38
#endif
3317
38
    }
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
9
  if (align_adjust)
3325
3
    {
3326
3
      bfd_byte b;
3327
3328
3
      b = 0;
3329
3
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3330
3
    || bfd_write (&b, 1, abfd) != 1)
3331
0
  return false;
3332
3
    }
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
9
  sofar = BFD_ALIGN (sofar,
3338
9
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
9
  obj_relocbase (abfd) = sofar;
3341
9
  abfd->output_has_begun = true;
3342
3343
9
  return true;
3344
9
}
coff-x86_64.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
#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
2
#ifdef COFF_PAGE_SIZE
2997
2
  unsigned int page_size = COFF_PAGE_SIZE;
2998
2
#endif
2999
2
#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
#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
2
  {
3141
    /* Set the target_index field.  */
3142
2
    target_index = 1;
3143
5
    for (current = abfd->sections; current != NULL; current = current->next)
3144
3
      current->target_index = target_index++;
3145
2
  }
3146
2
#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
5
       current != NULL;
3160
3
       current = current->next)
3161
3
    {
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
3
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
0
  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
2
  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
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
}
Unexecuted instantiation: coff64-rs6000.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-aarch64.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-aarch64.c:coff_compute_section_file_positions
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
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
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
}
pei-loongarch64.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
0
     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
}
pei-riscv64.c:coff_compute_section_file_positions
Line
Count
Source
2970
6
{
2971
6
  asection *current;
2972
6
  file_ptr sofar = bfd_coff_filhsz (abfd);
2973
6
  bool align_adjust;
2974
6
  unsigned int target_index;
2975
6
#ifdef ALIGN_SECTIONS_IN_FILE
2976
6
  asection *previous = NULL;
2977
6
  file_ptr old_sofar;
2978
6
#endif
2979
2980
6
#ifdef COFF_IMAGE_WITH_PE
2981
6
  unsigned int page_size;
2982
2983
6
  if (coff_data (abfd)->link_info
2984
6
      || (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
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
6
  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
6
  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
6
  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
6
  if (coff_data (abfd)->section_by_target_index)
3066
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3067
3068
6
#ifdef COFF_IMAGE_WITH_PE
3069
6
  {
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
6
    unsigned int count;
3077
6
    asection **section_list;
3078
6
    unsigned int i;
3079
6
    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
6
    count = 0;
3090
20
    for (current = abfd->sections; current != NULL; current = current->next)
3091
14
      ++count;
3092
3093
    /* We allocate an extra cell to simplify the final loop.  */
3094
6
    amt = sizeof (struct asection *) * (count + 1);
3095
6
    section_list = (asection **) bfd_malloc (amt);
3096
6
    if (section_list == NULL)
3097
0
      return false;
3098
3099
6
    i = 0;
3100
20
    for (current = abfd->sections; current != NULL; current = current->next)
3101
14
      {
3102
14
  section_list[i] = current;
3103
14
  ++i;
3104
14
      }
3105
6
    section_list[i] = NULL;
3106
3107
6
    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
6
    target_index = 1;
3112
6
    abfd->sections = NULL;
3113
6
    abfd->section_last = NULL;
3114
20
    for (i = 0; i < count; i++)
3115
14
      {
3116
14
  current = section_list[i];
3117
14
  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
14
  if (current->size == 0)
3125
8
    {
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
8
      current->target_index = 1;
3132
8
    }
3133
6
  else
3134
6
    current->target_index = target_index++;
3135
14
      }
3136
3137
6
    free (section_list);
3138
6
  }
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
6
  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
6
  align_adjust = false;
3158
6
  for (current = abfd->sections;
3159
20
       current != NULL;
3160
14
       current = current->next)
3161
14
    {
3162
14
#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
14
      if (coff_section_data (abfd, current) == NULL)
3166
6
  {
3167
6
    size_t amt = sizeof (struct coff_section_tdata);
3168
3169
6
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3170
6
    if (current->used_by_bfd == NULL)
3171
0
      return false;
3172
6
  }
3173
14
      if (pei_section_data (abfd, current) == NULL)
3174
6
  {
3175
6
    size_t amt = sizeof (struct pei_section_tdata);
3176
3177
6
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3178
6
    if (coff_section_data (abfd, current)->tdata == NULL)
3179
0
      return false;
3180
6
  }
3181
14
      if (pei_section_data (abfd, current)->virt_size == 0)
3182
14
  pei_section_data (abfd, current)->virt_size = current->size;
3183
14
#endif
3184
3185
      /* Only deal with sections which have contents.  */
3186
14
      if (!(current->flags & SEC_HAS_CONTENTS))
3187
8
  continue;
3188
3189
6
      current->rawsize = current->size;
3190
3191
6
#ifdef COFF_IMAGE_WITH_PE
3192
      /* Make sure we skip empty sections in a PE image.  */
3193
6
      if (current->size == 0)
3194
0
  continue;
3195
6
#endif
3196
3197
      /* Align the sections in the file to the same boundary on
3198
   which they are aligned in virtual memory.  */
3199
6
#ifdef ALIGN_SECTIONS_IN_FILE
3200
6
      if ((abfd->flags & EXEC_P) != 0)
3201
6
  {
3202
    /* Make sure this section is aligned on the right boundary - by
3203
       padding the previous section up if necessary.  */
3204
6
    old_sofar = sofar;
3205
3206
6
#ifdef COFF_IMAGE_WITH_PE
3207
6
    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
6
    if (previous != NULL
3251
6
        && (previous->flags & SEC_LOAD) != 0)
3252
0
      previous->size += sofar - old_sofar;
3253
6
  }
3254
3255
6
#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
6
      current->filepos = sofar;
3265
3266
6
#ifdef COFF_IMAGE_WITH_PE
3267
      /* Set the padded size.  */
3268
6
      current->size = (current->size + page_size - 1) & -page_size;
3269
6
#endif
3270
3271
6
      sofar += current->size;
3272
3273
6
#ifdef ALIGN_SECTIONS_IN_FILE
3274
      /* Make sure that this section is of the right size too.  */
3275
6
      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
6
      else
3286
6
  {
3287
6
    old_sofar = sofar;
3288
6
#ifdef COFF_IMAGE_WITH_PE
3289
6
    sofar = BFD_ALIGN (sofar, page_size);
3290
#else
3291
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3292
#endif
3293
6
    align_adjust = sofar != old_sofar;
3294
6
    current->size += sofar - old_sofar;
3295
6
  }
3296
6
#endif
3297
3298
6
#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
6
      if (pei_section_data (abfd, current)->virt_size < current->size)
3303
2
  align_adjust = true;
3304
6
#endif
3305
3306
6
#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
6
      if (strcmp (current->name, _LIB) == 0)
3311
0
  bfd_set_section_vma (current, 0);
3312
6
#endif
3313
3314
6
#ifdef ALIGN_SECTIONS_IN_FILE
3315
6
      previous = current;
3316
6
#endif
3317
6
    }
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
6
  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
6
  sofar = BFD_ALIGN (sofar,
3338
6
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3339
3340
6
  obj_relocbase (abfd) = sofar;
3341
6
  abfd->output_has_begun = true;
3342
3343
6
  return true;
3344
6
}
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
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
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
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
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
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-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-mcore.c:coff_compute_section_file_positions
pei-sh.c:coff_compute_section_file_positions
Line
Count
Source
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
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
}
3345
3346
#ifdef COFF_IMAGE_WITH_PE
3347
3348
static bool
3349
coff_read_word (bfd *abfd, unsigned int *value, unsigned int *pelength)
3350
26
{
3351
26
  unsigned char b[2];
3352
26
  int status;
3353
3354
26
  status = bfd_read (b, 2, abfd);
3355
26
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
26
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
26
  else
3364
26
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
26
  *pelength += status;
3367
3368
26
  return true;
3369
26
}
pei-i386.c:coff_read_word
Line
Count
Source
3350
11
{
3351
11
  unsigned char b[2];
3352
11
  int status;
3353
3354
11
  status = bfd_read (b, 2, abfd);
3355
11
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
11
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
11
  else
3364
11
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
11
  *pelength += status;
3367
3368
11
  return true;
3369
11
}
pei-x86_64.c:coff_read_word
Line
Count
Source
3350
8
{
3351
8
  unsigned char b[2];
3352
8
  int status;
3353
3354
8
  status = bfd_read (b, 2, abfd);
3355
8
  if (status < 1)
3356
0
    {
3357
0
      *value = 0;
3358
0
      return false;
3359
0
    }
3360
3361
8
  if (status == 1)
3362
0
    *value = (unsigned int) b[0];
3363
8
  else
3364
8
    *value = (unsigned int) (b[0] + (b[1] << 8));
3365
3366
8
  *pelength += status;
3367
3368
8
  return true;
3369
8
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word
Unexecuted instantiation: pei-ia64.c:coff_read_word
pei-loongarch64.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
}
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
}
Unexecuted instantiation: pei-arm-wince.c:coff_read_word
Unexecuted instantiation: pei-arm.c:coff_read_word
Unexecuted instantiation: pei-mcore.c:coff_read_word
pei-sh.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
}
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
2.41M
{
3383
2.41M
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
2.41M
  if (buf_size == 1)
3390
2
    {
3391
2
      *value = (unsigned int)b[0];
3392
2
      *pelength += 1;
3393
2
    }
3394
2.41M
  else
3395
2.41M
    {
3396
2.41M
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
2.41M
      *pelength += 2;
3398
2.41M
    }
3399
3400
2.41M
  return true;
3401
2.41M
}
pei-i386.c:coff_read_word_from_buffer
Line
Count
Source
3382
355k
{
3383
355k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
355k
  if (buf_size == 1)
3390
2
    {
3391
2
      *value = (unsigned int)b[0];
3392
2
      *pelength += 1;
3393
2
    }
3394
355k
  else
3395
355k
    {
3396
355k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
355k
      *pelength += 2;
3398
355k
    }
3399
3400
355k
  return true;
3401
355k
}
pei-x86_64.c:coff_read_word_from_buffer
Line
Count
Source
3382
373k
{
3383
373k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
373k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
373k
  else
3395
373k
    {
3396
373k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
373k
      *pelength += 2;
3398
373k
    }
3399
3400
373k
  return true;
3401
373k
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-ia64.c:coff_read_word_from_buffer
pei-loongarch64.c:coff_read_word_from_buffer
Line
Count
Source
3382
1.57M
{
3383
1.57M
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
1.57M
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
1.57M
  else
3395
1.57M
    {
3396
1.57M
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
1.57M
      *pelength += 2;
3398
1.57M
    }
3399
3400
1.57M
  return true;
3401
1.57M
}
pei-riscv64.c:coff_read_word_from_buffer
Line
Count
Source
3382
110k
{
3383
110k
  if (buf_size < 1)
3384
0
    {
3385
0
      *value = 0;
3386
0
      return false;
3387
0
    }
3388
3389
110k
  if (buf_size == 1)
3390
0
    {
3391
0
      *value = (unsigned int)b[0];
3392
0
      *pelength += 1;
3393
0
    }
3394
110k
  else
3395
110k
    {
3396
110k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3397
110k
      *pelength += 2;
3398
110k
    }
3399
3400
110k
  return true;
3401
110k
}
Unexecuted instantiation: pei-arm-wince.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-mcore.c:coff_read_word_from_buffer
pei-sh.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
}
3402
3403
78
#define COFF_CHECKSUM_BUFFER_SIZE 0x800000
3404
3405
static unsigned int
3406
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
3407
26
{
3408
26
  file_ptr filepos;
3409
26
  unsigned int value;
3410
26
  unsigned int total;
3411
26
  unsigned char *buf;
3412
26
  int buf_size;
3413
3414
26
  total = 0;
3415
26
  *pelength = 0;
3416
26
  filepos = (file_ptr) 0;
3417
26
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
26
  if (buf == NULL)
3419
0
    return 0;
3420
26
  buf_size = 0;
3421
3422
26
  do
3423
52
    {
3424
52
      unsigned char *cur_buf;
3425
52
      int cur_buf_size;
3426
3427
52
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
52
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
52
      cur_buf_size = buf_size;
3432
52
      cur_buf = buf;
3433
3434
2.41M
      while (cur_buf_size > 0)
3435
2.41M
        {
3436
2.41M
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
2.41M
          cur_buf += 2;
3438
2.41M
          cur_buf_size -= 2;
3439
2.41M
          total += value;
3440
2.41M
          total = 0xffff & (total + (total >> 0x10));
3441
2.41M
        }
3442
3443
52
      filepos += buf_size;
3444
52
    }
3445
52
  while (buf_size > 0);
3446
3447
26
  free (buf);
3448
3449
26
  return (0xffff & (total + (total >> 0x10)));
3450
26
}
pei-i386.c:coff_compute_checksum
Line
Count
Source
3407
11
{
3408
11
  file_ptr filepos;
3409
11
  unsigned int value;
3410
11
  unsigned int total;
3411
11
  unsigned char *buf;
3412
11
  int buf_size;
3413
3414
11
  total = 0;
3415
11
  *pelength = 0;
3416
11
  filepos = (file_ptr) 0;
3417
11
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
11
  if (buf == NULL)
3419
0
    return 0;
3420
11
  buf_size = 0;
3421
3422
11
  do
3423
22
    {
3424
22
      unsigned char *cur_buf;
3425
22
      int cur_buf_size;
3426
3427
22
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
22
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
22
      cur_buf_size = buf_size;
3432
22
      cur_buf = buf;
3433
3434
355k
      while (cur_buf_size > 0)
3435
355k
        {
3436
355k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
355k
          cur_buf += 2;
3438
355k
          cur_buf_size -= 2;
3439
355k
          total += value;
3440
355k
          total = 0xffff & (total + (total >> 0x10));
3441
355k
        }
3442
3443
22
      filepos += buf_size;
3444
22
    }
3445
22
  while (buf_size > 0);
3446
3447
11
  free (buf);
3448
3449
11
  return (0xffff & (total + (total >> 0x10)));
3450
11
}
pei-x86_64.c:coff_compute_checksum
Line
Count
Source
3407
8
{
3408
8
  file_ptr filepos;
3409
8
  unsigned int value;
3410
8
  unsigned int total;
3411
8
  unsigned char *buf;
3412
8
  int buf_size;
3413
3414
8
  total = 0;
3415
8
  *pelength = 0;
3416
8
  filepos = (file_ptr) 0;
3417
8
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3418
8
  if (buf == NULL)
3419
0
    return 0;
3420
8
  buf_size = 0;
3421
3422
8
  do
3423
16
    {
3424
16
      unsigned char *cur_buf;
3425
16
      int cur_buf_size;
3426
3427
16
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3428
0
  return 0;
3429
3430
16
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3431
16
      cur_buf_size = buf_size;
3432
16
      cur_buf = buf;
3433
3434
373k
      while (cur_buf_size > 0)
3435
373k
        {
3436
373k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
373k
          cur_buf += 2;
3438
373k
          cur_buf_size -= 2;
3439
373k
          total += value;
3440
373k
          total = 0xffff & (total + (total >> 0x10));
3441
373k
        }
3442
3443
16
      filepos += buf_size;
3444
16
    }
3445
16
  while (buf_size > 0);
3446
3447
8
  free (buf);
3448
3449
8
  return (0xffff & (total + (total >> 0x10)));
3450
8
}
Unexecuted instantiation: pei-aarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-ia64.c:coff_compute_checksum
pei-loongarch64.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
1.57M
      while (cur_buf_size > 0)
3435
1.57M
        {
3436
1.57M
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
1.57M
          cur_buf += 2;
3438
1.57M
          cur_buf_size -= 2;
3439
1.57M
          total += value;
3440
1.57M
          total = 0xffff & (total + (total >> 0x10));
3441
1.57M
        }
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
}
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
110k
      while (cur_buf_size > 0)
3435
110k
        {
3436
110k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3437
110k
          cur_buf += 2;
3438
110k
          cur_buf_size -= 2;
3439
110k
          total += value;
3440
110k
          total = 0xffff & (total + (total >> 0x10));
3441
110k
        }
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
}
Unexecuted instantiation: pei-arm-wince.c:coff_compute_checksum
Unexecuted instantiation: pei-arm.c:coff_compute_checksum
Unexecuted instantiation: pei-mcore.c:coff_compute_checksum
pei-sh.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
}
3451
3452
static bool
3453
coff_apply_checksum (bfd *abfd)
3454
26
{
3455
26
  unsigned int computed;
3456
26
  unsigned int checksum = 0;
3457
26
  unsigned int peheader;
3458
26
  unsigned int pelength;
3459
3460
26
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
26
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
26
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
26
  checksum = 0;
3470
26
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
26
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
26
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
26
  checksum = computed + pelength;
3479
3480
26
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
26
  return bfd_write (&checksum, 4, abfd) == 4;
3484
26
}
pei-i386.c:coff_apply_checksum
Line
Count
Source
3454
11
{
3455
11
  unsigned int computed;
3456
11
  unsigned int checksum = 0;
3457
11
  unsigned int peheader;
3458
11
  unsigned int pelength;
3459
3460
11
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
11
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
11
  checksum = 0;
3470
11
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
11
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
11
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
11
  checksum = computed + pelength;
3479
3480
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
11
  return bfd_write (&checksum, 4, abfd) == 4;
3484
11
}
pei-x86_64.c:coff_apply_checksum
Line
Count
Source
3454
8
{
3455
8
  unsigned int computed;
3456
8
  unsigned int checksum = 0;
3457
8
  unsigned int peheader;
3458
8
  unsigned int pelength;
3459
3460
8
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3461
0
    return false;
3462
3463
8
  if (!coff_read_word (abfd, &peheader, &pelength))
3464
0
    return false;
3465
3466
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3467
0
    return false;
3468
3469
8
  checksum = 0;
3470
8
  if (bfd_write (&checksum, 4, abfd) != 4)
3471
0
    return false;
3472
3473
8
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3474
0
    return false;
3475
3476
8
  computed = coff_compute_checksum (abfd, &pelength);
3477
3478
8
  checksum = computed + pelength;
3479
3480
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3481
0
    return false;
3482
3483
8
  return bfd_write (&checksum, 4, abfd) == 4;
3484
8
}
Unexecuted instantiation: pei-aarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-ia64.c:coff_apply_checksum
pei-loongarch64.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
}
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
}
Unexecuted instantiation: pei-arm-wince.c:coff_apply_checksum
Unexecuted instantiation: pei-arm.c:coff_apply_checksum
Unexecuted instantiation: pei-mcore.c:coff_apply_checksum
pei-sh.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
}
3485
3486
#endif /* COFF_IMAGE_WITH_PE */
3487
3488
static bool
3489
coff_write_object_contents (bfd * abfd)
3490
31
{
3491
31
  asection *current;
3492
31
  bool hasrelocs = false;
3493
31
  bool haslinno = false;
3494
#ifdef COFF_IMAGE_WITH_PE
3495
  bool hasdebug = false;
3496
#endif
3497
31
  file_ptr scn_base;
3498
31
  file_ptr reloc_base;
3499
31
  file_ptr lineno_base;
3500
31
  file_ptr sym_base;
3501
31
  unsigned long reloc_size = 0, reloc_count = 0;
3502
31
  unsigned long lnno_size = 0;
3503
31
  bool long_section_names;
3504
31
  asection *text_sec = NULL;
3505
31
  asection *data_sec = NULL;
3506
31
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
31
  struct internal_filehdr internal_f;
3512
31
  struct internal_aouthdr internal_a;
3513
#ifdef COFF_LONG_SECTION_NAMES
3514
29
  size_t string_size = STRING_SIZE_SIZE;
3515
#endif
3516
3517
31
  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
31
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
31
  if (! abfd->output_has_begun)
3524
18
    {
3525
18
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
18
    }
3528
3529
31
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
126
  for (current = abfd->sections; current != NULL; current =
3534
95
       current->next)
3535
95
    {
3536
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
92
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
#endif
3541
95
      reloc_count += current->reloc_count;
3542
95
    }
3543
3544
31
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
31
  lineno_base = reloc_base + reloc_size;
3547
31
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
126
  for (current = abfd->sections; current != NULL; current =
3551
95
       current->next)
3552
95
    {
3553
95
      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
95
      else
3560
95
  current->line_filepos = 0;
3561
3562
95
      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
95
      else
3573
95
  current->rel_filepos = 0;
3574
95
    }
3575
3576
  /* Write section headers to the file.  */
3577
31
  internal_f.f_nscns = 0;
3578
3579
31
  if ((abfd->flags & EXEC_P) != 0)
3580
26
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
5
  else
3582
5
    {
3583
5
      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
5
    }
3593
3594
31
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
31
  long_section_names = false;
3598
31
  for (current = abfd->sections;
3599
126
       current != NULL;
3600
95
       current = current->next)
3601
95
    {
3602
95
      struct internal_scnhdr section;
3603
#ifdef COFF_IMAGE_WITH_PE
3604
      bool is_reloc_section = false;
3605
3606
92
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
3
  {
3608
3
    is_reloc_section = true;
3609
3
    hasrelocs = true;
3610
3
    pe_data (abfd)->has_reloc_section = 1;
3611
3
  }
3612
#endif
3613
3614
95
      internal_f.f_nscns++;
3615
3616
95
      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
92
      if (bfd_coff_long_section_names (abfd))
3622
48
  {
3623
48
    size_t len;
3624
3625
    len = strlen (current->name);
3626
48
    if (len > SCNNMLEN)
3627
15
      {
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
15
        if (string_size < 10000000)
3633
15
    {
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
15
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
15
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
15
    }
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
15
        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
15
        string_size += len + 1;
3687
15
        long_section_names = true;
3688
15
      }
3689
48
  }
3690
92
#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
95
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
95
      else
3698
95
#endif
3699
95
      section.s_vaddr = current->vma;
3700
92
      section.s_paddr = current->lma;
3701
92
      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
92
      if (coff_section_data (abfd, current) != NULL
3714
92
    && pei_section_data (abfd, current) != NULL)
3715
92
  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
95
      if (current->size == 0
3723
95
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
23
  section.s_scnptr = 0;
3725
72
      else
3726
72
  section.s_scnptr = current->filepos;
3727
3728
92
      section.s_relptr = current->rel_filepos;
3729
92
      section.s_lnnoptr = current->line_filepos;
3730
92
      section.s_nreloc = current->reloc_count;
3731
92
      section.s_nlnno = current->lineno_count;
3732
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
3
      if (current->reloc_count != 0)
3735
0
  hasrelocs = true;
3736
#endif
3737
95
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
#ifdef COFF_IMAGE_WITH_PE
3740
92
      if ((current->flags & SEC_DEBUGGING) != 0
3741
92
    && ! is_reloc_section)
3742
26
  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
92
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
95
      if (!strcmp (current->name, _TEXT))
3759
6
  text_sec = current;
3760
89
      else if (!strcmp (current->name, _DATA))
3761
6
  data_sec = current;
3762
83
      else if (!strcmp (current->name, _BSS))
3763
4
  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
92
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
92
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3775
2
        != 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
92
#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
92
      if (section.s_size == 0)
3800
18
  internal_f.f_nscns--;
3801
74
      else
3802
74
#endif
3803
74
  {
3804
77
    SCNHDR buff;
3805
77
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
77
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
77
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
74
  }
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
92
      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
92
    }
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
31
  internal_f.f_timdat = 0;
3978
31
  internal_f.f_flags = 0;
3979
3980
31
  if (abfd->flags & EXEC_P)
3981
26
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
5
  else
3983
5
    {
3984
5
      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
5
    }
3994
3995
31
  if (!hasrelocs)
3996
28
    internal_f.f_flags |= F_RELFLG;
3997
31
  if (!haslinno)
3998
31
    internal_f.f_flags |= F_LNNO;
3999
31
  if (abfd->flags & EXEC_P)
4000
26
    internal_f.f_flags |= F_EXEC;
4001
#ifdef COFF_IMAGE_WITH_PE
4002
29
  if (! hasdebug)
4003
19
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
29
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
23
    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
14
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4011
#else
4012
2
  if (bfd_little_endian (abfd))
4013
2
    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
31
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
31
  {
4039
31
    unsigned int magic = 0;
4040
31
    unsigned short flags = 0;
4041
4042
31
    coff_set_flags (abfd, &magic, &flags);
4043
31
    internal_f.f_magic = magic;
4044
31
    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
0
    internal_a.magic = ZMAGIC;
4060
#endif
4061
4062
#if defined(LOONGARCH64)
4063
#define __A_MAGIC_SET__
4064
1
    internal_a.magic = ZMAGIC;
4065
#endif
4066
4067
#if defined(RISCV64)
4068
#define __A_MAGIC_SET__
4069
6
    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
10
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
11
    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
1
    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
31
#undef __A_MAGIC_SET__
4121
31
#endif
4122
31
  }
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
31
  obj_sym_filepos (abfd) = sym_base;
4134
4135
31
  if (bfd_get_symcount (abfd) != 0)
4136
4
    {
4137
4
      int firstundef;
4138
4139
4
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
4
      coff_mangle_symbols (abfd);
4142
4
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
4
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
4
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
4
    }
4149
#ifdef COFF_LONG_SECTION_NAMES
4150
25
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
2
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
2
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
2
    }
4157
29
#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
31
  if (obj_raw_syment_count (abfd) != 0)
4162
4
    {
4163
4
      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
4
    }
4170
27
  else
4171
27
    {
4172
27
      if (long_section_names)
4173
2
  internal_f.f_symptr = sym_base;
4174
25
      else
4175
25
  internal_f.f_symptr = 0;
4176
27
      internal_f.f_flags |= F_LSYMS;
4177
27
    }
4178
4179
31
  if (text_sec)
4180
6
    {
4181
6
      internal_a.tsize = text_sec->size;
4182
6
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
6
    }
4184
31
  if (data_sec)
4185
6
    {
4186
6
      internal_a.dsize = data_sec->size;
4187
6
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
6
    }
4189
31
  if (bss_sec)
4190
4
    {
4191
4
      internal_a.bsize = bss_sec->size;
4192
4
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
4
    }
4195
4196
31
  internal_a.entry = bfd_get_start_address (abfd);
4197
31
  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
29
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
29
    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
31
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
31
  {
4311
31
    char * buff;
4312
31
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
31
    buff = (char *) bfd_malloc (amount);
4315
31
    if (buff == NULL)
4316
0
      return false;
4317
4318
31
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
31
    amount = bfd_write (buff, amount, abfd);
4320
4321
31
    free (buff);
4322
4323
31
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
31
  }
4326
4327
31
  if (abfd->flags & EXEC_P)
4328
26
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
26
      char * buff;
4332
26
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
26
      buff = (char *) bfd_malloc (amount);
4335
26
      if (buff == NULL)
4336
0
  return false;
4337
4338
26
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
26
      amount = bfd_write (buff, amount, abfd);
4340
4341
26
      free (buff);
4342
4343
26
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
#ifdef COFF_IMAGE_WITH_PE
4347
26
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
#endif
4350
26
    }
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
31
  return true;
4371
31
}
pei-i386.c:coff_write_object_contents
Line
Count
Source
3490
11
{
3491
11
  asection *current;
3492
11
  bool hasrelocs = false;
3493
11
  bool haslinno = false;
3494
11
#ifdef COFF_IMAGE_WITH_PE
3495
11
  bool hasdebug = false;
3496
11
#endif
3497
11
  file_ptr scn_base;
3498
11
  file_ptr reloc_base;
3499
11
  file_ptr lineno_base;
3500
11
  file_ptr sym_base;
3501
11
  unsigned long reloc_size = 0, reloc_count = 0;
3502
11
  unsigned long lnno_size = 0;
3503
11
  bool long_section_names;
3504
11
  asection *text_sec = NULL;
3505
11
  asection *data_sec = NULL;
3506
11
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
11
  struct internal_filehdr internal_f;
3512
11
  struct internal_aouthdr internal_a;
3513
11
#ifdef COFF_LONG_SECTION_NAMES
3514
11
  size_t string_size = STRING_SIZE_SIZE;
3515
11
#endif
3516
3517
11
  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
11
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
11
  if (! abfd->output_has_begun)
3524
7
    {
3525
7
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
7
    }
3528
3529
11
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
51
  for (current = abfd->sections; current != NULL; current =
3534
40
       current->next)
3535
40
    {
3536
40
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
40
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
40
#endif
3541
40
      reloc_count += current->reloc_count;
3542
40
    }
3543
3544
11
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
11
  lineno_base = reloc_base + reloc_size;
3547
11
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
51
  for (current = abfd->sections; current != NULL; current =
3551
40
       current->next)
3552
40
    {
3553
40
      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
40
      else
3560
40
  current->line_filepos = 0;
3561
3562
40
      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
40
      else
3573
40
  current->rel_filepos = 0;
3574
40
    }
3575
3576
  /* Write section headers to the file.  */
3577
11
  internal_f.f_nscns = 0;
3578
3579
11
  if ((abfd->flags & EXEC_P) != 0)
3580
11
    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
11
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
11
  long_section_names = false;
3598
11
  for (current = abfd->sections;
3599
51
       current != NULL;
3600
40
       current = current->next)
3601
40
    {
3602
40
      struct internal_scnhdr section;
3603
40
#ifdef COFF_IMAGE_WITH_PE
3604
40
      bool is_reloc_section = false;
3605
3606
40
      if (strcmp (current->name, DOT_RELOC) == 0)
3607
1
  {
3608
1
    is_reloc_section = true;
3609
1
    hasrelocs = true;
3610
1
    pe_data (abfd)->has_reloc_section = 1;
3611
1
  }
3612
40
#endif
3613
3614
40
      internal_f.f_nscns++;
3615
3616
40
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
40
#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
40
      if (bfd_coff_long_section_names (abfd))
3622
27
  {
3623
27
    size_t len;
3624
3625
27
    len = strlen (current->name);
3626
27
    if (len > SCNNMLEN)
3627
4
      {
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
4
        if (string_size < 10000000)
3633
4
    {
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
4
      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
4
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3647
      /* Then strncpy takes care of any padding for us.  */
3648
4
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3649
4
    }
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
4
#endif
3672
4
        if (string_size > 0xffffffffUL - (len + 1)
3673
#ifndef COFF_WITH_PE
3674
      || string_size >= 10000000
3675
#endif
3676
4
      )
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
4
        string_size += len + 1;
3687
4
        long_section_names = true;
3688
4
      }
3689
27
  }
3690
40
#endif
3691
3692
40
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
40
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
40
      else
3698
40
#endif
3699
40
      section.s_vaddr = current->vma;
3700
40
      section.s_paddr = current->lma;
3701
40
      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
40
      section.s_page = 0;
3706
40
#endif
3707
3708
40
#ifdef COFF_WITH_PE
3709
40
      section.s_paddr = 0;
3710
40
#endif
3711
40
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
40
      if (coff_section_data (abfd, current) != NULL
3714
40
    && pei_section_data (abfd, current) != NULL)
3715
40
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
40
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
40
      if (current->size == 0
3723
40
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
12
  section.s_scnptr = 0;
3725
28
      else
3726
28
  section.s_scnptr = current->filepos;
3727
3728
40
      section.s_relptr = current->rel_filepos;
3729
40
      section.s_lnnoptr = current->line_filepos;
3730
40
      section.s_nreloc = current->reloc_count;
3731
40
      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
40
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
40
#ifdef COFF_IMAGE_WITH_PE
3740
40
      if ((current->flags & SEC_DEBUGGING) != 0
3741
40
    && ! is_reloc_section)
3742
4
  hasdebug = true;
3743
40
#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
40
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
40
      if (!strcmp (current->name, _TEXT))
3759
3
  text_sec = current;
3760
37
      else if (!strcmp (current->name, _DATA))
3761
4
  data_sec = current;
3762
33
      else if (!strcmp (current->name, _BSS))
3763
3
  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
40
#ifdef COFF_ENCODE_ALIGNMENT
3773
40
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
40
    && (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
40
#endif
3792
3793
40
#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
40
      if (section.s_size == 0)
3800
9
  internal_f.f_nscns--;
3801
31
      else
3802
31
#endif
3803
31
  {
3804
31
    SCNHDR buff;
3805
31
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
31
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
31
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
31
  }
3811
3812
40
#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
40
      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
40
#endif /* COFF_WITH_PE */
3907
40
    }
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
11
  internal_f.f_timdat = 0;
3978
11
  internal_f.f_flags = 0;
3979
3980
11
  if (abfd->flags & EXEC_P)
3981
11
    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
11
  if (!hasrelocs)
3996
10
    internal_f.f_flags |= F_RELFLG;
3997
11
  if (!haslinno)
3998
11
    internal_f.f_flags |= F_LNNO;
3999
11
  if (abfd->flags & EXEC_P)
4000
11
    internal_f.f_flags |= F_EXEC;
4001
11
#ifdef COFF_IMAGE_WITH_PE
4002
11
  if (! hasdebug)
4003
8
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
11
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
8
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
11
#endif
4007
4008
11
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64) && !defined (COFF_WITH_peRiscV64)
4009
11
#ifdef COFF_WITH_PE
4010
11
  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
11
#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
11
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
11
  {
4039
11
    unsigned int magic = 0;
4040
11
    unsigned short flags = 0;
4041
4042
11
    coff_set_flags (abfd, &magic, &flags);
4043
11
    internal_f.f_magic = magic;
4044
11
    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
11
#if defined(I386)
4078
11
#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
11
    internal_a.magic = ZMAGIC;
4085
11
#endif
4086
11
#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
11
#undef __A_MAGIC_SET__
4121
11
#endif
4122
11
  }
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
11
  internal_a.vstamp = 0;
4130
11
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
11
  obj_sym_filepos (abfd) = sym_base;
4134
4135
11
  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
10
#ifdef COFF_LONG_SECTION_NAMES
4150
10
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4151
2
    {
4152
      /* If we have long section names we have to write out the string
4153
   table even if there are no symbols.  */
4154
2
      if (! coff_write_symbols (abfd))
4155
0
  return false;
4156
2
    }
4157
11
#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
11
  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
10
  else
4171
10
    {
4172
10
      if (long_section_names)
4173
2
  internal_f.f_symptr = sym_base;
4174
8
      else
4175
8
  internal_f.f_symptr = 0;
4176
10
      internal_f.f_flags |= F_LSYMS;
4177
10
    }
4178
4179
11
  if (text_sec)
4180
3
    {
4181
3
      internal_a.tsize = text_sec->size;
4182
3
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
3
    }
4184
11
  if (data_sec)
4185
4
    {
4186
4
      internal_a.dsize = data_sec->size;
4187
4
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4188
4
    }
4189
11
  if (bss_sec)
4190
3
    {
4191
3
      internal_a.bsize = bss_sec->size;
4192
3
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4193
0
  internal_a.data_start = bss_sec->vma;
4194
3
    }
4195
4196
11
  internal_a.entry = bfd_get_start_address (abfd);
4197
11
  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
11
#ifdef COFF_WITH_PE
4296
11
  {
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
11
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
11
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
11
  }
4304
11
#endif
4305
4306
  /* Now write header.  */
4307
11
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
11
  {
4311
11
    char * buff;
4312
11
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
11
    buff = (char *) bfd_malloc (amount);
4315
11
    if (buff == NULL)
4316
0
      return false;
4317
4318
11
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
11
    amount = bfd_write (buff, amount, abfd);
4320
4321
11
    free (buff);
4322
4323
11
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
11
  }
4326
4327
11
  if (abfd->flags & EXEC_P)
4328
11
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
11
      char * buff;
4332
11
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
11
      buff = (char *) bfd_malloc (amount);
4335
11
      if (buff == NULL)
4336
0
  return false;
4337
4338
11
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
11
      amount = bfd_write (buff, amount, abfd);
4340
4341
11
      free (buff);
4342
4343
11
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
11
#ifdef COFF_IMAGE_WITH_PE
4347
11
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
11
#endif
4350
11
    }
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
11
  return true;
4371
11
}
Unexecuted instantiation: pe-x86_64.c:coff_write_object_contents
pei-x86_64.c:coff_write_object_contents
Line
Count
Source
3490
8
{
3491
8
  asection *current;
3492
8
  bool hasrelocs = false;
3493
8
  bool haslinno = false;
3494
8
#ifdef COFF_IMAGE_WITH_PE
3495
8
  bool hasdebug = false;
3496
8
#endif
3497
8
  file_ptr scn_base;
3498
8
  file_ptr reloc_base;
3499
8
  file_ptr lineno_base;
3500
8
  file_ptr sym_base;
3501
8
  unsigned long reloc_size = 0, reloc_count = 0;
3502
8
  unsigned long lnno_size = 0;
3503
8
  bool long_section_names;
3504
8
  asection *text_sec = NULL;
3505
8
  asection *data_sec = NULL;
3506
8
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
8
  struct internal_filehdr internal_f;
3512
8
  struct internal_aouthdr internal_a;
3513
8
#ifdef COFF_LONG_SECTION_NAMES
3514
8
  size_t string_size = STRING_SIZE_SIZE;
3515
8
#endif
3516
3517
8
  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
8
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
8
  if (! abfd->output_has_begun)
3524
5
    {
3525
5
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
5
    }
3528
3529
8
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
42
  for (current = abfd->sections; current != NULL; current =
3534
34
       current->next)
3535
34
    {
3536
34
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
34
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
34
#endif
3541
34
      reloc_count += current->reloc_count;
3542
34
    }
3543
3544
8
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
8
  lineno_base = reloc_base + reloc_size;
3547
8
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
42
  for (current = abfd->sections; current != NULL; current =
3551
34
       current->next)
3552
34
    {
3553
34
      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
34
      else
3560
34
  current->line_filepos = 0;
3561
3562
34
      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
34
      else
3573
34
  current->rel_filepos = 0;
3574
34
    }
3575
3576
  /* Write section headers to the file.  */
3577
8
  internal_f.f_nscns = 0;
3578
3579
8
  if ((abfd->flags & EXEC_P) != 0)
3580
8
    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
8
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
8
  long_section_names = false;
3598
8
  for (current = abfd->sections;
3599
42
       current != NULL;
3600
34
       current = current->next)
3601
34
    {
3602
34
      struct internal_scnhdr section;
3603
34
#ifdef COFF_IMAGE_WITH_PE
3604
34
      bool is_reloc_section = false;
3605
3606
34
      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
34
#endif
3613
3614
34
      internal_f.f_nscns++;
3615
3616
34
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
34
#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
34
      if (bfd_coff_long_section_names (abfd))
3622
21
  {
3623
21
    size_t len;
3624
3625
21
    len = strlen (current->name);
3626
21
    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
21
  }
3690
34
#endif
3691
3692
34
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
34
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
34
      else
3698
34
#endif
3699
34
      section.s_vaddr = current->vma;
3700
34
      section.s_paddr = current->lma;
3701
34
      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
34
      section.s_page = 0;
3706
34
#endif
3707
3708
34
#ifdef COFF_WITH_PE
3709
34
      section.s_paddr = 0;
3710
34
#endif
3711
34
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
34
      if (coff_section_data (abfd, current) != NULL
3714
34
    && pei_section_data (abfd, current) != NULL)
3715
34
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
34
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
34
      if (current->size == 0
3723
34
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
2
  section.s_scnptr = 0;
3725
32
      else
3726
32
  section.s_scnptr = current->filepos;
3727
3728
34
      section.s_relptr = current->rel_filepos;
3729
34
      section.s_lnnoptr = current->line_filepos;
3730
34
      section.s_nreloc = current->reloc_count;
3731
34
      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
34
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
34
#ifdef COFF_IMAGE_WITH_PE
3740
34
      if ((current->flags & SEC_DEBUGGING) != 0
3741
34
    && ! is_reloc_section)
3742
12
  hasdebug = true;
3743
34
#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
34
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
34
      if (!strcmp (current->name, _TEXT))
3759
3
  text_sec = current;
3760
31
      else if (!strcmp (current->name, _DATA))
3761
2
  data_sec = current;
3762
29
      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
34
#ifdef COFF_ENCODE_ALIGNMENT
3773
34
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
34
    && (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
34
#endif
3792
3793
34
#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
34
      if (section.s_size == 0)
3800
1
  internal_f.f_nscns--;
3801
33
      else
3802
33
#endif
3803
33
  {
3804
33
    SCNHDR buff;
3805
33
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
33
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
33
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
33
  }
3811
3812
34
#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
34
      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
34
#endif /* COFF_WITH_PE */
3907
34
    }
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
8
  internal_f.f_timdat = 0;
3978
8
  internal_f.f_flags = 0;
3979
3980
8
  if (abfd->flags & EXEC_P)
3981
8
    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
8
  if (!hasrelocs)
3996
6
    internal_f.f_flags |= F_RELFLG;
3997
8
  if (!haslinno)
3998
8
    internal_f.f_flags |= F_LNNO;
3999
8
  if (abfd->flags & EXEC_P)
4000
8
    internal_f.f_flags |= F_EXEC;
4001
8
#ifdef COFF_IMAGE_WITH_PE
4002
8
  if (! hasdebug)
4003
6
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
8
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
8
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
8
#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
8
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
8
  {
4039
8
    unsigned int magic = 0;
4040
8
    unsigned short flags = 0;
4041
4042
8
    coff_set_flags (abfd, &magic, &flags);
4043
8
    internal_f.f_magic = magic;
4044
8
    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
8
#if defined(I386)
4078
8
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
8
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
8
#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
8
#undef __A_MAGIC_SET__
4121
8
#endif
4122
8
  }
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
8
  internal_a.vstamp = 0;
4130
8
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
8
  obj_sym_filepos (abfd) = sym_base;
4134
4135
8
  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
7
#ifdef COFF_LONG_SECTION_NAMES
4150
7
  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
8
#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
8
  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
7
  else
4171
7
    {
4172
7
      if (long_section_names)
4173
0
  internal_f.f_symptr = sym_base;
4174
7
      else
4175
7
  internal_f.f_symptr = 0;
4176
7
      internal_f.f_flags |= F_LSYMS;
4177
7
    }
4178
4179
8
  if (text_sec)
4180
3
    {
4181
3
      internal_a.tsize = text_sec->size;
4182
3
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4183
3
    }
4184
8
  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
8
  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
8
  internal_a.entry = bfd_get_start_address (abfd);
4197
8
  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
8
#ifdef COFF_WITH_PE
4296
8
  {
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
8
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
8
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
8
  }
4304
8
#endif
4305
4306
  /* Now write header.  */
4307
8
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
8
  {
4311
8
    char * buff;
4312
8
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
8
    buff = (char *) bfd_malloc (amount);
4315
8
    if (buff == NULL)
4316
0
      return false;
4317
4318
8
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
8
    amount = bfd_write (buff, amount, abfd);
4320
4321
8
    free (buff);
4322
4323
8
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
8
  }
4326
4327
8
  if (abfd->flags & EXEC_P)
4328
8
    {
4329
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4330
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4331
8
      char * buff;
4332
8
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4333
4334
8
      buff = (char *) bfd_malloc (amount);
4335
8
      if (buff == NULL)
4336
0
  return false;
4337
4338
8
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4339
8
      amount = bfd_write (buff, amount, abfd);
4340
4341
8
      free (buff);
4342
4343
8
      if (amount != bfd_coff_aoutsz (abfd))
4344
0
  return false;
4345
4346
8
#ifdef COFF_IMAGE_WITH_PE
4347
8
      if (! coff_apply_checksum (abfd))
4348
0
  return false;
4349
8
#endif
4350
8
    }
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
8
  return true;
4371
8
}
coff-x86_64.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
#ifdef COFF_IMAGE_WITH_PE
3495
  bool hasdebug = false;
3496
#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
#ifdef COFF_LONG_SECTION_NAMES
3514
  size_t string_size = STRING_SIZE_SIZE;
3515
#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
5
  for (current = abfd->sections; current != NULL; current =
3534
3
       current->next)
3535
3
    {
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
3
      reloc_count += current->reloc_count;
3542
3
    }
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
5
  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
#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
3
      else
3573
3
  current->rel_filepos = 0;
3574
3
    }
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
5
       current != NULL;
3600
3
       current = current->next)
3601
3
    {
3602
3
      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
3
      internal_f.f_nscns++;
3615
3616
3
      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
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
#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
3
      if (current->size == 0
3723
3
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
1
  section.s_scnptr = 0;
3725
2
      else
3726
2
  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
3
#ifndef COFF_IMAGE_WITH_PE
3733
      /* In PEI, relocs come in the .reloc section.  */
3734
3
      if (current->reloc_count != 0)
3735
0
  hasrelocs = true;
3736
3
#endif
3737
3
      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
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
#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
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
#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
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
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
#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
2
#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
2
  if (bfd_little_endian (abfd))
4013
2
    internal_f.f_flags |= F_AR32WR;
4014
0
  else
4015
0
    internal_f.f_flags |= F_AR32W;
4016
2
#endif
4017
2
#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
#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
2
#if defined(I386)
4078
2
#define __A_MAGIC_SET__
4079
#if defined LYNXOS
4080
    internal_a.magic = LYNXCOFFMAGIC;
4081
#elif defined AMD64
4082
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4083
#else
4084
    internal_a.magic = ZMAGIC;
4085
#endif
4086
2
#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
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
#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
2
  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
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
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
#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
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
#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
2
  return true;
4371
2
}
Unexecuted instantiation: coff64-rs6000.c:coff_write_object_contents
Unexecuted instantiation: pe-aarch64.c:coff_write_object_contents
Unexecuted instantiation: pei-aarch64.c:coff_write_object_contents
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
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
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
1
  else
3582
1
    {
3583
1
      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
1
    }
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
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
1
  else
3983
1
    {
3984
1
      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
1
    }
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
0
    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
#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
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
1
  return true;
4371
1
}
pei-loongarch64.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
#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
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
1
#if defined(LOONGARCH64)
4063
1
#define __A_MAGIC_SET__
4064
1
    internal_a.magic = ZMAGIC;
4065
1
#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
}
pei-riscv64.c:coff_write_object_contents
Line
Count
Source
3490
6
{
3491
6
  asection *current;
3492
6
  bool hasrelocs = false;
3493
6
  bool haslinno = false;
3494
6
#ifdef COFF_IMAGE_WITH_PE
3495
6
  bool hasdebug = false;
3496
6
#endif
3497
6
  file_ptr scn_base;
3498
6
  file_ptr reloc_base;
3499
6
  file_ptr lineno_base;
3500
6
  file_ptr sym_base;
3501
6
  unsigned long reloc_size = 0, reloc_count = 0;
3502
6
  unsigned long lnno_size = 0;
3503
6
  bool long_section_names;
3504
6
  asection *text_sec = NULL;
3505
6
  asection *data_sec = NULL;
3506
6
  asection *bss_sec = NULL;
3507
#ifdef RS6000COFF_C
3508
  asection *tdata_sec = NULL;
3509
  asection *tbss_sec = NULL;
3510
#endif
3511
6
  struct internal_filehdr internal_f;
3512
6
  struct internal_aouthdr internal_a;
3513
6
#ifdef COFF_LONG_SECTION_NAMES
3514
6
  size_t string_size = STRING_SIZE_SIZE;
3515
6
#endif
3516
3517
6
  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
6
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3522
3523
6
  if (! abfd->output_has_begun)
3524
3
    {
3525
3
      if (! coff_compute_section_file_positions (abfd))
3526
0
  return false;
3527
3
    }
3528
3529
6
  reloc_base = obj_relocbase (abfd);
3530
3531
  /* Work out the size of the reloc and linno areas.  */
3532
3533
20
  for (current = abfd->sections; current != NULL; current =
3534
14
       current->next)
3535
14
    {
3536
14
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3537
      /* We store the actual reloc count in the first reloc's addr.  */
3538
14
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3539
0
  reloc_count ++;
3540
14
#endif
3541
14
      reloc_count += current->reloc_count;
3542
14
    }
3543
3544
6
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3545
3546
6
  lineno_base = reloc_base + reloc_size;
3547
6
  sym_base = lineno_base + lnno_size;
3548
3549
  /* Indicate in each section->line_filepos its actual file address.  */
3550
20
  for (current = abfd->sections; current != NULL; current =
3551
14
       current->next)
3552
14
    {
3553
14
      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
14
      else
3560
14
  current->line_filepos = 0;
3561
3562
14
      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
14
      else
3573
14
  current->rel_filepos = 0;
3574
14
    }
3575
3576
  /* Write section headers to the file.  */
3577
6
  internal_f.f_nscns = 0;
3578
3579
6
  if ((abfd->flags & EXEC_P) != 0)
3580
5
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
1
  else
3582
1
    {
3583
1
      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
1
    }
3593
3594
6
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3595
0
    return false;
3596
3597
6
  long_section_names = false;
3598
6
  for (current = abfd->sections;
3599
20
       current != NULL;
3600
14
       current = current->next)
3601
14
    {
3602
14
      struct internal_scnhdr section;
3603
14
#ifdef COFF_IMAGE_WITH_PE
3604
14
      bool is_reloc_section = false;
3605
3606
14
      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
14
#endif
3613
3614
14
      internal_f.f_nscns++;
3615
3616
14
      strncpy (section.s_name, current->name, SCNNMLEN);
3617
3618
14
#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
14
      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
14
#endif
3691
3692
14
#ifdef _LIB
3693
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3694
   Ian Taylor <ian@cygnus.com>.  */
3695
14
      if (strcmp (current->name, _LIB) == 0)
3696
0
  section.s_vaddr = 0;
3697
14
      else
3698
14
#endif
3699
14
      section.s_vaddr = current->vma;
3700
14
      section.s_paddr = current->lma;
3701
14
      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
14
      section.s_page = 0;
3706
14
#endif
3707
3708
14
#ifdef COFF_WITH_PE
3709
14
      section.s_paddr = 0;
3710
14
#endif
3711
14
#ifdef COFF_IMAGE_WITH_PE
3712
      /* Reminder: s_paddr holds the virtual size of the section.  */
3713
14
      if (coff_section_data (abfd, current) != NULL
3714
14
    && pei_section_data (abfd, current) != NULL)
3715
14
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3716
0
      else
3717
0
  section.s_paddr = 0;
3718
14
#endif
3719
3720
      /* If this section has no size or is unloadable then the scnptr
3721
   will be 0 too.  */
3722
14
      if (current->size == 0
3723
14
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3724
8
  section.s_scnptr = 0;
3725
6
      else
3726
6
  section.s_scnptr = current->filepos;
3727
3728
14
      section.s_relptr = current->rel_filepos;
3729
14
      section.s_lnnoptr = current->line_filepos;
3730
14
      section.s_nreloc = current->reloc_count;
3731
14
      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
14
      if (current->lineno_count != 0)
3738
0
  haslinno = true;
3739
14
#ifdef COFF_IMAGE_WITH_PE
3740
14
      if ((current->flags & SEC_DEBUGGING) != 0
3741
14
    && ! is_reloc_section)
3742
6
  hasdebug = true;
3743
14
#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
14
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3757
3758
14
      if (!strcmp (current->name, _TEXT))
3759
0
  text_sec = current;
3760
14
      else if (!strcmp (current->name, _DATA))
3761
0
  data_sec = current;
3762
14
      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
14
#ifdef COFF_ENCODE_ALIGNMENT
3773
14
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3774
14
    && (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
14
#endif
3792
3793
14
#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
14
      if (section.s_size == 0)
3800
8
  internal_f.f_nscns--;
3801
6
      else
3802
6
#endif
3803
6
  {
3804
6
    SCNHDR buff;
3805
6
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3806
3807
6
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3808
6
        || bfd_write (& buff, amt, abfd) != amt)
3809
0
      return false;
3810
6
  }
3811
3812
14
#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
14
      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
14
#endif /* COFF_WITH_PE */
3907
14
    }
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
6
  internal_f.f_timdat = 0;
3978
6
  internal_f.f_flags = 0;
3979
3980
6
  if (abfd->flags & EXEC_P)
3981
5
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
1
  else
3983
1
    {
3984
1
      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
1
    }
3994
3995
6
  if (!hasrelocs)
3996
6
    internal_f.f_flags |= F_RELFLG;
3997
6
  if (!haslinno)
3998
6
    internal_f.f_flags |= F_LNNO;
3999
6
  if (abfd->flags & EXEC_P)
4000
5
    internal_f.f_flags |= F_EXEC;
4001
6
#ifdef COFF_IMAGE_WITH_PE
4002
6
  if (! hasdebug)
4003
3
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4004
6
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4005
5
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4006
6
#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
6
  memset (&internal_a, 0, sizeof internal_a);
4036
4037
  /* Set up architecture-dependent stuff.  */
4038
6
  {
4039
6
    unsigned int magic = 0;
4040
6
    unsigned short flags = 0;
4041
4042
6
    coff_set_flags (abfd, &magic, &flags);
4043
6
    internal_f.f_magic = magic;
4044
6
    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
6
#if defined(RISCV64)
4068
6
#define __A_MAGIC_SET__
4069
6
    internal_a.magic = ZMAGIC;
4070
6
#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
6
#undef __A_MAGIC_SET__
4121
6
#endif
4122
6
  }
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
6
  internal_a.vstamp = 0;
4130
6
#endif
4131
4132
  /* Now should write relocs, strings, syms.  */
4133
6
  obj_sym_filepos (abfd) = sym_base;
4134
4135
6
  if (bfd_get_symcount (abfd) != 0)
4136
2
    {
4137
2
      int firstundef;
4138
4139
2
      if (!coff_renumber_symbols (abfd, &firstundef))
4140
0
  return false;
4141
2
      coff_mangle_symbols (abfd);
4142
2
      if (! coff_write_symbols (abfd))
4143
0
  return false;
4144
2
      if (! coff_write_linenumbers (abfd))
4145
0
  return false;
4146
2
      if (! coff_write_relocs (abfd, firstundef))
4147
0
  return false;
4148
2
    }
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
6
#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
6
  if (obj_raw_syment_count (abfd) != 0)
4162
2
    {
4163
2
      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
2
    }
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
6
  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
6
  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
6
  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
6
  internal_a.entry = bfd_get_start_address (abfd);
4197
6
  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
6
#ifdef COFF_WITH_PE
4296
6
  {
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
6
    struct pe_tdata *pe = pe_data (abfd);
4300
4301
6
    if (pe->build_id.after_write_object_contents != NULL)
4302
0
      (*pe->build_id.after_write_object_contents) (abfd);
4303
6
  }
4304
6
#endif
4305
4306
  /* Now write header.  */
4307
6
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4308
0
    return false;
4309
4310
6
  {
4311
6
    char * buff;
4312
6
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4313
4314
6
    buff = (char *) bfd_malloc (amount);
4315
6
    if (buff == NULL)
4316
0
      return false;
4317
4318
6
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4319
6
    amount = bfd_write (buff, amount, abfd);
4320
4321
6
    free (buff);
4322
4323
6
    if (amount != bfd_coff_filhsz (abfd))
4324
0
      return false;
4325
6
  }
4326
4327
6
  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
6
  return true;
4371
6
}
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
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
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3581
1
  else
3582
1
    {
3583
1
      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
1
    }
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
2
        != 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
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3982
1
  else
3983
1
    {
3984
1
      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
1
    }
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
0
    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
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
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
1
  return true;
4371
1
}
Unexecuted instantiation: pei-arm.c:coff_write_object_contents
Unexecuted instantiation: pei-mcore.c:coff_write_object_contents
pei-sh.c:coff_write_object_contents
Line
Count
Source
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
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
#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
1
#if defined(SH) && defined(COFF_WITH_PE)
4108
1
#define __A_MAGIC_SET__
4109
1
    internal_a.magic = SH_PE_MAGIC;
4110
1
#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
}
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
85
{
4380
85
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
17
    {
4382
17
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
17
    }
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
85
    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
85
#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
85
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
85
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
85
  if (count == 0)
4435
0
    return true;
4436
4437
85
  return bfd_write (location, count, abfd) == count;
4438
85
}
pei-i386.c:coff_set_section_contents
Line
Count
Source
4379
36
{
4380
36
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
7
    {
4382
7
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
7
    }
4385
4386
36
#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
36
    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
36
#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
36
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
36
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
36
  if (count == 0)
4435
0
    return true;
4436
4437
36
  return bfd_write (location, count, abfd) == count;
4438
36
}
Unexecuted instantiation: pe-x86_64.c:coff_set_section_contents
pei-x86_64.c:coff_set_section_contents
Line
Count
Source
4379
37
{
4380
37
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4381
4
    {
4382
4
      if (! coff_compute_section_file_positions (abfd))
4383
0
  return false;
4384
4
    }
4385
4386
37
#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
37
    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
37
#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
37
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
37
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
37
  if (count == 0)
4435
0
    return true;
4436
4437
37
  return bfd_write (location, count, abfd) == count;
4438
37
}
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
Unexecuted instantiation: pei-aarch64.c:coff_set_section_contents
Unexecuted instantiation: pei-ia64.c:coff_set_section_contents
pei-loongarch64.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-riscv64.c:coff_set_section_contents
Line
Count
Source
4379
6
{
4380
6
  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
6
#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
6
    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
6
#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
6
  if (section->filepos == 0)
4429
0
    return true;
4430
4431
6
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4432
0
    return false;
4433
4434
6
  if (count == 0)
4435
0
    return true;
4436
4437
6
  return bfd_write (location, count, abfd) == count;
4438
6
}
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
pei-arm-wince.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-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
19.6k
{
4444
19.6k
  size_t amt;
4445
4446
19.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
19.6k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
315
    return NULL;
4453
19.3k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
19.6k
}
pei-i386.c:buy_and_read
Line
Count
Source
4443
377
{
4444
377
  size_t amt;
4445
4446
377
  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
377
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
377
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
377
}
pe-x86_64.c:buy_and_read
Line
Count
Source
4443
746
{
4444
746
  size_t amt;
4445
4446
746
  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
746
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
746
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
746
}
pei-x86_64.c:buy_and_read
Line
Count
Source
4443
353
{
4444
353
  size_t amt;
4445
4446
353
  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
353
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
353
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
353
}
coff-x86_64.c:buy_and_read
Line
Count
Source
4443
1.44k
{
4444
1.44k
  size_t amt;
4445
4446
1.44k
  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.44k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.44k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.44k
}
coff64-rs6000.c:buy_and_read
Line
Count
Source
4443
696
{
4444
696
  size_t amt;
4445
4446
696
  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
696
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
315
    return NULL;
4453
381
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
696
}
pe-aarch64.c:buy_and_read
Line
Count
Source
4443
599
{
4444
599
  size_t amt;
4445
4446
599
  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
599
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
599
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
599
}
pei-aarch64.c:buy_and_read
Line
Count
Source
4443
325
{
4444
325
  size_t amt;
4445
4446
325
  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
325
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
325
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
325
}
pei-ia64.c:buy_and_read
Line
Count
Source
4443
353
{
4444
353
  size_t amt;
4445
4446
353
  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
353
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
353
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
353
}
pei-loongarch64.c:buy_and_read
Line
Count
Source
4443
289
{
4444
289
  size_t amt;
4445
4446
289
  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
289
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
289
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
289
}
pei-riscv64.c:buy_and_read
Line
Count
Source
4443
332
{
4444
332
  size_t amt;
4445
4446
332
  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
332
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
332
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
332
}
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
674
{
4444
674
  size_t amt;
4445
4446
674
  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
674
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
674
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
674
}
coff-sh.c:buy_and_read
Line
Count
Source
4443
1.53k
{
4444
1.53k
  size_t amt;
4445
4446
1.53k
  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.53k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.53k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.53k
}
Unexecuted instantiation: coff-stgo32.c:buy_and_read
coff-tic30.c:buy_and_read
Line
Count
Source
4443
4.93k
{
4444
4.93k
  size_t amt;
4445
4446
4.93k
  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.93k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
4.93k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
4.93k
}
Unexecuted instantiation: coff-tic4x.c:buy_and_read
coff-tic54x.c:buy_and_read
Line
Count
Source
4443
763
{
4444
763
  size_t amt;
4445
4446
763
  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
763
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
763
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
763
}
coff-z80.c:buy_and_read
Line
Count
Source
4443
2.10k
{
4444
2.10k
  size_t amt;
4445
4446
2.10k
  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.10k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
2.10k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
2.10k
}
coff-z8k.c:buy_and_read
Line
Count
Source
4443
1.58k
{
4444
1.58k
  size_t amt;
4445
4446
1.58k
  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.58k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
1.58k
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
1.58k
}
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
315
{
4444
315
  size_t amt;
4445
4446
315
  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
315
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
315
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
315
}
pe-mcore.c:buy_and_read
Line
Count
Source
4443
459
{
4444
459
  size_t amt;
4445
4446
459
  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
459
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
459
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
459
}
pe-sh.c:buy_and_read
Line
Count
Source
4443
494
{
4444
494
  size_t amt;
4445
4446
494
  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
494
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
494
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
494
}
pei-arm-wince.c:buy_and_read
Line
Count
Source
4443
252
{
4444
252
  size_t amt;
4445
4446
252
  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
252
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
252
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
252
}
pei-arm.c:buy_and_read
Line
Count
Source
4443
411
{
4444
411
  size_t amt;
4445
4446
411
  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
411
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
411
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
411
}
pei-mcore.c:buy_and_read
Line
Count
Source
4443
289
{
4444
289
  size_t amt;
4445
4446
289
  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
289
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
289
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
289
}
pei-sh.c:buy_and_read
Line
Count
Source
4443
299
{
4444
299
  size_t amt;
4445
4446
299
  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
299
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4452
0
    return NULL;
4453
299
  return _bfd_malloc_and_read (abfd, amt, amt);
4454
299
}
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
12.5M
{
4482
12.5M
  const alent *al1 = *(const alent **) arg1;
4483
12.5M
  const alent *al2 = *(const alent **) arg2;
4484
12.5M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
12.5M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
12.5M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
12.5M
  if (s1->symbol.value < s2->symbol.value)
4490
159k
    return -1;
4491
12.3M
  else if (s1->symbol.value > s2->symbol.value)
4492
2.67M
    return 1;
4493
4494
9.72M
  return 0;
4495
12.5M
}
pei-i386.c:coff_sort_func_alent
Line
Count
Source
4481
442k
{
4482
442k
  const alent *al1 = *(const alent **) arg1;
4483
442k
  const alent *al2 = *(const alent **) arg2;
4484
442k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
442k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
442k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
442k
  if (s1->symbol.value < s2->symbol.value)
4490
3.50k
    return -1;
4491
439k
  else if (s1->symbol.value > s2->symbol.value)
4492
84.1k
    return 1;
4493
4494
354k
  return 0;
4495
442k
}
pe-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
262k
{
4482
262k
  const alent *al1 = *(const alent **) arg1;
4483
262k
  const alent *al2 = *(const alent **) arg2;
4484
262k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
262k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
262k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
262k
  if (s1->symbol.value < s2->symbol.value)
4490
5.49k
    return -1;
4491
256k
  else if (s1->symbol.value > s2->symbol.value)
4492
61.2k
    return 1;
4493
4494
195k
  return 0;
4495
262k
}
pei-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
58.0k
{
4482
58.0k
  const alent *al1 = *(const alent **) arg1;
4483
58.0k
  const alent *al2 = *(const alent **) arg2;
4484
58.0k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
58.0k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
58.0k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
58.0k
  if (s1->symbol.value < s2->symbol.value)
4490
832
    return -1;
4491
57.1k
  else if (s1->symbol.value > s2->symbol.value)
4492
7.51k
    return 1;
4493
4494
49.6k
  return 0;
4495
58.0k
}
coff-x86_64.c:coff_sort_func_alent
Line
Count
Source
4481
1.15M
{
4482
1.15M
  const alent *al1 = *(const alent **) arg1;
4483
1.15M
  const alent *al2 = *(const alent **) arg2;
4484
1.15M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.15M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.15M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.15M
  if (s1->symbol.value < s2->symbol.value)
4490
9.89k
    return -1;
4491
1.14M
  else if (s1->symbol.value > s2->symbol.value)
4492
223k
    return 1;
4493
4494
918k
  return 0;
4495
1.15M
}
coff64-rs6000.c:coff_sort_func_alent
Line
Count
Source
4481
113k
{
4482
113k
  const alent *al1 = *(const alent **) arg1;
4483
113k
  const alent *al2 = *(const alent **) arg2;
4484
113k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
113k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
113k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
113k
  if (s1->symbol.value < s2->symbol.value)
4490
1.31k
    return -1;
4491
112k
  else if (s1->symbol.value > s2->symbol.value)
4492
5.22k
    return 1;
4493
4494
106k
  return 0;
4495
113k
}
pe-aarch64.c:coff_sort_func_alent
Line
Count
Source
4481
634k
{
4482
634k
  const alent *al1 = *(const alent **) arg1;
4483
634k
  const alent *al2 = *(const alent **) arg2;
4484
634k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
634k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
634k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
634k
  if (s1->symbol.value < s2->symbol.value)
4490
8.01k
    return -1;
4491
626k
  else if (s1->symbol.value > s2->symbol.value)
4492
185k
    return 1;
4493
4494
441k
  return 0;
4495
634k
}
pei-aarch64.c:coff_sort_func_alent
Line
Count
Source
4481
491k
{
4482
491k
  const alent *al1 = *(const alent **) arg1;
4483
491k
  const alent *al2 = *(const alent **) arg2;
4484
491k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
491k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
491k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
491k
  if (s1->symbol.value < s2->symbol.value)
4490
5.53k
    return -1;
4491
485k
  else if (s1->symbol.value > s2->symbol.value)
4492
66.0k
    return 1;
4493
4494
419k
  return 0;
4495
491k
}
pei-ia64.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.96k
    return -1;
4491
374k
  else if (s1->symbol.value > s2->symbol.value)
4492
65.1k
    return 1;
4493
4494
309k
  return 0;
4495
379k
}
pei-loongarch64.c:coff_sort_func_alent
Line
Count
Source
4481
2.12M
{
4482
2.12M
  const alent *al1 = *(const alent **) arg1;
4483
2.12M
  const alent *al2 = *(const alent **) arg2;
4484
2.12M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
2.12M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
2.12M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
2.12M
  if (s1->symbol.value < s2->symbol.value)
4490
25.3k
    return -1;
4491
2.09M
  else if (s1->symbol.value > s2->symbol.value)
4492
634k
    return 1;
4493
4494
1.46M
  return 0;
4495
2.12M
}
pei-riscv64.c:coff_sort_func_alent
Line
Count
Source
4481
167k
{
4482
167k
  const alent *al1 = *(const alent **) arg1;
4483
167k
  const alent *al2 = *(const alent **) arg2;
4484
167k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
167k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
167k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
167k
  if (s1->symbol.value < s2->symbol.value)
4490
3.14k
    return -1;
4491
164k
  else if (s1->symbol.value > s2->symbol.value)
4492
48.7k
    return 1;
4493
4494
115k
  return 0;
4495
167k
}
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
249k
{
4482
249k
  const alent *al1 = *(const alent **) arg1;
4483
249k
  const alent *al2 = *(const alent **) arg2;
4484
249k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
249k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
249k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
249k
  if (s1->symbol.value < s2->symbol.value)
4490
1.99k
    return -1;
4491
247k
  else if (s1->symbol.value > s2->symbol.value)
4492
48.5k
    return 1;
4493
4494
198k
  return 0;
4495
249k
}
coff-sh.c:coff_sort_func_alent
Line
Count
Source
4481
1.38M
{
4482
1.38M
  const alent *al1 = *(const alent **) arg1;
4483
1.38M
  const alent *al2 = *(const alent **) arg2;
4484
1.38M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.38M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.38M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.38M
  if (s1->symbol.value < s2->symbol.value)
4490
18.7k
    return -1;
4491
1.36M
  else if (s1->symbol.value > s2->symbol.value)
4492
130k
    return 1;
4493
4494
1.23M
  return 0;
4495
1.38M
}
Unexecuted instantiation: coff-stgo32.c:coff_sort_func_alent
coff-tic30.c:coff_sort_func_alent
Line
Count
Source
4481
403k
{
4482
403k
  const alent *al1 = *(const alent **) arg1;
4483
403k
  const alent *al2 = *(const alent **) arg2;
4484
403k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
403k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
403k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
403k
  if (s1->symbol.value < s2->symbol.value)
4490
6.39k
    return -1;
4491
397k
  else if (s1->symbol.value > s2->symbol.value)
4492
42.0k
    return 1;
4493
4494
355k
  return 0;
4495
403k
}
Unexecuted instantiation: coff-tic4x.c:coff_sort_func_alent
coff-tic54x.c:coff_sort_func_alent
Line
Count
Source
4481
1.07M
{
4482
1.07M
  const alent *al1 = *(const alent **) arg1;
4483
1.07M
  const alent *al2 = *(const alent **) arg2;
4484
1.07M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.07M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.07M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.07M
  if (s1->symbol.value < s2->symbol.value)
4490
12.4k
    return -1;
4491
1.06M
  else if (s1->symbol.value > s2->symbol.value)
4492
209k
    return 1;
4493
4494
852k
  return 0;
4495
1.07M
}
coff-z80.c:coff_sort_func_alent
Line
Count
Source
4481
222k
{
4482
222k
  const alent *al1 = *(const alent **) arg1;
4483
222k
  const alent *al2 = *(const alent **) arg2;
4484
222k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
222k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
222k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
222k
  if (s1->symbol.value < s2->symbol.value)
4490
3.45k
    return -1;
4491
219k
  else if (s1->symbol.value > s2->symbol.value)
4492
21.7k
    return 1;
4493
4494
197k
  return 0;
4495
222k
}
coff-z8k.c:coff_sort_func_alent
Line
Count
Source
4481
378k
{
4482
378k
  const alent *al1 = *(const alent **) arg1;
4483
378k
  const alent *al2 = *(const alent **) arg2;
4484
378k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
378k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
378k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
378k
  if (s1->symbol.value < s2->symbol.value)
4490
711
    return -1;
4491
378k
  else if (s1->symbol.value > s2->symbol.value)
4492
53.4k
    return 1;
4493
4494
324k
  return 0;
4495
378k
}
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
260k
{
4482
260k
  const alent *al1 = *(const alent **) arg1;
4483
260k
  const alent *al2 = *(const alent **) arg2;
4484
260k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
260k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
260k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
260k
  if (s1->symbol.value < s2->symbol.value)
4490
4.77k
    return -1;
4491
255k
  else if (s1->symbol.value > s2->symbol.value)
4492
72.7k
    return 1;
4493
4494
183k
  return 0;
4495
260k
}
pe-mcore.c:coff_sort_func_alent
Line
Count
Source
4481
1.00M
{
4482
1.00M
  const alent *al1 = *(const alent **) arg1;
4483
1.00M
  const alent *al2 = *(const alent **) arg2;
4484
1.00M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
1.00M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
1.00M
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
1.00M
  if (s1->symbol.value < s2->symbol.value)
4490
5.80k
    return -1;
4491
1.00M
  else if (s1->symbol.value > s2->symbol.value)
4492
280k
    return 1;
4493
4494
719k
  return 0;
4495
1.00M
}
pe-sh.c:coff_sort_func_alent
Line
Count
Source
4481
852k
{
4482
852k
  const alent *al1 = *(const alent **) arg1;
4483
852k
  const alent *al2 = *(const alent **) arg2;
4484
852k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
852k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
852k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
852k
  if (s1->symbol.value < s2->symbol.value)
4490
21.6k
    return -1;
4491
830k
  else if (s1->symbol.value > s2->symbol.value)
4492
251k
    return 1;
4493
4494
578k
  return 0;
4495
852k
}
pei-arm-wince.c:coff_sort_func_alent
Line
Count
Source
4481
420k
{
4482
420k
  const alent *al1 = *(const alent **) arg1;
4483
420k
  const alent *al2 = *(const alent **) arg2;
4484
420k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
420k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
420k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
420k
  if (s1->symbol.value < s2->symbol.value)
4490
8.35k
    return -1;
4491
412k
  else if (s1->symbol.value > s2->symbol.value)
4492
103k
    return 1;
4493
4494
308k
  return 0;
4495
420k
}
pei-arm.c:coff_sort_func_alent
Line
Count
Source
4481
237k
{
4482
237k
  const alent *al1 = *(const alent **) arg1;
4483
237k
  const alent *al2 = *(const alent **) arg2;
4484
237k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
237k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
237k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
237k
  if (s1->symbol.value < s2->symbol.value)
4490
3.65k
    return -1;
4491
234k
  else if (s1->symbol.value > s2->symbol.value)
4492
41.0k
    return 1;
4493
4494
192k
  return 0;
4495
237k
}
pei-mcore.c:coff_sort_func_alent
Line
Count
Source
4481
28.6k
{
4482
28.6k
  const alent *al1 = *(const alent **) arg1;
4483
28.6k
  const alent *al2 = *(const alent **) arg2;
4484
28.6k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
28.6k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
28.6k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
28.6k
  if (s1->symbol.value < s2->symbol.value)
4490
791
    return -1;
4491
27.8k
  else if (s1->symbol.value > s2->symbol.value)
4492
3.35k
    return 1;
4493
4494
24.4k
  return 0;
4495
28.6k
}
pei-sh.c:coff_sort_func_alent
Line
Count
Source
4481
209k
{
4482
209k
  const alent *al1 = *(const alent **) arg1;
4483
209k
  const alent *al2 = *(const alent **) arg2;
4484
209k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4485
209k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4486
4487
209k
  if (s1 == NULL || s2 == NULL)
4488
0
    return 0;
4489
209k
  if (s1->symbol.value < s2->symbol.value)
4490
2.58k
    return -1;
4491
207k
  else if (s1->symbol.value > s2->symbol.value)
4492
35.7k
    return 1;
4493
4494
171k
  return 0;
4495
209k
}
4496
4497
static bool
4498
coff_slurp_line_table (bfd *abfd, asection *asect)
4499
44.6k
{
4500
44.6k
  LINENO *native_lineno;
4501
44.6k
  alent *lineno_cache;
4502
44.6k
  unsigned int counter;
4503
44.6k
  alent *cache_ptr;
4504
44.6k
  bfd_vma prev_offset = 0;
4505
44.6k
  bool ordered = true;
4506
44.6k
  unsigned int nbr_func;
4507
44.6k
  LINENO *src;
4508
44.6k
  bool have_func;
4509
44.6k
  bool ret = true;
4510
44.6k
  size_t amt;
4511
4512
44.6k
  if (asect->lineno_count == 0)
4513
34.3k
    return true;
4514
4515
10.2k
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
10.2k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
10.2k
             asect->lineno_count,
4519
10.2k
             bfd_coff_linesz (abfd));
4520
10.2k
  if (native_lineno == NULL)
4521
5.20k
    {
4522
5.20k
      _bfd_error_handler
4523
5.20k
  (_("%pB: warning: line number table read failed"), abfd);
4524
5.20k
      return false;
4525
5.20k
    }
4526
4527
5.07k
  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
5.07k
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
5.07k
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
5.07k
  cache_ptr = lineno_cache;
4541
5.07k
  asect->lineno = lineno_cache;
4542
5.07k
  src = native_lineno;
4543
5.07k
  nbr_func = 0;
4544
5.07k
  have_func = false;
4545
4546
10.6M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
10.6M
    {
4548
10.6M
      struct internal_lineno dst;
4549
4550
10.6M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
10.6M
      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
10.6M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
10.6M
      if (cache_ptr->line_number == 0)
4558
3.95M
  {
4559
3.95M
    combined_entry_type * ent;
4560
3.95M
    unsigned long symndx;
4561
3.95M
    coff_symbol_type *sym;
4562
4563
3.95M
    have_func = false;
4564
3.95M
    symndx = dst.l_addr.l_symndx;
4565
3.95M
    if (symndx >= obj_raw_syment_count (abfd))
4566
1.66M
      {
4567
1.66M
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
1.66M
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
1.66M
     abfd, symndx, counter);
4571
1.66M
        cache_ptr->line_number = -1;
4572
1.66M
        ret = false;
4573
1.66M
        continue;
4574
1.66M
      }
4575
4576
2.28M
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
2.28M
    if (! ent->is_sym)
4580
339k
      {
4581
339k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
339k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
339k
     abfd, symndx, counter);
4585
339k
        cache_ptr->line_number = -1;
4586
339k
        ret = false;
4587
339k
        continue;
4588
339k
      }
4589
1.95M
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
1.95M
    if (sym < obj_symbols (abfd)
4593
1.95M
        || 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
1.95M
    have_func = true;
4605
1.95M
    nbr_func++;
4606
1.95M
    cache_ptr->u.sym = (asymbol *) sym;
4607
1.95M
    if (sym->lineno != NULL)
4608
1.92M
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
1.92M
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
1.92M
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
1.95M
    sym->lineno = cache_ptr;
4614
1.95M
    if (sym->symbol.value < prev_offset)
4615
47.3k
      ordered = false;
4616
1.95M
    prev_offset = sym->symbol.value;
4617
1.95M
  }
4618
6.72M
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
4.59M
  continue;
4622
2.12M
      else
4623
2.12M
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
4.07M
      cache_ptr++;
4625
4.07M
    }
4626
4627
5.07k
  asect->lineno_count = cache_ptr - lineno_cache;
4628
5.07k
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
5.07k
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
5.07k
  if (!ordered)
4633
2.51k
    {
4634
      /* Sort the table.  */
4635
2.51k
      alent **func_table;
4636
2.51k
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
2.51k
      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
2.51k
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
2.51k
  {
4646
2.51k
    alent **p = func_table;
4647
2.51k
    unsigned int i;
4648
4649
3.77M
    for (i = 0; i < asect->lineno_count; i++)
4650
3.77M
      if (lineno_cache[i].line_number == 0)
4651
1.77M
        *p++ = &lineno_cache[i];
4652
4653
2.51k
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
2.51k
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
2.51k
    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
2.51k
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
2.51k
      {
4666
2.51k
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
1.77M
        for (i = 0; i < nbr_func; i++)
4669
1.77M
    {
4670
1.77M
      coff_symbol_type *sym;
4671
1.77M
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
1.77M
      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
1.77M
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
1.77M
      do
4680
3.77M
        *n_cache_ptr++ = *old_ptr++;
4681
3.77M
      while (old_ptr->line_number != 0);
4682
1.77M
    }
4683
4684
2.51k
        memcpy (lineno_cache, n_lineno_cache,
4685
2.51k
          asect->lineno_count * sizeof (alent));
4686
2.51k
      }
4687
0
    else
4688
0
      ret = false;
4689
2.51k
    bfd_release (abfd, func_table);
4690
2.51k
  }
4691
0
      else
4692
0
  ret = false;
4693
2.51k
    }
4694
4695
5.07k
  return ret;
4696
5.07k
}
pei-i386.c:coff_slurp_line_table
Line
Count
Source
4499
720
{
4500
720
  LINENO *native_lineno;
4501
720
  alent *lineno_cache;
4502
720
  unsigned int counter;
4503
720
  alent *cache_ptr;
4504
720
  bfd_vma prev_offset = 0;
4505
720
  bool ordered = true;
4506
720
  unsigned int nbr_func;
4507
720
  LINENO *src;
4508
720
  bool have_func;
4509
720
  bool ret = true;
4510
720
  size_t amt;
4511
4512
720
  if (asect->lineno_count == 0)
4513
343
    return true;
4514
4515
377
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
377
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
377
             asect->lineno_count,
4519
377
             bfd_coff_linesz (abfd));
4520
377
  if (native_lineno == NULL)
4521
233
    {
4522
233
      _bfd_error_handler
4523
233
  (_("%pB: warning: line number table read failed"), abfd);
4524
233
      return false;
4525
233
    }
4526
4527
144
  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
144
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
144
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
144
  cache_ptr = lineno_cache;
4541
144
  asect->lineno = lineno_cache;
4542
144
  src = native_lineno;
4543
144
  nbr_func = 0;
4544
144
  have_func = false;
4545
4546
379k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
378k
    {
4548
378k
      struct internal_lineno dst;
4549
4550
378k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
378k
      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
378k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
378k
      if (cache_ptr->line_number == 0)
4558
122k
  {
4559
122k
    combined_entry_type * ent;
4560
122k
    unsigned long symndx;
4561
122k
    coff_symbol_type *sym;
4562
4563
122k
    have_func = false;
4564
122k
    symndx = dst.l_addr.l_symndx;
4565
122k
    if (symndx >= obj_raw_syment_count (abfd))
4566
48.4k
      {
4567
48.4k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
48.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
48.4k
     abfd, symndx, counter);
4571
48.4k
        cache_ptr->line_number = -1;
4572
48.4k
        ret = false;
4573
48.4k
        continue;
4574
48.4k
      }
4575
4576
74.3k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
74.3k
    if (! ent->is_sym)
4580
4.97k
      {
4581
4.97k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
4.97k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
4.97k
     abfd, symndx, counter);
4585
4.97k
        cache_ptr->line_number = -1;
4586
4.97k
        ret = false;
4587
4.97k
        continue;
4588
4.97k
      }
4589
69.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
69.3k
    if (sym < obj_symbols (abfd)
4593
69.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
69.3k
    have_func = true;
4605
69.3k
    nbr_func++;
4606
69.3k
    cache_ptr->u.sym = (asymbol *) sym;
4607
69.3k
    if (sym->lineno != NULL)
4608
68.5k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
68.5k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
68.5k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
69.3k
    sym->lineno = cache_ptr;
4614
69.3k
    if (sym->symbol.value < prev_offset)
4615
1.21k
      ordered = false;
4616
69.3k
    prev_offset = sym->symbol.value;
4617
69.3k
  }
4618
256k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
214k
  continue;
4622
41.8k
      else
4623
41.8k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
111k
      cache_ptr++;
4625
111k
    }
4626
4627
144
  asect->lineno_count = cache_ptr - lineno_cache;
4628
144
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
144
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
144
  if (!ordered)
4633
78
    {
4634
      /* Sort the table.  */
4635
78
      alent **func_table;
4636
78
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
78
      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
78
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
78
  {
4646
78
    alent **p = func_table;
4647
78
    unsigned int i;
4648
4649
107k
    for (i = 0; i < asect->lineno_count; i++)
4650
107k
      if (lineno_cache[i].line_number == 0)
4651
67.0k
        *p++ = &lineno_cache[i];
4652
4653
78
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
78
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
78
    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
78
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
78
      {
4666
78
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
67.1k
        for (i = 0; i < nbr_func; i++)
4669
67.0k
    {
4670
67.0k
      coff_symbol_type *sym;
4671
67.0k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
67.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
67.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
67.0k
      do
4680
107k
        *n_cache_ptr++ = *old_ptr++;
4681
107k
      while (old_ptr->line_number != 0);
4682
67.0k
    }
4683
4684
78
        memcpy (lineno_cache, n_lineno_cache,
4685
78
          asect->lineno_count * sizeof (alent));
4686
78
      }
4687
0
    else
4688
0
      ret = false;
4689
78
    bfd_release (abfd, func_table);
4690
78
  }
4691
0
      else
4692
0
  ret = false;
4693
78
    }
4694
4695
144
  return ret;
4696
144
}
pe-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
3.06k
{
4500
3.06k
  LINENO *native_lineno;
4501
3.06k
  alent *lineno_cache;
4502
3.06k
  unsigned int counter;
4503
3.06k
  alent *cache_ptr;
4504
3.06k
  bfd_vma prev_offset = 0;
4505
3.06k
  bool ordered = true;
4506
3.06k
  unsigned int nbr_func;
4507
3.06k
  LINENO *src;
4508
3.06k
  bool have_func;
4509
3.06k
  bool ret = true;
4510
3.06k
  size_t amt;
4511
4512
3.06k
  if (asect->lineno_count == 0)
4513
2.54k
    return true;
4514
4515
521
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
521
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
521
             asect->lineno_count,
4519
521
             bfd_coff_linesz (abfd));
4520
521
  if (native_lineno == NULL)
4521
259
    {
4522
259
      _bfd_error_handler
4523
259
  (_("%pB: warning: line number table read failed"), abfd);
4524
259
      return false;
4525
259
    }
4526
4527
262
  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
262
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
262
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
262
  cache_ptr = lineno_cache;
4541
262
  asect->lineno = lineno_cache;
4542
262
  src = native_lineno;
4543
262
  nbr_func = 0;
4544
262
  have_func = false;
4545
4546
213k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
213k
    {
4548
213k
      struct internal_lineno dst;
4549
4550
213k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
213k
      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
213k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
213k
      if (cache_ptr->line_number == 0)
4558
82.4k
  {
4559
82.4k
    combined_entry_type * ent;
4560
82.4k
    unsigned long symndx;
4561
82.4k
    coff_symbol_type *sym;
4562
4563
82.4k
    have_func = false;
4564
82.4k
    symndx = dst.l_addr.l_symndx;
4565
82.4k
    if (symndx >= obj_raw_syment_count (abfd))
4566
36.3k
      {
4567
36.3k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
36.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
36.3k
     abfd, symndx, counter);
4571
36.3k
        cache_ptr->line_number = -1;
4572
36.3k
        ret = false;
4573
36.3k
        continue;
4574
36.3k
      }
4575
4576
46.1k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
46.1k
    if (! ent->is_sym)
4580
3.87k
      {
4581
3.87k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
3.87k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
3.87k
     abfd, symndx, counter);
4585
3.87k
        cache_ptr->line_number = -1;
4586
3.87k
        ret = false;
4587
3.87k
        continue;
4588
3.87k
      }
4589
42.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
42.2k
    if (sym < obj_symbols (abfd)
4593
42.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
42.2k
    have_func = true;
4605
42.2k
    nbr_func++;
4606
42.2k
    cache_ptr->u.sym = (asymbol *) sym;
4607
42.2k
    if (sym->lineno != NULL)
4608
41.5k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
41.5k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
41.5k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
42.2k
    sym->lineno = cache_ptr;
4614
42.2k
    if (sym->symbol.value < prev_offset)
4615
1.50k
      ordered = false;
4616
42.2k
    prev_offset = sym->symbol.value;
4617
42.2k
  }
4618
130k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
57.9k
  continue;
4622
72.7k
      else
4623
72.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
114k
      cache_ptr++;
4625
114k
    }
4626
4627
262
  asect->lineno_count = cache_ptr - lineno_cache;
4628
262
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
262
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
262
  if (!ordered)
4633
102
    {
4634
      /* Sort the table.  */
4635
102
      alent **func_table;
4636
102
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
102
      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
102
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
102
  {
4646
102
    alent **p = func_table;
4647
102
    unsigned int i;
4648
4649
108k
    for (i = 0; i < asect->lineno_count; i++)
4650
108k
      if (lineno_cache[i].line_number == 0)
4651
39.7k
        *p++ = &lineno_cache[i];
4652
4653
102
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
102
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
102
    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
102
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
102
      {
4666
102
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
39.8k
        for (i = 0; i < nbr_func; i++)
4669
39.7k
    {
4670
39.7k
      coff_symbol_type *sym;
4671
39.7k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
39.7k
      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
39.7k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
39.7k
      do
4680
108k
        *n_cache_ptr++ = *old_ptr++;
4681
108k
      while (old_ptr->line_number != 0);
4682
39.7k
    }
4683
4684
102
        memcpy (lineno_cache, n_lineno_cache,
4685
102
          asect->lineno_count * sizeof (alent));
4686
102
      }
4687
0
    else
4688
0
      ret = false;
4689
102
    bfd_release (abfd, func_table);
4690
102
  }
4691
0
      else
4692
0
  ret = false;
4693
102
    }
4694
4695
262
  return ret;
4696
262
}
pei-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
2.29k
{
4500
2.29k
  LINENO *native_lineno;
4501
2.29k
  alent *lineno_cache;
4502
2.29k
  unsigned int counter;
4503
2.29k
  alent *cache_ptr;
4504
2.29k
  bfd_vma prev_offset = 0;
4505
2.29k
  bool ordered = true;
4506
2.29k
  unsigned int nbr_func;
4507
2.29k
  LINENO *src;
4508
2.29k
  bool have_func;
4509
2.29k
  bool ret = true;
4510
2.29k
  size_t amt;
4511
4512
2.29k
  if (asect->lineno_count == 0)
4513
1.94k
    return true;
4514
4515
353
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
353
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
353
             asect->lineno_count,
4519
353
             bfd_coff_linesz (abfd));
4520
353
  if (native_lineno == NULL)
4521
197
    {
4522
197
      _bfd_error_handler
4523
197
  (_("%pB: warning: line number table read failed"), abfd);
4524
197
      return false;
4525
197
    }
4526
4527
156
  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
156
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
156
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
156
  cache_ptr = lineno_cache;
4541
156
  asect->lineno = lineno_cache;
4542
156
  src = native_lineno;
4543
156
  nbr_func = 0;
4544
156
  have_func = false;
4545
4546
76.5k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
76.4k
    {
4548
76.4k
      struct internal_lineno dst;
4549
4550
76.4k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
76.4k
      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
76.4k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
76.4k
      if (cache_ptr->line_number == 0)
4558
29.1k
  {
4559
29.1k
    combined_entry_type * ent;
4560
29.1k
    unsigned long symndx;
4561
29.1k
    coff_symbol_type *sym;
4562
4563
29.1k
    have_func = false;
4564
29.1k
    symndx = dst.l_addr.l_symndx;
4565
29.1k
    if (symndx >= obj_raw_syment_count (abfd))
4566
14.1k
      {
4567
14.1k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
14.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
14.1k
     abfd, symndx, counter);
4571
14.1k
        cache_ptr->line_number = -1;
4572
14.1k
        ret = false;
4573
14.1k
        continue;
4574
14.1k
      }
4575
4576
15.0k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
15.0k
    if (! ent->is_sym)
4580
1.51k
      {
4581
1.51k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
1.51k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
1.51k
     abfd, symndx, counter);
4585
1.51k
        cache_ptr->line_number = -1;
4586
1.51k
        ret = false;
4587
1.51k
        continue;
4588
1.51k
      }
4589
13.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
13.4k
    if (sym < obj_symbols (abfd)
4593
13.4k
        || 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
13.4k
    have_func = true;
4605
13.4k
    nbr_func++;
4606
13.4k
    cache_ptr->u.sym = (asymbol *) sym;
4607
13.4k
    if (sym->lineno != NULL)
4608
13.1k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
13.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
13.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
13.4k
    sym->lineno = cache_ptr;
4614
13.4k
    if (sym->symbol.value < prev_offset)
4615
309
      ordered = false;
4616
13.4k
    prev_offset = sym->symbol.value;
4617
13.4k
  }
4618
47.2k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
39.1k
  continue;
4622
8.12k
      else
4623
8.12k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
21.6k
      cache_ptr++;
4625
21.6k
    }
4626
4627
156
  asect->lineno_count = cache_ptr - lineno_cache;
4628
156
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
156
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
156
  if (!ordered)
4633
75
    {
4634
      /* Sort the table.  */
4635
75
      alent **func_table;
4636
75
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
75
      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
75
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
75
  {
4646
75
    alent **p = func_table;
4647
75
    unsigned int i;
4648
4649
19.7k
    for (i = 0; i < asect->lineno_count; i++)
4650
19.6k
      if (lineno_cache[i].line_number == 0)
4651
12.2k
        *p++ = &lineno_cache[i];
4652
4653
75
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
75
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
75
    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
75
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
75
      {
4666
75
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
12.2k
        for (i = 0; i < nbr_func; i++)
4669
12.2k
    {
4670
12.2k
      coff_symbol_type *sym;
4671
12.2k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
12.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
12.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
12.2k
      do
4680
19.6k
        *n_cache_ptr++ = *old_ptr++;
4681
19.6k
      while (old_ptr->line_number != 0);
4682
12.2k
    }
4683
4684
75
        memcpy (lineno_cache, n_lineno_cache,
4685
75
          asect->lineno_count * sizeof (alent));
4686
75
      }
4687
0
    else
4688
0
      ret = false;
4689
75
    bfd_release (abfd, func_table);
4690
75
  }
4691
0
      else
4692
0
  ret = false;
4693
75
    }
4694
4695
156
  return ret;
4696
156
}
coff-x86_64.c:coff_slurp_line_table
Line
Count
Source
4499
6.16k
{
4500
6.16k
  LINENO *native_lineno;
4501
6.16k
  alent *lineno_cache;
4502
6.16k
  unsigned int counter;
4503
6.16k
  alent *cache_ptr;
4504
6.16k
  bfd_vma prev_offset = 0;
4505
6.16k
  bool ordered = true;
4506
6.16k
  unsigned int nbr_func;
4507
6.16k
  LINENO *src;
4508
6.16k
  bool have_func;
4509
6.16k
  bool ret = true;
4510
6.16k
  size_t amt;
4511
4512
6.16k
  if (asect->lineno_count == 0)
4513
5.37k
    return true;
4514
4515
782
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
782
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
782
             asect->lineno_count,
4519
782
             bfd_coff_linesz (abfd));
4520
782
  if (native_lineno == NULL)
4521
445
    {
4522
445
      _bfd_error_handler
4523
445
  (_("%pB: warning: line number table read failed"), abfd);
4524
445
      return false;
4525
445
    }
4526
4527
337
  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
337
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
337
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
337
  cache_ptr = lineno_cache;
4541
337
  asect->lineno = lineno_cache;
4542
337
  src = native_lineno;
4543
337
  nbr_func = 0;
4544
337
  have_func = false;
4545
4546
1.10M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.10M
    {
4548
1.10M
      struct internal_lineno dst;
4549
4550
1.10M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.10M
      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.10M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.10M
      if (cache_ptr->line_number == 0)
4558
392k
  {
4559
392k
    combined_entry_type * ent;
4560
392k
    unsigned long symndx;
4561
392k
    coff_symbol_type *sym;
4562
4563
392k
    have_func = false;
4564
392k
    symndx = dst.l_addr.l_symndx;
4565
392k
    if (symndx >= obj_raw_syment_count (abfd))
4566
180k
      {
4567
180k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
180k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
180k
     abfd, symndx, counter);
4571
180k
        cache_ptr->line_number = -1;
4572
180k
        ret = false;
4573
180k
        continue;
4574
180k
      }
4575
4576
211k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
211k
    if (! ent->is_sym)
4580
34.9k
      {
4581
34.9k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
34.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
34.9k
     abfd, symndx, counter);
4585
34.9k
        cache_ptr->line_number = -1;
4586
34.9k
        ret = false;
4587
34.9k
        continue;
4588
34.9k
      }
4589
176k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
176k
    if (sym < obj_symbols (abfd)
4593
176k
        || 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
176k
    have_func = true;
4605
176k
    nbr_func++;
4606
176k
    cache_ptr->u.sym = (asymbol *) sym;
4607
176k
    if (sym->lineno != NULL)
4608
175k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
175k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
175k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
176k
    sym->lineno = cache_ptr;
4614
176k
    if (sym->symbol.value < prev_offset)
4615
2.79k
      ordered = false;
4616
176k
    prev_offset = sym->symbol.value;
4617
176k
  }
4618
716k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
503k
  continue;
4622
212k
      else
4623
212k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
389k
      cache_ptr++;
4625
389k
    }
4626
4627
337
  asect->lineno_count = cache_ptr - lineno_cache;
4628
337
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
337
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
337
  if (!ordered)
4633
160
    {
4634
      /* Sort the table.  */
4635
160
      alent **func_table;
4636
160
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
160
      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
160
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
160
  {
4646
160
    alent **p = func_table;
4647
160
    unsigned int i;
4648
4649
333k
    for (i = 0; i < asect->lineno_count; i++)
4650
332k
      if (lineno_cache[i].line_number == 0)
4651
159k
        *p++ = &lineno_cache[i];
4652
4653
160
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
160
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
160
    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
160
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
160
      {
4666
160
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
159k
        for (i = 0; i < nbr_func; i++)
4669
159k
    {
4670
159k
      coff_symbol_type *sym;
4671
159k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
159k
      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
159k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
159k
      do
4680
332k
        *n_cache_ptr++ = *old_ptr++;
4681
332k
      while (old_ptr->line_number != 0);
4682
159k
    }
4683
4684
160
        memcpy (lineno_cache, n_lineno_cache,
4685
160
          asect->lineno_count * sizeof (alent));
4686
160
      }
4687
0
    else
4688
0
      ret = false;
4689
160
    bfd_release (abfd, func_table);
4690
160
  }
4691
0
      else
4692
0
  ret = false;
4693
160
    }
4694
4695
337
  return ret;
4696
337
}
coff64-rs6000.c:coff_slurp_line_table
Line
Count
Source
4499
3.19k
{
4500
3.19k
  LINENO *native_lineno;
4501
3.19k
  alent *lineno_cache;
4502
3.19k
  unsigned int counter;
4503
3.19k
  alent *cache_ptr;
4504
3.19k
  bfd_vma prev_offset = 0;
4505
3.19k
  bool ordered = true;
4506
3.19k
  unsigned int nbr_func;
4507
3.19k
  LINENO *src;
4508
3.19k
  bool have_func;
4509
3.19k
  bool ret = true;
4510
3.19k
  size_t amt;
4511
4512
3.19k
  if (asect->lineno_count == 0)
4513
2.55k
    return true;
4514
4515
646
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
646
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
646
             asect->lineno_count,
4519
646
             bfd_coff_linesz (abfd));
4520
646
  if (native_lineno == NULL)
4521
426
    {
4522
426
      _bfd_error_handler
4523
426
  (_("%pB: warning: line number table read failed"), abfd);
4524
426
      return false;
4525
426
    }
4526
4527
220
  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
220
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
220
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
220
  cache_ptr = lineno_cache;
4541
220
  asect->lineno = lineno_cache;
4542
220
  src = native_lineno;
4543
220
  nbr_func = 0;
4544
220
  have_func = false;
4545
4546
163k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
163k
    {
4548
163k
      struct internal_lineno dst;
4549
4550
163k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
163k
      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
163k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
163k
      if (cache_ptr->line_number == 0)
4558
71.4k
  {
4559
71.4k
    combined_entry_type * ent;
4560
71.4k
    unsigned long symndx;
4561
71.4k
    coff_symbol_type *sym;
4562
4563
71.4k
    have_func = false;
4564
71.4k
    symndx = dst.l_addr.l_symndx;
4565
71.4k
    if (symndx >= obj_raw_syment_count (abfd))
4566
11.8k
      {
4567
11.8k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
11.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
11.8k
     abfd, symndx, counter);
4571
11.8k
        cache_ptr->line_number = -1;
4572
11.8k
        ret = false;
4573
11.8k
        continue;
4574
11.8k
      }
4575
4576
59.6k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
59.6k
    if (! ent->is_sym)
4580
829
      {
4581
829
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
829
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
829
     abfd, symndx, counter);
4585
829
        cache_ptr->line_number = -1;
4586
829
        ret = false;
4587
829
        continue;
4588
829
      }
4589
58.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
58.8k
    if (sym < obj_symbols (abfd)
4593
58.8k
        || 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.8k
    have_func = true;
4605
58.8k
    nbr_func++;
4606
58.8k
    cache_ptr->u.sym = (asymbol *) sym;
4607
58.8k
    if (sym->lineno != NULL)
4608
58.1k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
58.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
58.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
58.8k
    sym->lineno = cache_ptr;
4614
58.8k
    if (sym->symbol.value < prev_offset)
4615
526
      ordered = false;
4616
58.8k
    prev_offset = sym->symbol.value;
4617
58.8k
  }
4618
92.2k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
53.0k
  continue;
4622
39.2k
      else
4623
39.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
98.0k
      cache_ptr++;
4625
98.0k
    }
4626
4627
220
  asect->lineno_count = cache_ptr - lineno_cache;
4628
220
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
220
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
220
  if (!ordered)
4633
118
    {
4634
      /* Sort the table.  */
4635
118
      alent **func_table;
4636
118
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
118
      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
118
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
118
  {
4646
118
    alent **p = func_table;
4647
118
    unsigned int i;
4648
4649
51.9k
    for (i = 0; i < asect->lineno_count; i++)
4650
51.7k
      if (lineno_cache[i].line_number == 0)
4651
23.8k
        *p++ = &lineno_cache[i];
4652
4653
118
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
118
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
118
    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
118
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
118
      {
4666
118
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
23.9k
        for (i = 0; i < nbr_func; i++)
4669
23.8k
    {
4670
23.8k
      coff_symbol_type *sym;
4671
23.8k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
23.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
23.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
23.8k
      do
4680
51.7k
        *n_cache_ptr++ = *old_ptr++;
4681
51.7k
      while (old_ptr->line_number != 0);
4682
23.8k
    }
4683
4684
118
        memcpy (lineno_cache, n_lineno_cache,
4685
118
          asect->lineno_count * sizeof (alent));
4686
118
      }
4687
0
    else
4688
0
      ret = false;
4689
118
    bfd_release (abfd, func_table);
4690
118
  }
4691
0
      else
4692
0
  ret = false;
4693
118
    }
4694
4695
220
  return ret;
4696
220
}
pe-aarch64.c:coff_slurp_line_table
Line
Count
Source
4499
1.54k
{
4500
1.54k
  LINENO *native_lineno;
4501
1.54k
  alent *lineno_cache;
4502
1.54k
  unsigned int counter;
4503
1.54k
  alent *cache_ptr;
4504
1.54k
  bfd_vma prev_offset = 0;
4505
1.54k
  bool ordered = true;
4506
1.54k
  unsigned int nbr_func;
4507
1.54k
  LINENO *src;
4508
1.54k
  bool have_func;
4509
1.54k
  bool ret = true;
4510
1.54k
  size_t amt;
4511
4512
1.54k
  if (asect->lineno_count == 0)
4513
1.08k
    return true;
4514
4515
464
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
464
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
464
             asect->lineno_count,
4519
464
             bfd_coff_linesz (abfd));
4520
464
  if (native_lineno == NULL)
4521
250
    {
4522
250
      _bfd_error_handler
4523
250
  (_("%pB: warning: line number table read failed"), abfd);
4524
250
      return false;
4525
250
    }
4526
4527
214
  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
214
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
214
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
214
  cache_ptr = lineno_cache;
4541
214
  asect->lineno = lineno_cache;
4542
214
  src = native_lineno;
4543
214
  nbr_func = 0;
4544
214
  have_func = false;
4545
4546
400k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
400k
    {
4548
400k
      struct internal_lineno dst;
4549
4550
400k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
400k
      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
400k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
400k
      if (cache_ptr->line_number == 0)
4558
143k
  {
4559
143k
    combined_entry_type * ent;
4560
143k
    unsigned long symndx;
4561
143k
    coff_symbol_type *sym;
4562
4563
143k
    have_func = false;
4564
143k
    symndx = dst.l_addr.l_symndx;
4565
143k
    if (symndx >= obj_raw_syment_count (abfd))
4566
52.6k
      {
4567
52.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
52.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
52.6k
     abfd, symndx, counter);
4571
52.6k
        cache_ptr->line_number = -1;
4572
52.6k
        ret = false;
4573
52.6k
        continue;
4574
52.6k
      }
4575
4576
90.6k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
90.6k
    if (! ent->is_sym)
4580
10.2k
      {
4581
10.2k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
10.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
10.2k
     abfd, symndx, counter);
4585
10.2k
        cache_ptr->line_number = -1;
4586
10.2k
        ret = false;
4587
10.2k
        continue;
4588
10.2k
      }
4589
80.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
80.4k
    if (sym < obj_symbols (abfd)
4593
80.4k
        || 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
80.4k
    have_func = true;
4605
80.4k
    nbr_func++;
4606
80.4k
    cache_ptr->u.sym = (asymbol *) sym;
4607
80.4k
    if (sym->lineno != NULL)
4608
79.5k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
79.5k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
79.5k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
80.4k
    sym->lineno = cache_ptr;
4614
80.4k
    if (sym->symbol.value < prev_offset)
4615
3.05k
      ordered = false;
4616
80.4k
    prev_offset = sym->symbol.value;
4617
80.4k
  }
4618
256k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
165k
  continue;
4622
91.9k
      else
4623
91.9k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
172k
      cache_ptr++;
4625
172k
    }
4626
4627
214
  asect->lineno_count = cache_ptr - lineno_cache;
4628
214
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
214
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
214
  if (!ordered)
4633
112
    {
4634
      /* Sort the table.  */
4635
112
      alent **func_table;
4636
112
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
112
      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
112
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
112
  {
4646
112
    alent **p = func_table;
4647
112
    unsigned int i;
4648
4649
169k
    for (i = 0; i < asect->lineno_count; i++)
4650
169k
      if (lineno_cache[i].line_number == 0)
4651
79.0k
        *p++ = &lineno_cache[i];
4652
4653
112
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
112
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
112
    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
112
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
112
      {
4666
112
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
79.1k
        for (i = 0; i < nbr_func; i++)
4669
79.0k
    {
4670
79.0k
      coff_symbol_type *sym;
4671
79.0k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
79.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
79.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
79.0k
      do
4680
169k
        *n_cache_ptr++ = *old_ptr++;
4681
169k
      while (old_ptr->line_number != 0);
4682
79.0k
    }
4683
4684
112
        memcpy (lineno_cache, n_lineno_cache,
4685
112
          asect->lineno_count * sizeof (alent));
4686
112
      }
4687
0
    else
4688
0
      ret = false;
4689
112
    bfd_release (abfd, func_table);
4690
112
  }
4691
0
      else
4692
0
  ret = false;
4693
112
    }
4694
4695
214
  return ret;
4696
214
}
pei-aarch64.c:coff_slurp_line_table
Line
Count
Source
4499
816
{
4500
816
  LINENO *native_lineno;
4501
816
  alent *lineno_cache;
4502
816
  unsigned int counter;
4503
816
  alent *cache_ptr;
4504
816
  bfd_vma prev_offset = 0;
4505
816
  bool ordered = true;
4506
816
  unsigned int nbr_func;
4507
816
  LINENO *src;
4508
816
  bool have_func;
4509
816
  bool ret = true;
4510
816
  size_t amt;
4511
4512
816
  if (asect->lineno_count == 0)
4513
491
    return true;
4514
4515
325
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
325
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
325
             asect->lineno_count,
4519
325
             bfd_coff_linesz (abfd));
4520
325
  if (native_lineno == NULL)
4521
181
    {
4522
181
      _bfd_error_handler
4523
181
  (_("%pB: warning: line number table read failed"), abfd);
4524
181
      return false;
4525
181
    }
4526
4527
144
  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
144
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
144
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
144
  cache_ptr = lineno_cache;
4541
144
  asect->lineno = lineno_cache;
4542
144
  src = native_lineno;
4543
144
  nbr_func = 0;
4544
144
  have_func = false;
4545
4546
662k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
662k
    {
4548
662k
      struct internal_lineno dst;
4549
4550
662k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
662k
      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
662k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
662k
      if (cache_ptr->line_number == 0)
4558
196k
  {
4559
196k
    combined_entry_type * ent;
4560
196k
    unsigned long symndx;
4561
196k
    coff_symbol_type *sym;
4562
4563
196k
    have_func = false;
4564
196k
    symndx = dst.l_addr.l_symndx;
4565
196k
    if (symndx >= obj_raw_syment_count (abfd))
4566
87.3k
      {
4567
87.3k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
87.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
87.3k
     abfd, symndx, counter);
4571
87.3k
        cache_ptr->line_number = -1;
4572
87.3k
        ret = false;
4573
87.3k
        continue;
4574
87.3k
      }
4575
4576
108k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
108k
    if (! ent->is_sym)
4580
21.0k
      {
4581
21.0k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
21.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
21.0k
     abfd, symndx, counter);
4585
21.0k
        cache_ptr->line_number = -1;
4586
21.0k
        ret = false;
4587
21.0k
        continue;
4588
21.0k
      }
4589
87.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
87.8k
    if (sym < obj_symbols (abfd)
4593
87.8k
        || 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
87.8k
    have_func = true;
4605
87.8k
    nbr_func++;
4606
87.8k
    cache_ptr->u.sym = (asymbol *) sym;
4607
87.8k
    if (sym->lineno != NULL)
4608
86.7k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
86.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
86.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
87.8k
    sym->lineno = cache_ptr;
4614
87.8k
    if (sym->symbol.value < prev_offset)
4615
1.61k
      ordered = false;
4616
87.8k
    prev_offset = sym->symbol.value;
4617
87.8k
  }
4618
465k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
327k
  continue;
4622
138k
      else
4623
138k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
226k
      cache_ptr++;
4625
226k
    }
4626
4627
144
  asect->lineno_count = cache_ptr - lineno_cache;
4628
144
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
144
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
144
  if (!ordered)
4633
98
    {
4634
      /* Sort the table.  */
4635
98
      alent **func_table;
4636
98
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
98
      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
98
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
98
  {
4646
98
    alent **p = func_table;
4647
98
    unsigned int i;
4648
4649
208k
    for (i = 0; i < asect->lineno_count; i++)
4650
208k
      if (lineno_cache[i].line_number == 0)
4651
81.8k
        *p++ = &lineno_cache[i];
4652
4653
98
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
98
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
98
    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
98
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
98
      {
4666
98
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
81.9k
        for (i = 0; i < nbr_func; i++)
4669
81.8k
    {
4670
81.8k
      coff_symbol_type *sym;
4671
81.8k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
81.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
81.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
81.8k
      do
4680
208k
        *n_cache_ptr++ = *old_ptr++;
4681
208k
      while (old_ptr->line_number != 0);
4682
81.8k
    }
4683
4684
98
        memcpy (lineno_cache, n_lineno_cache,
4685
98
          asect->lineno_count * sizeof (alent));
4686
98
      }
4687
0
    else
4688
0
      ret = false;
4689
98
    bfd_release (abfd, func_table);
4690
98
  }
4691
0
      else
4692
0
  ret = false;
4693
98
    }
4694
4695
144
  return ret;
4696
144
}
pei-ia64.c:coff_slurp_line_table
Line
Count
Source
4499
1.14k
{
4500
1.14k
  LINENO *native_lineno;
4501
1.14k
  alent *lineno_cache;
4502
1.14k
  unsigned int counter;
4503
1.14k
  alent *cache_ptr;
4504
1.14k
  bfd_vma prev_offset = 0;
4505
1.14k
  bool ordered = true;
4506
1.14k
  unsigned int nbr_func;
4507
1.14k
  LINENO *src;
4508
1.14k
  bool have_func;
4509
1.14k
  bool ret = true;
4510
1.14k
  size_t amt;
4511
4512
1.14k
  if (asect->lineno_count == 0)
4513
793
    return true;
4514
4515
353
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
353
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
353
             asect->lineno_count,
4519
353
             bfd_coff_linesz (abfd));
4520
353
  if (native_lineno == NULL)
4521
175
    {
4522
175
      _bfd_error_handler
4523
175
  (_("%pB: warning: line number table read failed"), abfd);
4524
175
      return false;
4525
175
    }
4526
4527
178
  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
178
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
178
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
178
  cache_ptr = lineno_cache;
4541
178
  asect->lineno = lineno_cache;
4542
178
  src = native_lineno;
4543
178
  nbr_func = 0;
4544
178
  have_func = false;
4545
4546
435k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
435k
    {
4548
435k
      struct internal_lineno dst;
4549
4550
435k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
435k
      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
435k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
435k
      if (cache_ptr->line_number == 0)
4558
143k
  {
4559
143k
    combined_entry_type * ent;
4560
143k
    unsigned long symndx;
4561
143k
    coff_symbol_type *sym;
4562
4563
143k
    have_func = false;
4564
143k
    symndx = dst.l_addr.l_symndx;
4565
143k
    if (symndx >= obj_raw_syment_count (abfd))
4566
63.3k
      {
4567
63.3k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
63.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
63.3k
     abfd, symndx, counter);
4571
63.3k
        cache_ptr->line_number = -1;
4572
63.3k
        ret = false;
4573
63.3k
        continue;
4574
63.3k
      }
4575
4576
80.2k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
80.2k
    if (! ent->is_sym)
4580
17.1k
      {
4581
17.1k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
17.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
17.1k
     abfd, symndx, counter);
4585
17.1k
        cache_ptr->line_number = -1;
4586
17.1k
        ret = false;
4587
17.1k
        continue;
4588
17.1k
      }
4589
63.1k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
63.1k
    if (sym < obj_symbols (abfd)
4593
63.1k
        || 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
63.1k
    have_func = true;
4605
63.1k
    nbr_func++;
4606
63.1k
    cache_ptr->u.sym = (asymbol *) sym;
4607
63.1k
    if (sym->lineno != NULL)
4608
61.9k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
61.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
61.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
63.1k
    sym->lineno = cache_ptr;
4614
63.1k
    if (sym->symbol.value < prev_offset)
4615
1.54k
      ordered = false;
4616
63.1k
    prev_offset = sym->symbol.value;
4617
63.1k
  }
4618
292k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
220k
  continue;
4622
72.1k
      else
4623
72.1k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
135k
      cache_ptr++;
4625
135k
    }
4626
4627
178
  asect->lineno_count = cache_ptr - lineno_cache;
4628
178
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
178
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
178
  if (!ordered)
4633
98
    {
4634
      /* Sort the table.  */
4635
98
      alent **func_table;
4636
98
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
98
      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
98
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
98
  {
4646
98
    alent **p = func_table;
4647
98
    unsigned int i;
4648
4649
129k
    for (i = 0; i < asect->lineno_count; i++)
4650
129k
      if (lineno_cache[i].line_number == 0)
4651
61.6k
        *p++ = &lineno_cache[i];
4652
4653
98
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
98
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
98
    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
98
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
98
      {
4666
98
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
61.7k
        for (i = 0; i < nbr_func; i++)
4669
61.6k
    {
4670
61.6k
      coff_symbol_type *sym;
4671
61.6k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
61.6k
      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
61.6k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
61.6k
      do
4680
129k
        *n_cache_ptr++ = *old_ptr++;
4681
129k
      while (old_ptr->line_number != 0);
4682
61.6k
    }
4683
4684
98
        memcpy (lineno_cache, n_lineno_cache,
4685
98
          asect->lineno_count * sizeof (alent));
4686
98
      }
4687
0
    else
4688
0
      ret = false;
4689
98
    bfd_release (abfd, func_table);
4690
98
  }
4691
0
      else
4692
0
  ret = false;
4693
98
    }
4694
4695
178
  return ret;
4696
178
}
pei-loongarch64.c:coff_slurp_line_table
Line
Count
Source
4499
711
{
4500
711
  LINENO *native_lineno;
4501
711
  alent *lineno_cache;
4502
711
  unsigned int counter;
4503
711
  alent *cache_ptr;
4504
711
  bfd_vma prev_offset = 0;
4505
711
  bool ordered = true;
4506
711
  unsigned int nbr_func;
4507
711
  LINENO *src;
4508
711
  bool have_func;
4509
711
  bool ret = true;
4510
711
  size_t amt;
4511
4512
711
  if (asect->lineno_count == 0)
4513
422
    return true;
4514
4515
289
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
289
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
289
             asect->lineno_count,
4519
289
             bfd_coff_linesz (abfd));
4520
289
  if (native_lineno == NULL)
4521
145
    {
4522
145
      _bfd_error_handler
4523
145
  (_("%pB: warning: line number table read failed"), abfd);
4524
145
      return false;
4525
145
    }
4526
4527
144
  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
144
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
144
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
144
  cache_ptr = lineno_cache;
4541
144
  asect->lineno = lineno_cache;
4542
144
  src = native_lineno;
4543
144
  nbr_func = 0;
4544
144
  have_func = false;
4545
4546
1.28M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.28M
    {
4548
1.28M
      struct internal_lineno dst;
4549
4550
1.28M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.28M
      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.28M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.28M
      if (cache_ptr->line_number == 0)
4558
557k
  {
4559
557k
    combined_entry_type * ent;
4560
557k
    unsigned long symndx;
4561
557k
    coff_symbol_type *sym;
4562
4563
557k
    have_func = false;
4564
557k
    symndx = dst.l_addr.l_symndx;
4565
557k
    if (symndx >= obj_raw_syment_count (abfd))
4566
263k
      {
4567
263k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
263k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
263k
     abfd, symndx, counter);
4571
263k
        cache_ptr->line_number = -1;
4572
263k
        ret = false;
4573
263k
        continue;
4574
263k
      }
4575
4576
294k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
294k
    if (! ent->is_sym)
4580
52.2k
      {
4581
52.2k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
52.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
52.2k
     abfd, symndx, counter);
4585
52.2k
        cache_ptr->line_number = -1;
4586
52.2k
        ret = false;
4587
52.2k
        continue;
4588
52.2k
      }
4589
241k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
241k
    if (sym < obj_symbols (abfd)
4593
241k
        || 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
241k
    have_func = true;
4605
241k
    nbr_func++;
4606
241k
    cache_ptr->u.sym = (asymbol *) sym;
4607
241k
    if (sym->lineno != NULL)
4608
239k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
239k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
239k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
241k
    sym->lineno = cache_ptr;
4614
241k
    if (sym->symbol.value < prev_offset)
4615
7.19k
      ordered = false;
4616
241k
    prev_offset = sym->symbol.value;
4617
241k
  }
4618
728k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
457k
  continue;
4622
270k
      else
4623
270k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
512k
      cache_ptr++;
4625
512k
    }
4626
4627
144
  asect->lineno_count = cache_ptr - lineno_cache;
4628
144
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
144
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
144
  if (!ordered)
4633
100
    {
4634
      /* Sort the table.  */
4635
100
      alent **func_table;
4636
100
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
100
      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
100
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
100
  {
4646
100
    alent **p = func_table;
4647
100
    unsigned int i;
4648
4649
511k
    for (i = 0; i < asect->lineno_count; i++)
4650
511k
      if (lineno_cache[i].line_number == 0)
4651
241k
        *p++ = &lineno_cache[i];
4652
4653
100
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
100
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
100
    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
100
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
100
      {
4666
100
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
241k
        for (i = 0; i < nbr_func; i++)
4669
241k
    {
4670
241k
      coff_symbol_type *sym;
4671
241k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
241k
      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
241k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
241k
      do
4680
511k
        *n_cache_ptr++ = *old_ptr++;
4681
511k
      while (old_ptr->line_number != 0);
4682
241k
    }
4683
4684
100
        memcpy (lineno_cache, n_lineno_cache,
4685
100
          asect->lineno_count * sizeof (alent));
4686
100
      }
4687
0
    else
4688
0
      ret = false;
4689
100
    bfd_release (abfd, func_table);
4690
100
  }
4691
0
      else
4692
0
  ret = false;
4693
100
    }
4694
4695
144
  return ret;
4696
144
}
pei-riscv64.c:coff_slurp_line_table
Line
Count
Source
4499
647
{
4500
647
  LINENO *native_lineno;
4501
647
  alent *lineno_cache;
4502
647
  unsigned int counter;
4503
647
  alent *cache_ptr;
4504
647
  bfd_vma prev_offset = 0;
4505
647
  bool ordered = true;
4506
647
  unsigned int nbr_func;
4507
647
  LINENO *src;
4508
647
  bool have_func;
4509
647
  bool ret = true;
4510
647
  size_t amt;
4511
4512
647
  if (asect->lineno_count == 0)
4513
315
    return true;
4514
4515
332
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
332
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
332
             asect->lineno_count,
4519
332
             bfd_coff_linesz (abfd));
4520
332
  if (native_lineno == NULL)
4521
181
    {
4522
181
      _bfd_error_handler
4523
181
  (_("%pB: warning: line number table read failed"), abfd);
4524
181
      return false;
4525
181
    }
4526
4527
151
  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
151
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
151
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
151
  cache_ptr = lineno_cache;
4541
151
  asect->lineno = lineno_cache;
4542
151
  src = native_lineno;
4543
151
  nbr_func = 0;
4544
151
  have_func = false;
4545
4546
181k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
181k
    {
4548
181k
      struct internal_lineno dst;
4549
4550
181k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
181k
      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
181k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
181k
      if (cache_ptr->line_number == 0)
4558
92.7k
  {
4559
92.7k
    combined_entry_type * ent;
4560
92.7k
    unsigned long symndx;
4561
92.7k
    coff_symbol_type *sym;
4562
4563
92.7k
    have_func = false;
4564
92.7k
    symndx = dst.l_addr.l_symndx;
4565
92.7k
    if (symndx >= obj_raw_syment_count (abfd))
4566
43.6k
      {
4567
43.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
43.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
43.6k
     abfd, symndx, counter);
4571
43.6k
        cache_ptr->line_number = -1;
4572
43.6k
        ret = false;
4573
43.6k
        continue;
4574
43.6k
      }
4575
4576
49.1k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
49.1k
    if (! ent->is_sym)
4580
4.53k
      {
4581
4.53k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
4.53k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
4.53k
     abfd, symndx, counter);
4585
4.53k
        cache_ptr->line_number = -1;
4586
4.53k
        ret = false;
4587
4.53k
        continue;
4588
4.53k
      }
4589
44.6k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
44.6k
    if (sym < obj_symbols (abfd)
4593
44.6k
        || 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
44.6k
    have_func = true;
4605
44.6k
    nbr_func++;
4606
44.6k
    cache_ptr->u.sym = (asymbol *) sym;
4607
44.6k
    if (sym->lineno != NULL)
4608
44.0k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
44.0k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
44.0k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
44.6k
    sym->lineno = cache_ptr;
4614
44.6k
    if (sym->symbol.value < prev_offset)
4615
1.00k
      ordered = false;
4616
44.6k
    prev_offset = sym->symbol.value;
4617
44.6k
  }
4618
88.9k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
61.3k
  continue;
4622
27.5k
      else
4623
27.5k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
72.1k
      cache_ptr++;
4625
72.1k
    }
4626
4627
151
  asect->lineno_count = cache_ptr - lineno_cache;
4628
151
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
151
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
151
  if (!ordered)
4633
83
    {
4634
      /* Sort the table.  */
4635
83
      alent **func_table;
4636
83
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
83
      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
83
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
83
  {
4646
83
    alent **p = func_table;
4647
83
    unsigned int i;
4648
4649
50.0k
    for (i = 0; i < asect->lineno_count; i++)
4650
49.9k
      if (lineno_cache[i].line_number == 0)
4651
25.1k
        *p++ = &lineno_cache[i];
4652
4653
83
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
83
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
83
    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
83
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
83
      {
4666
83
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
25.2k
        for (i = 0; i < nbr_func; i++)
4669
25.1k
    {
4670
25.1k
      coff_symbol_type *sym;
4671
25.1k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
25.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
25.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
25.1k
      do
4680
49.9k
        *n_cache_ptr++ = *old_ptr++;
4681
49.9k
      while (old_ptr->line_number != 0);
4682
25.1k
    }
4683
4684
83
        memcpy (lineno_cache, n_lineno_cache,
4685
83
          asect->lineno_count * sizeof (alent));
4686
83
      }
4687
0
    else
4688
0
      ret = false;
4689
83
    bfd_release (abfd, func_table);
4690
83
  }
4691
0
      else
4692
0
  ret = false;
4693
83
    }
4694
4695
151
  return ret;
4696
151
}
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
3.29k
{
4500
3.29k
  LINENO *native_lineno;
4501
3.29k
  alent *lineno_cache;
4502
3.29k
  unsigned int counter;
4503
3.29k
  alent *cache_ptr;
4504
3.29k
  bfd_vma prev_offset = 0;
4505
3.29k
  bool ordered = true;
4506
3.29k
  unsigned int nbr_func;
4507
3.29k
  LINENO *src;
4508
3.29k
  bool have_func;
4509
3.29k
  bool ret = true;
4510
3.29k
  size_t amt;
4511
4512
3.29k
  if (asect->lineno_count == 0)
4513
2.72k
    return true;
4514
4515
566
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
566
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
566
             asect->lineno_count,
4519
566
             bfd_coff_linesz (abfd));
4520
566
  if (native_lineno == NULL)
4521
337
    {
4522
337
      _bfd_error_handler
4523
337
  (_("%pB: warning: line number table read failed"), abfd);
4524
337
      return false;
4525
337
    }
4526
4527
229
  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
229
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
229
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
229
  cache_ptr = lineno_cache;
4541
229
  asect->lineno = lineno_cache;
4542
229
  src = native_lineno;
4543
229
  nbr_func = 0;
4544
229
  have_func = false;
4545
4546
202k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
202k
    {
4548
202k
      struct internal_lineno dst;
4549
4550
202k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
202k
      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
202k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
202k
      if (cache_ptr->line_number == 0)
4558
91.8k
  {
4559
91.8k
    combined_entry_type * ent;
4560
91.8k
    unsigned long symndx;
4561
91.8k
    coff_symbol_type *sym;
4562
4563
91.8k
    have_func = false;
4564
91.8k
    symndx = dst.l_addr.l_symndx;
4565
91.8k
    if (symndx >= obj_raw_syment_count (abfd))
4566
42.7k
      {
4567
42.7k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
42.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
42.7k
     abfd, symndx, counter);
4571
42.7k
        cache_ptr->line_number = -1;
4572
42.7k
        ret = false;
4573
42.7k
        continue;
4574
42.7k
      }
4575
4576
49.1k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
49.1k
    if (! ent->is_sym)
4580
6.17k
      {
4581
6.17k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
6.17k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
6.17k
     abfd, symndx, counter);
4585
6.17k
        cache_ptr->line_number = -1;
4586
6.17k
        ret = false;
4587
6.17k
        continue;
4588
6.17k
      }
4589
42.9k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
42.9k
    if (sym < obj_symbols (abfd)
4593
42.9k
        || 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
42.9k
    have_func = true;
4605
42.9k
    nbr_func++;
4606
42.9k
    cache_ptr->u.sym = (asymbol *) sym;
4607
42.9k
    if (sym->lineno != NULL)
4608
42.4k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
42.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
42.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
42.9k
    sym->lineno = cache_ptr;
4614
42.9k
    if (sym->symbol.value < prev_offset)
4615
1.05k
      ordered = false;
4616
42.9k
    prev_offset = sym->symbol.value;
4617
42.9k
  }
4618
110k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
66.4k
  continue;
4622
43.8k
      else
4623
43.8k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
86.7k
      cache_ptr++;
4625
86.7k
    }
4626
4627
229
  asect->lineno_count = cache_ptr - lineno_cache;
4628
229
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
229
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
229
  if (!ordered)
4633
98
    {
4634
      /* Sort the table.  */
4635
98
      alent **func_table;
4636
98
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
98
      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
98
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
98
  {
4646
98
    alent **p = func_table;
4647
98
    unsigned int i;
4648
4649
80.6k
    for (i = 0; i < asect->lineno_count; i++)
4650
80.5k
      if (lineno_cache[i].line_number == 0)
4651
39.1k
        *p++ = &lineno_cache[i];
4652
4653
98
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
98
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
98
    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
98
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
98
      {
4666
98
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
39.2k
        for (i = 0; i < nbr_func; i++)
4669
39.1k
    {
4670
39.1k
      coff_symbol_type *sym;
4671
39.1k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
39.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
39.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
39.1k
      do
4680
80.5k
        *n_cache_ptr++ = *old_ptr++;
4681
80.5k
      while (old_ptr->line_number != 0);
4682
39.1k
    }
4683
4684
98
        memcpy (lineno_cache, n_lineno_cache,
4685
98
          asect->lineno_count * sizeof (alent));
4686
98
      }
4687
0
    else
4688
0
      ret = false;
4689
98
    bfd_release (abfd, func_table);
4690
98
  }
4691
0
      else
4692
0
  ret = false;
4693
98
    }
4694
4695
229
  return ret;
4696
229
}
coff-sh.c:coff_slurp_line_table
Line
Count
Source
4499
2.57k
{
4500
2.57k
  LINENO *native_lineno;
4501
2.57k
  alent *lineno_cache;
4502
2.57k
  unsigned int counter;
4503
2.57k
  alent *cache_ptr;
4504
2.57k
  bfd_vma prev_offset = 0;
4505
2.57k
  bool ordered = true;
4506
2.57k
  unsigned int nbr_func;
4507
2.57k
  LINENO *src;
4508
2.57k
  bool have_func;
4509
2.57k
  bool ret = true;
4510
2.57k
  size_t amt;
4511
4512
2.57k
  if (asect->lineno_count == 0)
4513
2.01k
    return true;
4514
4515
562
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
562
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
562
             asect->lineno_count,
4519
562
             bfd_coff_linesz (abfd));
4520
562
  if (native_lineno == NULL)
4521
260
    {
4522
260
      _bfd_error_handler
4523
260
  (_("%pB: warning: line number table read failed"), abfd);
4524
260
      return false;
4525
260
    }
4526
4527
302
  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
302
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
302
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
302
  cache_ptr = lineno_cache;
4541
302
  asect->lineno = lineno_cache;
4542
302
  src = native_lineno;
4543
302
  nbr_func = 0;
4544
302
  have_func = false;
4545
4546
1.12M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.12M
    {
4548
1.12M
      struct internal_lineno dst;
4549
4550
1.12M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.12M
      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.12M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.12M
      if (cache_ptr->line_number == 0)
4558
346k
  {
4559
346k
    combined_entry_type * ent;
4560
346k
    unsigned long symndx;
4561
346k
    coff_symbol_type *sym;
4562
4563
346k
    have_func = false;
4564
346k
    symndx = dst.l_addr.l_symndx;
4565
346k
    if (symndx >= obj_raw_syment_count (abfd))
4566
97.0k
      {
4567
97.0k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
97.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
97.0k
     abfd, symndx, counter);
4571
97.0k
        cache_ptr->line_number = -1;
4572
97.0k
        ret = false;
4573
97.0k
        continue;
4574
97.0k
      }
4575
4576
249k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
249k
    if (! ent->is_sym)
4580
34.7k
      {
4581
34.7k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
34.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
34.7k
     abfd, symndx, counter);
4585
34.7k
        cache_ptr->line_number = -1;
4586
34.7k
        ret = false;
4587
34.7k
        continue;
4588
34.7k
      }
4589
214k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
214k
    if (sym < obj_symbols (abfd)
4593
214k
        || 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
214k
    have_func = true;
4605
214k
    nbr_func++;
4606
214k
    cache_ptr->u.sym = (asymbol *) sym;
4607
214k
    if (sym->lineno != NULL)
4608
209k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
209k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
209k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
214k
    sym->lineno = cache_ptr;
4614
214k
    if (sym->symbol.value < prev_offset)
4615
4.86k
      ordered = false;
4616
214k
    prev_offset = sym->symbol.value;
4617
214k
  }
4618
774k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
489k
  continue;
4622
284k
      else
4623
284k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
499k
      cache_ptr++;
4625
499k
    }
4626
4627
302
  asect->lineno_count = cache_ptr - lineno_cache;
4628
302
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
302
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
302
  if (!ordered)
4633
136
    {
4634
      /* Sort the table.  */
4635
136
      alent **func_table;
4636
136
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
136
      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
136
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
136
  {
4646
136
    alent **p = func_table;
4647
136
    unsigned int i;
4648
4649
490k
    for (i = 0; i < asect->lineno_count; i++)
4650
490k
      if (lineno_cache[i].line_number == 0)
4651
210k
        *p++ = &lineno_cache[i];
4652
4653
136
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
136
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
136
    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
136
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
136
      {
4666
136
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
210k
        for (i = 0; i < nbr_func; i++)
4669
210k
    {
4670
210k
      coff_symbol_type *sym;
4671
210k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
210k
      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
210k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
210k
      do
4680
490k
        *n_cache_ptr++ = *old_ptr++;
4681
490k
      while (old_ptr->line_number != 0);
4682
210k
    }
4683
4684
136
        memcpy (lineno_cache, n_lineno_cache,
4685
136
          asect->lineno_count * sizeof (alent));
4686
136
      }
4687
0
    else
4688
0
      ret = false;
4689
136
    bfd_release (abfd, func_table);
4690
136
  }
4691
0
      else
4692
0
  ret = false;
4693
136
    }
4694
4695
302
  return ret;
4696
302
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_line_table
coff-tic30.c:coff_slurp_line_table
Line
Count
Source
4499
3.01k
{
4500
3.01k
  LINENO *native_lineno;
4501
3.01k
  alent *lineno_cache;
4502
3.01k
  unsigned int counter;
4503
3.01k
  alent *cache_ptr;
4504
3.01k
  bfd_vma prev_offset = 0;
4505
3.01k
  bool ordered = true;
4506
3.01k
  unsigned int nbr_func;
4507
3.01k
  LINENO *src;
4508
3.01k
  bool have_func;
4509
3.01k
  bool ret = true;
4510
3.01k
  size_t amt;
4511
4512
3.01k
  if (asect->lineno_count == 0)
4513
2.34k
    return true;
4514
4515
666
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
666
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
666
             asect->lineno_count,
4519
666
             bfd_coff_linesz (abfd));
4520
666
  if (native_lineno == NULL)
4521
337
    {
4522
337
      _bfd_error_handler
4523
337
  (_("%pB: warning: line number table read failed"), abfd);
4524
337
      return false;
4525
337
    }
4526
4527
329
  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
329
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
329
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
329
  cache_ptr = lineno_cache;
4541
329
  asect->lineno = lineno_cache;
4542
329
  src = native_lineno;
4543
329
  nbr_func = 0;
4544
329
  have_func = false;
4545
4546
473k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
473k
    {
4548
473k
      struct internal_lineno dst;
4549
4550
473k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
473k
      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
473k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
473k
      if (cache_ptr->line_number == 0)
4558
117k
  {
4559
117k
    combined_entry_type * ent;
4560
117k
    unsigned long symndx;
4561
117k
    coff_symbol_type *sym;
4562
4563
117k
    have_func = false;
4564
117k
    symndx = dst.l_addr.l_symndx;
4565
117k
    if (symndx >= obj_raw_syment_count (abfd))
4566
37.6k
      {
4567
37.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
37.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
37.6k
     abfd, symndx, counter);
4571
37.6k
        cache_ptr->line_number = -1;
4572
37.6k
        ret = false;
4573
37.6k
        continue;
4574
37.6k
      }
4575
4576
79.7k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
79.7k
    if (! ent->is_sym)
4580
7.85k
      {
4581
7.85k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
7.85k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
7.85k
     abfd, symndx, counter);
4585
7.85k
        cache_ptr->line_number = -1;
4586
7.85k
        ret = false;
4587
7.85k
        continue;
4588
7.85k
      }
4589
71.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
71.8k
    if (sym < obj_symbols (abfd)
4593
71.8k
        || 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
71.8k
    have_func = true;
4605
71.8k
    nbr_func++;
4606
71.8k
    cache_ptr->u.sym = (asymbol *) sym;
4607
71.8k
    if (sym->lineno != NULL)
4608
70.3k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
70.3k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
70.3k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
71.8k
    sym->lineno = cache_ptr;
4614
71.8k
    if (sym->symbol.value < prev_offset)
4615
2.03k
      ordered = false;
4616
71.8k
    prev_offset = sym->symbol.value;
4617
71.8k
  }
4618
355k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
231k
  continue;
4622
123k
      else
4623
123k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
195k
      cache_ptr++;
4625
195k
    }
4626
4627
329
  asect->lineno_count = cache_ptr - lineno_cache;
4628
329
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
329
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
329
  if (!ordered)
4633
154
    {
4634
      /* Sort the table.  */
4635
154
      alent **func_table;
4636
154
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
154
      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
154
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
154
  {
4646
154
    alent **p = func_table;
4647
154
    unsigned int i;
4648
4649
182k
    for (i = 0; i < asect->lineno_count; i++)
4650
182k
      if (lineno_cache[i].line_number == 0)
4651
66.5k
        *p++ = &lineno_cache[i];
4652
4653
154
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
154
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
154
    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
154
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
154
      {
4666
154
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
66.6k
        for (i = 0; i < nbr_func; i++)
4669
66.5k
    {
4670
66.5k
      coff_symbol_type *sym;
4671
66.5k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
66.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
66.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
66.5k
      do
4680
182k
        *n_cache_ptr++ = *old_ptr++;
4681
182k
      while (old_ptr->line_number != 0);
4682
66.5k
    }
4683
4684
154
        memcpy (lineno_cache, n_lineno_cache,
4685
154
          asect->lineno_count * sizeof (alent));
4686
154
      }
4687
0
    else
4688
0
      ret = false;
4689
154
    bfd_release (abfd, func_table);
4690
154
  }
4691
0
      else
4692
0
  ret = false;
4693
154
    }
4694
4695
329
  return ret;
4696
329
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_line_table
coff-tic54x.c:coff_slurp_line_table
Line
Count
Source
4499
4.56k
{
4500
4.56k
  LINENO *native_lineno;
4501
4.56k
  alent *lineno_cache;
4502
4.56k
  unsigned int counter;
4503
4.56k
  alent *cache_ptr;
4504
4.56k
  bfd_vma prev_offset = 0;
4505
4.56k
  bool ordered = true;
4506
4.56k
  unsigned int nbr_func;
4507
4.56k
  LINENO *src;
4508
4.56k
  bool have_func;
4509
4.56k
  bool ret = true;
4510
4.56k
  size_t amt;
4511
4512
4.56k
  if (asect->lineno_count == 0)
4513
3.96k
    return true;
4514
4515
599
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
599
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
599
             asect->lineno_count,
4519
599
             bfd_coff_linesz (abfd));
4520
599
  if (native_lineno == NULL)
4521
259
    {
4522
259
      _bfd_error_handler
4523
259
  (_("%pB: warning: line number table read failed"), abfd);
4524
259
      return false;
4525
259
    }
4526
4527
340
  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
340
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
340
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
340
  cache_ptr = lineno_cache;
4541
340
  asect->lineno = lineno_cache;
4542
340
  src = native_lineno;
4543
340
  nbr_func = 0;
4544
340
  have_func = false;
4545
4546
1.21M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
1.21M
    {
4548
1.21M
      struct internal_lineno dst;
4549
4550
1.21M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
1.21M
      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.21M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
1.21M
      if (cache_ptr->line_number == 0)
4558
417k
  {
4559
417k
    combined_entry_type * ent;
4560
417k
    unsigned long symndx;
4561
417k
    coff_symbol_type *sym;
4562
4563
417k
    have_func = false;
4564
417k
    symndx = dst.l_addr.l_symndx;
4565
417k
    if (symndx >= obj_raw_syment_count (abfd))
4566
201k
      {
4567
201k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
201k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
201k
     abfd, symndx, counter);
4571
201k
        cache_ptr->line_number = -1;
4572
201k
        ret = false;
4573
201k
        continue;
4574
201k
      }
4575
4576
216k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
216k
    if (! ent->is_sym)
4580
47.4k
      {
4581
47.4k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
47.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
47.4k
     abfd, symndx, counter);
4585
47.4k
        cache_ptr->line_number = -1;
4586
47.4k
        ret = false;
4587
47.4k
        continue;
4588
47.4k
      }
4589
168k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
168k
    if (sym < obj_symbols (abfd)
4593
168k
        || 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
168k
    have_func = true;
4605
168k
    nbr_func++;
4606
168k
    cache_ptr->u.sym = (asymbol *) sym;
4607
168k
    if (sym->lineno != NULL)
4608
165k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
165k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
165k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
168k
    sym->lineno = cache_ptr;
4614
168k
    if (sym->symbol.value < prev_offset)
4615
3.38k
      ordered = false;
4616
168k
    prev_offset = sym->symbol.value;
4617
168k
  }
4618
795k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
651k
  continue;
4622
144k
      else
4623
144k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
312k
      cache_ptr++;
4625
312k
    }
4626
4627
340
  asect->lineno_count = cache_ptr - lineno_cache;
4628
340
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
340
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
340
  if (!ordered)
4633
138
    {
4634
      /* Sort the table.  */
4635
138
      alent **func_table;
4636
138
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
138
      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
138
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
138
  {
4646
138
    alent **p = func_table;
4647
138
    unsigned int i;
4648
4649
279k
    for (i = 0; i < asect->lineno_count; i++)
4650
279k
      if (lineno_cache[i].line_number == 0)
4651
143k
        *p++ = &lineno_cache[i];
4652
4653
138
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
138
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
138
    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
138
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
138
      {
4666
138
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
144k
        for (i = 0; i < nbr_func; i++)
4669
143k
    {
4670
143k
      coff_symbol_type *sym;
4671
143k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
143k
      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
143k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
143k
      do
4680
279k
        *n_cache_ptr++ = *old_ptr++;
4681
279k
      while (old_ptr->line_number != 0);
4682
143k
    }
4683
4684
138
        memcpy (lineno_cache, n_lineno_cache,
4685
138
          asect->lineno_count * sizeof (alent));
4686
138
      }
4687
0
    else
4688
0
      ret = false;
4689
138
    bfd_release (abfd, func_table);
4690
138
  }
4691
0
      else
4692
0
  ret = false;
4693
138
    }
4694
4695
340
  return ret;
4696
340
}
coff-z80.c:coff_slurp_line_table
Line
Count
Source
4499
3.69k
{
4500
3.69k
  LINENO *native_lineno;
4501
3.69k
  alent *lineno_cache;
4502
3.69k
  unsigned int counter;
4503
3.69k
  alent *cache_ptr;
4504
3.69k
  bfd_vma prev_offset = 0;
4505
3.69k
  bool ordered = true;
4506
3.69k
  unsigned int nbr_func;
4507
3.69k
  LINENO *src;
4508
3.69k
  bool have_func;
4509
3.69k
  bool ret = true;
4510
3.69k
  size_t amt;
4511
4512
3.69k
  if (asect->lineno_count == 0)
4513
3.03k
    return true;
4514
4515
658
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
658
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
658
             asect->lineno_count,
4519
658
             bfd_coff_linesz (abfd));
4520
658
  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
379
  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
379
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
379
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
379
  cache_ptr = lineno_cache;
4541
379
  asect->lineno = lineno_cache;
4542
379
  src = native_lineno;
4543
379
  nbr_func = 0;
4544
379
  have_func = false;
4545
4546
219k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
218k
    {
4548
218k
      struct internal_lineno dst;
4549
4550
218k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
218k
      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
218k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
218k
      if (cache_ptr->line_number == 0)
4558
66.7k
  {
4559
66.7k
    combined_entry_type * ent;
4560
66.7k
    unsigned long symndx;
4561
66.7k
    coff_symbol_type *sym;
4562
4563
66.7k
    have_func = false;
4564
66.7k
    symndx = dst.l_addr.l_symndx;
4565
66.7k
    if (symndx >= obj_raw_syment_count (abfd))
4566
18.7k
      {
4567
18.7k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
18.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
18.7k
     abfd, symndx, counter);
4571
18.7k
        cache_ptr->line_number = -1;
4572
18.7k
        ret = false;
4573
18.7k
        continue;
4574
18.7k
      }
4575
4576
48.0k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
48.0k
    if (! ent->is_sym)
4580
5.27k
      {
4581
5.27k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
5.27k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
5.27k
     abfd, symndx, counter);
4585
5.27k
        cache_ptr->line_number = -1;
4586
5.27k
        ret = false;
4587
5.27k
        continue;
4588
5.27k
      }
4589
42.7k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
42.7k
    if (sym < obj_symbols (abfd)
4593
42.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
42.7k
    have_func = true;
4605
42.7k
    nbr_func++;
4606
42.7k
    cache_ptr->u.sym = (asymbol *) sym;
4607
42.7k
    if (sym->lineno != NULL)
4608
41.6k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
41.6k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
41.6k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
42.7k
    sym->lineno = cache_ptr;
4614
42.7k
    if (sym->symbol.value < prev_offset)
4615
945
      ordered = false;
4616
42.7k
    prev_offset = sym->symbol.value;
4617
42.7k
  }
4618
152k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
101k
  continue;
4622
50.3k
      else
4623
50.3k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
93.1k
      cache_ptr++;
4625
93.1k
    }
4626
4627
379
  asect->lineno_count = cache_ptr - lineno_cache;
4628
379
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
379
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
379
  if (!ordered)
4633
126
    {
4634
      /* Sort the table.  */
4635
126
      alent **func_table;
4636
126
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
126
      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
126
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
126
  {
4646
126
    alent **p = func_table;
4647
126
    unsigned int i;
4648
4649
90.1k
    for (i = 0; i < asect->lineno_count; i++)
4650
90.0k
      if (lineno_cache[i].line_number == 0)
4651
41.1k
        *p++ = &lineno_cache[i];
4652
4653
126
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
126
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
126
    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
126
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
126
      {
4666
126
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
41.2k
        for (i = 0; i < nbr_func; i++)
4669
41.1k
    {
4670
41.1k
      coff_symbol_type *sym;
4671
41.1k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
41.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
41.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
41.1k
      do
4680
90.0k
        *n_cache_ptr++ = *old_ptr++;
4681
90.0k
      while (old_ptr->line_number != 0);
4682
41.1k
    }
4683
4684
126
        memcpy (lineno_cache, n_lineno_cache,
4685
126
          asect->lineno_count * sizeof (alent));
4686
126
      }
4687
0
    else
4688
0
      ret = false;
4689
126
    bfd_release (abfd, func_table);
4690
126
  }
4691
0
      else
4692
0
  ret = false;
4693
126
    }
4694
4695
379
  return ret;
4696
379
}
coff-z8k.c:coff_slurp_line_table
Line
Count
Source
4499
1.43k
{
4500
1.43k
  LINENO *native_lineno;
4501
1.43k
  alent *lineno_cache;
4502
1.43k
  unsigned int counter;
4503
1.43k
  alent *cache_ptr;
4504
1.43k
  bfd_vma prev_offset = 0;
4505
1.43k
  bool ordered = true;
4506
1.43k
  unsigned int nbr_func;
4507
1.43k
  LINENO *src;
4508
1.43k
  bool have_func;
4509
1.43k
  bool ret = true;
4510
1.43k
  size_t amt;
4511
4512
1.43k
  if (asect->lineno_count == 0)
4513
955
    return true;
4514
4515
477
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
477
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
477
             asect->lineno_count,
4519
477
             bfd_coff_linesz (abfd));
4520
477
  if (native_lineno == NULL)
4521
251
    {
4522
251
      _bfd_error_handler
4523
251
  (_("%pB: warning: line number table read failed"), abfd);
4524
251
      return false;
4525
251
    }
4526
4527
226
  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
226
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
226
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
226
  cache_ptr = lineno_cache;
4541
226
  asect->lineno = lineno_cache;
4542
226
  src = native_lineno;
4543
226
  nbr_func = 0;
4544
226
  have_func = false;
4545
4546
337k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
337k
    {
4548
337k
      struct internal_lineno dst;
4549
4550
337k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
337k
      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
337k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
337k
      if (cache_ptr->line_number == 0)
4558
115k
  {
4559
115k
    combined_entry_type * ent;
4560
115k
    unsigned long symndx;
4561
115k
    coff_symbol_type *sym;
4562
4563
115k
    have_func = false;
4564
115k
    symndx = dst.l_addr.l_symndx;
4565
115k
    if (symndx >= obj_raw_syment_count (abfd))
4566
29.8k
      {
4567
29.8k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
29.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
29.8k
     abfd, symndx, counter);
4571
29.8k
        cache_ptr->line_number = -1;
4572
29.8k
        ret = false;
4573
29.8k
        continue;
4574
29.8k
      }
4575
4576
85.8k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
85.8k
    if (! ent->is_sym)
4580
1.65k
      {
4581
1.65k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
1.65k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
1.65k
     abfd, symndx, counter);
4585
1.65k
        cache_ptr->line_number = -1;
4586
1.65k
        ret = false;
4587
1.65k
        continue;
4588
1.65k
      }
4589
84.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
84.2k
    if (sym < obj_symbols (abfd)
4593
84.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
84.2k
    have_func = true;
4605
84.2k
    nbr_func++;
4606
84.2k
    cache_ptr->u.sym = (asymbol *) sym;
4607
84.2k
    if (sym->lineno != NULL)
4608
83.7k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
83.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
83.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
84.2k
    sym->lineno = cache_ptr;
4614
84.2k
    if (sym->symbol.value < prev_offset)
4615
418
      ordered = false;
4616
84.2k
    prev_offset = sym->symbol.value;
4617
84.2k
  }
4618
221k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
143k
  continue;
4622
78.2k
      else
4623
78.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
162k
      cache_ptr++;
4625
162k
    }
4626
4627
226
  asect->lineno_count = cache_ptr - lineno_cache;
4628
226
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
226
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
226
  if (!ordered)
4633
85
    {
4634
      /* Sort the table.  */
4635
85
      alent **func_table;
4636
85
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
85
      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
85
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
85
  {
4646
85
    alent **p = func_table;
4647
85
    unsigned int i;
4648
4649
115k
    for (i = 0; i < asect->lineno_count; i++)
4650
115k
      if (lineno_cache[i].line_number == 0)
4651
54.3k
        *p++ = &lineno_cache[i];
4652
4653
85
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
85
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
85
    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
85
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
85
      {
4666
85
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
54.4k
        for (i = 0; i < nbr_func; i++)
4669
54.3k
    {
4670
54.3k
      coff_symbol_type *sym;
4671
54.3k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
54.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
54.3k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
54.3k
      do
4680
115k
        *n_cache_ptr++ = *old_ptr++;
4681
115k
      while (old_ptr->line_number != 0);
4682
54.3k
    }
4683
4684
85
        memcpy (lineno_cache, n_lineno_cache,
4685
85
          asect->lineno_count * sizeof (alent));
4686
85
      }
4687
0
    else
4688
0
      ret = false;
4689
85
    bfd_release (abfd, func_table);
4690
85
  }
4691
0
      else
4692
0
  ret = false;
4693
85
    }
4694
4695
226
  return ret;
4696
226
}
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
610
{
4500
610
  LINENO *native_lineno;
4501
610
  alent *lineno_cache;
4502
610
  unsigned int counter;
4503
610
  alent *cache_ptr;
4504
610
  bfd_vma prev_offset = 0;
4505
610
  bool ordered = true;
4506
610
  unsigned int nbr_func;
4507
610
  LINENO *src;
4508
610
  bool have_func;
4509
610
  bool ret = true;
4510
610
  size_t amt;
4511
4512
610
  if (asect->lineno_count == 0)
4513
326
    return true;
4514
4515
284
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
284
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
284
             asect->lineno_count,
4519
284
             bfd_coff_linesz (abfd));
4520
284
  if (native_lineno == NULL)
4521
112
    {
4522
112
      _bfd_error_handler
4523
112
  (_("%pB: warning: line number table read failed"), abfd);
4524
112
      return false;
4525
112
    }
4526
4527
172
  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
172
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
172
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
172
  cache_ptr = lineno_cache;
4541
172
  asect->lineno = lineno_cache;
4542
172
  src = native_lineno;
4543
172
  nbr_func = 0;
4544
172
  have_func = false;
4545
4546
172k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
172k
    {
4548
172k
      struct internal_lineno dst;
4549
4550
172k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
172k
      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
172k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
172k
      if (cache_ptr->line_number == 0)
4558
80.9k
  {
4559
80.9k
    combined_entry_type * ent;
4560
80.9k
    unsigned long symndx;
4561
80.9k
    coff_symbol_type *sym;
4562
4563
80.9k
    have_func = false;
4564
80.9k
    symndx = dst.l_addr.l_symndx;
4565
80.9k
    if (symndx >= obj_raw_syment_count (abfd))
4566
36.7k
      {
4567
36.7k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
36.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
36.7k
     abfd, symndx, counter);
4571
36.7k
        cache_ptr->line_number = -1;
4572
36.7k
        ret = false;
4573
36.7k
        continue;
4574
36.7k
      }
4575
4576
44.1k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
44.1k
    if (! ent->is_sym)
4580
6.01k
      {
4581
6.01k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
6.01k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
6.01k
     abfd, symndx, counter);
4585
6.01k
        cache_ptr->line_number = -1;
4586
6.01k
        ret = false;
4587
6.01k
        continue;
4588
6.01k
      }
4589
38.1k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
38.1k
    if (sym < obj_symbols (abfd)
4593
38.1k
        || 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
38.1k
    have_func = true;
4605
38.1k
    nbr_func++;
4606
38.1k
    cache_ptr->u.sym = (asymbol *) sym;
4607
38.1k
    if (sym->lineno != NULL)
4608
37.1k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
37.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
37.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
38.1k
    sym->lineno = cache_ptr;
4614
38.1k
    if (sym->symbol.value < prev_offset)
4615
1.91k
      ordered = false;
4616
38.1k
    prev_offset = sym->symbol.value;
4617
38.1k
  }
4618
91.8k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
63.8k
  continue;
4622
28.0k
      else
4623
28.0k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
66.2k
      cache_ptr++;
4625
66.2k
    }
4626
4627
172
  asect->lineno_count = cache_ptr - lineno_cache;
4628
172
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
172
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
172
  if (!ordered)
4633
100
    {
4634
      /* Sort the table.  */
4635
100
      alent **func_table;
4636
100
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
100
      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
100
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
100
  {
4646
100
    alent **p = func_table;
4647
100
    unsigned int i;
4648
4649
63.2k
    for (i = 0; i < asect->lineno_count; i++)
4650
63.1k
      if (lineno_cache[i].line_number == 0)
4651
36.2k
        *p++ = &lineno_cache[i];
4652
4653
100
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
100
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
100
    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
100
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
100
      {
4666
100
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
36.3k
        for (i = 0; i < nbr_func; i++)
4669
36.2k
    {
4670
36.2k
      coff_symbol_type *sym;
4671
36.2k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
36.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
36.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
36.2k
      do
4680
63.1k
        *n_cache_ptr++ = *old_ptr++;
4681
63.1k
      while (old_ptr->line_number != 0);
4682
36.2k
    }
4683
4684
100
        memcpy (lineno_cache, n_lineno_cache,
4685
100
          asect->lineno_count * sizeof (alent));
4686
100
      }
4687
0
    else
4688
0
      ret = false;
4689
100
    bfd_release (abfd, func_table);
4690
100
  }
4691
0
      else
4692
0
  ret = false;
4693
100
    }
4694
4695
172
  return ret;
4696
172
}
pe-mcore.c:coff_slurp_line_table
Line
Count
Source
4499
1.04k
{
4500
1.04k
  LINENO *native_lineno;
4501
1.04k
  alent *lineno_cache;
4502
1.04k
  unsigned int counter;
4503
1.04k
  alent *cache_ptr;
4504
1.04k
  bfd_vma prev_offset = 0;
4505
1.04k
  bool ordered = true;
4506
1.04k
  unsigned int nbr_func;
4507
1.04k
  LINENO *src;
4508
1.04k
  bool have_func;
4509
1.04k
  bool ret = true;
4510
1.04k
  size_t amt;
4511
4512
1.04k
  if (asect->lineno_count == 0)
4513
679
    return true;
4514
4515
367
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
367
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
367
             asect->lineno_count,
4519
367
             bfd_coff_linesz (abfd));
4520
367
  if (native_lineno == NULL)
4521
123
    {
4522
123
      _bfd_error_handler
4523
123
  (_("%pB: warning: line number table read failed"), abfd);
4524
123
      return false;
4525
123
    }
4526
4527
244
  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
244
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
244
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
244
  cache_ptr = lineno_cache;
4541
244
  asect->lineno = lineno_cache;
4542
244
  src = native_lineno;
4543
244
  nbr_func = 0;
4544
244
  have_func = false;
4545
4546
674k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
674k
    {
4548
674k
      struct internal_lineno dst;
4549
4550
674k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
674k
      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
674k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
674k
      if (cache_ptr->line_number == 0)
4558
308k
  {
4559
308k
    combined_entry_type * ent;
4560
308k
    unsigned long symndx;
4561
308k
    coff_symbol_type *sym;
4562
4563
308k
    have_func = false;
4564
308k
    symndx = dst.l_addr.l_symndx;
4565
308k
    if (symndx >= obj_raw_syment_count (abfd))
4566
143k
      {
4567
143k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
143k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
143k
     abfd, symndx, counter);
4571
143k
        cache_ptr->line_number = -1;
4572
143k
        ret = false;
4573
143k
        continue;
4574
143k
      }
4575
4576
164k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
164k
    if (! ent->is_sym)
4580
32.4k
      {
4581
32.4k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
32.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
32.4k
     abfd, symndx, counter);
4585
32.4k
        cache_ptr->line_number = -1;
4586
32.4k
        ret = false;
4587
32.4k
        continue;
4588
32.4k
      }
4589
132k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
132k
    if (sym < obj_symbols (abfd)
4593
132k
        || 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
132k
    have_func = true;
4605
132k
    nbr_func++;
4606
132k
    cache_ptr->u.sym = (asymbol *) sym;
4607
132k
    if (sym->lineno != NULL)
4608
130k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
130k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
130k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
132k
    sym->lineno = cache_ptr;
4614
132k
    if (sym->symbol.value < prev_offset)
4615
2.22k
      ordered = false;
4616
132k
    prev_offset = sym->symbol.value;
4617
132k
  }
4618
366k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
258k
  continue;
4622
108k
      else
4623
108k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
240k
      cache_ptr++;
4625
240k
    }
4626
4627
244
  asect->lineno_count = cache_ptr - lineno_cache;
4628
244
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
244
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
244
  if (!ordered)
4633
128
    {
4634
      /* Sort the table.  */
4635
128
      alent **func_table;
4636
128
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
128
      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
128
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
128
  {
4646
128
    alent **p = func_table;
4647
128
    unsigned int i;
4648
4649
238k
    for (i = 0; i < asect->lineno_count; i++)
4650
238k
      if (lineno_cache[i].line_number == 0)
4651
131k
        *p++ = &lineno_cache[i];
4652
4653
128
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
128
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
128
    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
128
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
128
      {
4666
128
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
131k
        for (i = 0; i < nbr_func; i++)
4669
131k
    {
4670
131k
      coff_symbol_type *sym;
4671
131k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
131k
      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
131k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
131k
      do
4680
238k
        *n_cache_ptr++ = *old_ptr++;
4681
238k
      while (old_ptr->line_number != 0);
4682
131k
    }
4683
4684
128
        memcpy (lineno_cache, n_lineno_cache,
4685
128
          asect->lineno_count * sizeof (alent));
4686
128
      }
4687
0
    else
4688
0
      ret = false;
4689
128
    bfd_release (abfd, func_table);
4690
128
  }
4691
0
      else
4692
0
  ret = false;
4693
128
    }
4694
4695
244
  return ret;
4696
244
}
pe-sh.c:coff_slurp_line_table
Line
Count
Source
4499
1.20k
{
4500
1.20k
  LINENO *native_lineno;
4501
1.20k
  alent *lineno_cache;
4502
1.20k
  unsigned int counter;
4503
1.20k
  alent *cache_ptr;
4504
1.20k
  bfd_vma prev_offset = 0;
4505
1.20k
  bool ordered = true;
4506
1.20k
  unsigned int nbr_func;
4507
1.20k
  LINENO *src;
4508
1.20k
  bool have_func;
4509
1.20k
  bool ret = true;
4510
1.20k
  size_t amt;
4511
4512
1.20k
  if (asect->lineno_count == 0)
4513
793
    return true;
4514
4515
410
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
410
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
410
             asect->lineno_count,
4519
410
             bfd_coff_linesz (abfd));
4520
410
  if (native_lineno == NULL)
4521
163
    {
4522
163
      _bfd_error_handler
4523
163
  (_("%pB: warning: line number table read failed"), abfd);
4524
163
      return false;
4525
163
    }
4526
4527
247
  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
247
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
247
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
247
  cache_ptr = lineno_cache;
4541
247
  asect->lineno = lineno_cache;
4542
247
  src = native_lineno;
4543
247
  nbr_func = 0;
4544
247
  have_func = false;
4545
4546
681k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
681k
    {
4548
681k
      struct internal_lineno dst;
4549
4550
681k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
681k
      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
681k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
681k
      if (cache_ptr->line_number == 0)
4558
256k
  {
4559
256k
    combined_entry_type * ent;
4560
256k
    unsigned long symndx;
4561
256k
    coff_symbol_type *sym;
4562
4563
256k
    have_func = false;
4564
256k
    symndx = dst.l_addr.l_symndx;
4565
256k
    if (symndx >= obj_raw_syment_count (abfd))
4566
112k
      {
4567
112k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
112k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
112k
     abfd, symndx, counter);
4571
112k
        cache_ptr->line_number = -1;
4572
112k
        ret = false;
4573
112k
        continue;
4574
112k
      }
4575
4576
143k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
143k
    if (! ent->is_sym)
4580
29.1k
      {
4581
29.1k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
29.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
29.1k
     abfd, symndx, counter);
4585
29.1k
        cache_ptr->line_number = -1;
4586
29.1k
        ret = false;
4587
29.1k
        continue;
4588
29.1k
      }
4589
114k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
114k
    if (sym < obj_symbols (abfd)
4593
114k
        || 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
114k
    have_func = true;
4605
114k
    nbr_func++;
4606
114k
    cache_ptr->u.sym = (asymbol *) sym;
4607
114k
    if (sym->lineno != NULL)
4608
112k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
112k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
112k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
114k
    sym->lineno = cache_ptr;
4614
114k
    if (sym->symbol.value < prev_offset)
4615
4.49k
      ordered = false;
4616
114k
    prev_offset = sym->symbol.value;
4617
114k
  }
4618
424k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
254k
  continue;
4622
170k
      else
4623
170k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
284k
      cache_ptr++;
4625
284k
    }
4626
4627
247
  asect->lineno_count = cache_ptr - lineno_cache;
4628
247
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
247
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
247
  if (!ordered)
4633
134
    {
4634
      /* Sort the table.  */
4635
134
      alent **func_table;
4636
134
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
134
      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
134
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
134
  {
4646
134
    alent **p = func_table;
4647
134
    unsigned int i;
4648
4649
282k
    for (i = 0; i < asect->lineno_count; i++)
4650
281k
      if (lineno_cache[i].line_number == 0)
4651
113k
        *p++ = &lineno_cache[i];
4652
4653
134
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
134
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
134
    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
134
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
134
      {
4666
134
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
113k
        for (i = 0; i < nbr_func; i++)
4669
113k
    {
4670
113k
      coff_symbol_type *sym;
4671
113k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
113k
      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
113k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
113k
      do
4680
281k
        *n_cache_ptr++ = *old_ptr++;
4681
281k
      while (old_ptr->line_number != 0);
4682
113k
    }
4683
4684
134
        memcpy (lineno_cache, n_lineno_cache,
4685
134
          asect->lineno_count * sizeof (alent));
4686
134
      }
4687
0
    else
4688
0
      ret = false;
4689
134
    bfd_release (abfd, func_table);
4690
134
  }
4691
0
      else
4692
0
  ret = false;
4693
134
    }
4694
4695
247
  return ret;
4696
247
}
pei-arm-wince.c:coff_slurp_line_table
Line
Count
Source
4499
442
{
4500
442
  LINENO *native_lineno;
4501
442
  alent *lineno_cache;
4502
442
  unsigned int counter;
4503
442
  alent *cache_ptr;
4504
442
  bfd_vma prev_offset = 0;
4505
442
  bool ordered = true;
4506
442
  unsigned int nbr_func;
4507
442
  LINENO *src;
4508
442
  bool have_func;
4509
442
  bool ret = true;
4510
442
  size_t amt;
4511
4512
442
  if (asect->lineno_count == 0)
4513
190
    return true;
4514
4515
252
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
252
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
252
             asect->lineno_count,
4519
252
             bfd_coff_linesz (abfd));
4520
252
  if (native_lineno == NULL)
4521
93
    {
4522
93
      _bfd_error_handler
4523
93
  (_("%pB: warning: line number table read failed"), abfd);
4524
93
      return false;
4525
93
    }
4526
4527
159
  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
159
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
159
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
159
  cache_ptr = lineno_cache;
4541
159
  asect->lineno = lineno_cache;
4542
159
  src = native_lineno;
4543
159
  nbr_func = 0;
4544
159
  have_func = false;
4545
4546
315k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
315k
    {
4548
315k
      struct internal_lineno dst;
4549
4550
315k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
315k
      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
315k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
315k
      if (cache_ptr->line_number == 0)
4558
149k
  {
4559
149k
    combined_entry_type * ent;
4560
149k
    unsigned long symndx;
4561
149k
    coff_symbol_type *sym;
4562
4563
149k
    have_func = false;
4564
149k
    symndx = dst.l_addr.l_symndx;
4565
149k
    if (symndx >= obj_raw_syment_count (abfd))
4566
70.2k
      {
4567
70.2k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
70.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
70.2k
     abfd, symndx, counter);
4571
70.2k
        cache_ptr->line_number = -1;
4572
70.2k
        ret = false;
4573
70.2k
        continue;
4574
70.2k
      }
4575
4576
79.2k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
79.2k
    if (! ent->is_sym)
4580
9.27k
      {
4581
9.27k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
9.27k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
9.27k
     abfd, symndx, counter);
4585
9.27k
        cache_ptr->line_number = -1;
4586
9.27k
        ret = false;
4587
9.27k
        continue;
4588
9.27k
      }
4589
69.9k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
69.9k
    if (sym < obj_symbols (abfd)
4593
69.9k
        || 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
69.9k
    have_func = true;
4605
69.9k
    nbr_func++;
4606
69.9k
    cache_ptr->u.sym = (asymbol *) sym;
4607
69.9k
    if (sym->lineno != NULL)
4608
68.2k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
68.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
68.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
69.9k
    sym->lineno = cache_ptr;
4614
69.9k
    if (sym->symbol.value < prev_offset)
4615
2.56k
      ordered = false;
4616
69.9k
    prev_offset = sym->symbol.value;
4617
69.9k
  }
4618
165k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
108k
  continue;
4622
57.1k
      else
4623
57.1k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
127k
      cache_ptr++;
4625
127k
    }
4626
4627
159
  asect->lineno_count = cache_ptr - lineno_cache;
4628
159
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
159
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
159
  if (!ordered)
4633
99
    {
4634
      /* Sort the table.  */
4635
99
      alent **func_table;
4636
99
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
99
      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
99
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
99
  {
4646
99
    alent **p = func_table;
4647
99
    unsigned int i;
4648
4649
121k
    for (i = 0; i < asect->lineno_count; i++)
4650
120k
      if (lineno_cache[i].line_number == 0)
4651
66.6k
        *p++ = &lineno_cache[i];
4652
4653
99
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
99
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
99
    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
99
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
99
      {
4666
99
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
66.7k
        for (i = 0; i < nbr_func; i++)
4669
66.6k
    {
4670
66.6k
      coff_symbol_type *sym;
4671
66.6k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
66.6k
      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
66.6k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
66.6k
      do
4680
120k
        *n_cache_ptr++ = *old_ptr++;
4681
120k
      while (old_ptr->line_number != 0);
4682
66.6k
    }
4683
4684
99
        memcpy (lineno_cache, n_lineno_cache,
4685
99
          asect->lineno_count * sizeof (alent));
4686
99
      }
4687
0
    else
4688
0
      ret = false;
4689
99
    bfd_release (abfd, func_table);
4690
99
  }
4691
0
      else
4692
0
  ret = false;
4693
99
    }
4694
4695
159
  return ret;
4696
159
}
pei-arm.c:coff_slurp_line_table
Line
Count
Source
4499
1.13k
{
4500
1.13k
  LINENO *native_lineno;
4501
1.13k
  alent *lineno_cache;
4502
1.13k
  unsigned int counter;
4503
1.13k
  alent *cache_ptr;
4504
1.13k
  bfd_vma prev_offset = 0;
4505
1.13k
  bool ordered = true;
4506
1.13k
  unsigned int nbr_func;
4507
1.13k
  LINENO *src;
4508
1.13k
  bool have_func;
4509
1.13k
  bool ret = true;
4510
1.13k
  size_t amt;
4511
4512
1.13k
  if (asect->lineno_count == 0)
4513
720
    return true;
4514
4515
411
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
411
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
411
             asect->lineno_count,
4519
411
             bfd_coff_linesz (abfd));
4520
411
  if (native_lineno == NULL)
4521
235
    {
4522
235
      _bfd_error_handler
4523
235
  (_("%pB: warning: line number table read failed"), abfd);
4524
235
      return false;
4525
235
    }
4526
4527
176
  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
176
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
176
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
176
  cache_ptr = lineno_cache;
4541
176
  asect->lineno = lineno_cache;
4542
176
  src = native_lineno;
4543
176
  nbr_func = 0;
4544
176
  have_func = false;
4545
4546
156k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
156k
    {
4548
156k
      struct internal_lineno dst;
4549
4550
156k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
156k
      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
156k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
156k
      if (cache_ptr->line_number == 0)
4558
76.9k
  {
4559
76.9k
    combined_entry_type * ent;
4560
76.9k
    unsigned long symndx;
4561
76.9k
    coff_symbol_type *sym;
4562
4563
76.9k
    have_func = false;
4564
76.9k
    symndx = dst.l_addr.l_symndx;
4565
76.9k
    if (symndx >= obj_raw_syment_count (abfd))
4566
26.6k
      {
4567
26.6k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
26.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
26.6k
     abfd, symndx, counter);
4571
26.6k
        cache_ptr->line_number = -1;
4572
26.6k
        ret = false;
4573
26.6k
        continue;
4574
26.6k
      }
4575
4576
50.2k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
50.2k
    if (! ent->is_sym)
4580
3.31k
      {
4581
3.31k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
3.31k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
3.31k
     abfd, symndx, counter);
4585
3.31k
        cache_ptr->line_number = -1;
4586
3.31k
        ret = false;
4587
3.31k
        continue;
4588
3.31k
      }
4589
46.9k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
46.9k
    if (sym < obj_symbols (abfd)
4593
46.9k
        || 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
46.9k
    have_func = true;
4605
46.9k
    nbr_func++;
4606
46.9k
    cache_ptr->u.sym = (asymbol *) sym;
4607
46.9k
    if (sym->lineno != NULL)
4608
45.9k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
45.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
45.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
46.9k
    sym->lineno = cache_ptr;
4614
46.9k
    if (sym->symbol.value < prev_offset)
4615
1.22k
      ordered = false;
4616
46.9k
    prev_offset = sym->symbol.value;
4617
46.9k
  }
4618
79.4k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
55.3k
  continue;
4622
24.1k
      else
4623
24.1k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
71.0k
      cache_ptr++;
4625
71.0k
    }
4626
4627
176
  asect->lineno_count = cache_ptr - lineno_cache;
4628
176
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
176
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
176
  if (!ordered)
4633
88
    {
4634
      /* Sort the table.  */
4635
88
      alent **func_table;
4636
88
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
88
      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
88
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
88
  {
4646
88
    alent **p = func_table;
4647
88
    unsigned int i;
4648
4649
59.8k
    for (i = 0; i < asect->lineno_count; i++)
4650
59.7k
      if (lineno_cache[i].line_number == 0)
4651
39.9k
        *p++ = &lineno_cache[i];
4652
4653
88
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
88
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
88
    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
88
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
88
      {
4666
88
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
40.0k
        for (i = 0; i < nbr_func; i++)
4669
39.9k
    {
4670
39.9k
      coff_symbol_type *sym;
4671
39.9k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
39.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
39.9k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
39.9k
      do
4680
59.7k
        *n_cache_ptr++ = *old_ptr++;
4681
59.7k
      while (old_ptr->line_number != 0);
4682
39.9k
    }
4683
4684
88
        memcpy (lineno_cache, n_lineno_cache,
4685
88
          asect->lineno_count * sizeof (alent));
4686
88
      }
4687
0
    else
4688
0
      ret = false;
4689
88
    bfd_release (abfd, func_table);
4690
88
  }
4691
0
      else
4692
0
  ret = false;
4693
88
    }
4694
4695
176
  return ret;
4696
176
}
pei-mcore.c:coff_slurp_line_table
Line
Count
Source
4499
441
{
4500
441
  LINENO *native_lineno;
4501
441
  alent *lineno_cache;
4502
441
  unsigned int counter;
4503
441
  alent *cache_ptr;
4504
441
  bfd_vma prev_offset = 0;
4505
441
  bool ordered = true;
4506
441
  unsigned int nbr_func;
4507
441
  LINENO *src;
4508
441
  bool have_func;
4509
441
  bool ret = true;
4510
441
  size_t amt;
4511
4512
441
  if (asect->lineno_count == 0)
4513
152
    return true;
4514
4515
289
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
289
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
289
             asect->lineno_count,
4519
289
             bfd_coff_linesz (abfd));
4520
289
  if (native_lineno == NULL)
4521
147
    {
4522
147
      _bfd_error_handler
4523
147
  (_("%pB: warning: line number table read failed"), abfd);
4524
147
      return false;
4525
147
    }
4526
4527
142
  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
142
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
142
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
142
  cache_ptr = lineno_cache;
4541
142
  asect->lineno = lineno_cache;
4542
142
  src = native_lineno;
4543
142
  nbr_func = 0;
4544
142
  have_func = false;
4545
4546
31.7k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
31.6k
    {
4548
31.6k
      struct internal_lineno dst;
4549
4550
31.6k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
31.6k
      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
31.6k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
31.6k
      if (cache_ptr->line_number == 0)
4558
15.3k
  {
4559
15.3k
    combined_entry_type * ent;
4560
15.3k
    unsigned long symndx;
4561
15.3k
    coff_symbol_type *sym;
4562
4563
15.3k
    have_func = false;
4564
15.3k
    symndx = dst.l_addr.l_symndx;
4565
15.3k
    if (symndx >= obj_raw_syment_count (abfd))
4566
7.19k
      {
4567
7.19k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
7.19k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
7.19k
     abfd, symndx, counter);
4571
7.19k
        cache_ptr->line_number = -1;
4572
7.19k
        ret = false;
4573
7.19k
        continue;
4574
7.19k
      }
4575
4576
8.12k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
8.12k
    if (! ent->is_sym)
4580
883
      {
4581
883
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
883
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
883
     abfd, symndx, counter);
4585
883
        cache_ptr->line_number = -1;
4586
883
        ret = false;
4587
883
        continue;
4588
883
      }
4589
7.24k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
7.24k
    if (sym < obj_symbols (abfd)
4593
7.24k
        || 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
7.24k
    have_func = true;
4605
7.24k
    nbr_func++;
4606
7.24k
    cache_ptr->u.sym = (asymbol *) sym;
4607
7.24k
    if (sym->lineno != NULL)
4608
6.94k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
6.94k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
6.94k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
7.24k
    sym->lineno = cache_ptr;
4614
7.24k
    if (sym->symbol.value < prev_offset)
4615
290
      ordered = false;
4616
7.24k
    prev_offset = sym->symbol.value;
4617
7.24k
  }
4618
16.3k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
11.0k
  continue;
4622
5.32k
      else
4623
5.32k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
12.5k
      cache_ptr++;
4625
12.5k
    }
4626
4627
142
  asect->lineno_count = cache_ptr - lineno_cache;
4628
142
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
142
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
142
  if (!ordered)
4633
83
    {
4634
      /* Sort the table.  */
4635
83
      alent **func_table;
4636
83
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
83
      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
83
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
83
  {
4646
83
    alent **p = func_table;
4647
83
    unsigned int i;
4648
4649
12.1k
    for (i = 0; i < asect->lineno_count; i++)
4650
12.0k
      if (lineno_cache[i].line_number == 0)
4651
7.00k
        *p++ = &lineno_cache[i];
4652
4653
83
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
83
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
83
    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
83
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
83
      {
4666
83
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
7.08k
        for (i = 0; i < nbr_func; i++)
4669
7.00k
    {
4670
7.00k
      coff_symbol_type *sym;
4671
7.00k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
7.00k
      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
7.00k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
7.00k
      do
4680
12.0k
        *n_cache_ptr++ = *old_ptr++;
4681
12.0k
      while (old_ptr->line_number != 0);
4682
7.00k
    }
4683
4684
83
        memcpy (lineno_cache, n_lineno_cache,
4685
83
          asect->lineno_count * sizeof (alent));
4686
83
      }
4687
0
    else
4688
0
      ret = false;
4689
83
    bfd_release (abfd, func_table);
4690
83
  }
4691
0
      else
4692
0
  ret = false;
4693
83
    }
4694
4695
142
  return ret;
4696
142
}
pei-sh.c:coff_slurp_line_table
Line
Count
Source
4499
881
{
4500
881
  LINENO *native_lineno;
4501
881
  alent *lineno_cache;
4502
881
  unsigned int counter;
4503
881
  alent *cache_ptr;
4504
881
  bfd_vma prev_offset = 0;
4505
881
  bool ordered = true;
4506
881
  unsigned int nbr_func;
4507
881
  LINENO *src;
4508
881
  bool have_func;
4509
881
  bool ret = true;
4510
881
  size_t amt;
4511
4512
881
  if (asect->lineno_count == 0)
4513
582
    return true;
4514
4515
299
  BFD_ASSERT (asect->lineno == NULL);
4516
4517
299
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4518
299
             asect->lineno_count,
4519
299
             bfd_coff_linesz (abfd));
4520
299
  if (native_lineno == NULL)
4521
117
    {
4522
117
      _bfd_error_handler
4523
117
  (_("%pB: warning: line number table read failed"), abfd);
4524
117
      return false;
4525
117
    }
4526
4527
182
  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
182
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4534
182
  if (lineno_cache == NULL)
4535
0
    {
4536
0
      free (native_lineno);
4537
0
      return false;
4538
0
    }
4539
4540
182
  cache_ptr = lineno_cache;
4541
182
  asect->lineno = lineno_cache;
4542
182
  src = native_lineno;
4543
182
  nbr_func = 0;
4544
182
  have_func = false;
4545
4546
172k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4547
171k
    {
4548
171k
      struct internal_lineno dst;
4549
4550
171k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4551
171k
      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
171k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4556
4557
171k
      if (cache_ptr->line_number == 0)
4558
79.2k
  {
4559
79.2k
    combined_entry_type * ent;
4560
79.2k
    unsigned long symndx;
4561
79.2k
    coff_symbol_type *sym;
4562
4563
79.2k
    have_func = false;
4564
79.2k
    symndx = dst.l_addr.l_symndx;
4565
79.2k
    if (symndx >= obj_raw_syment_count (abfd))
4566
38.2k
      {
4567
38.2k
        _bfd_error_handler
4568
    /* xgettext:c-format */
4569
38.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4570
38.2k
     abfd, symndx, counter);
4571
38.2k
        cache_ptr->line_number = -1;
4572
38.2k
        ret = false;
4573
38.2k
        continue;
4574
38.2k
      }
4575
4576
40.9k
    ent = obj_raw_syments (abfd) + symndx;
4577
    /* FIXME: We should not be casting between ints and
4578
       pointers like this.  */
4579
40.9k
    if (! ent->is_sym)
4580
3.31k
      {
4581
3.31k
        _bfd_error_handler
4582
    /* xgettext:c-format */
4583
3.31k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4584
3.31k
     abfd, symndx, counter);
4585
3.31k
        cache_ptr->line_number = -1;
4586
3.31k
        ret = false;
4587
3.31k
        continue;
4588
3.31k
      }
4589
37.6k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4590
4591
    /* PR 17512 file: 078-10659-0.004  */
4592
37.6k
    if (sym < obj_symbols (abfd)
4593
37.6k
        || 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
37.6k
    have_func = true;
4605
37.6k
    nbr_func++;
4606
37.6k
    cache_ptr->u.sym = (asymbol *) sym;
4607
37.6k
    if (sym->lineno != NULL)
4608
36.7k
      _bfd_error_handler
4609
        /* xgettext:c-format */
4610
36.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4611
36.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4612
4613
37.6k
    sym->lineno = cache_ptr;
4614
37.6k
    if (sym->symbol.value < prev_offset)
4615
1.12k
      ordered = false;
4616
37.6k
    prev_offset = sym->symbol.value;
4617
37.6k
  }
4618
92.6k
      else if (!have_func)
4619
  /* Drop line information that has no associated function.
4620
     PR 17521: file: 078-10659-0.004.  */
4621
57.1k
  continue;
4622
35.5k
      else
4623
35.5k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4624
73.1k
      cache_ptr++;
4625
73.1k
    }
4626
4627
182
  asect->lineno_count = cache_ptr - lineno_cache;
4628
182
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4629
182
  free (native_lineno);
4630
4631
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4632
182
  if (!ordered)
4633
126
    {
4634
      /* Sort the table.  */
4635
126
      alent **func_table;
4636
126
      alent *n_lineno_cache;
4637
4638
      /* Create a table of functions.  */
4639
126
      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
126
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4645
126
  {
4646
126
    alent **p = func_table;
4647
126
    unsigned int i;
4648
4649
71.3k
    for (i = 0; i < asect->lineno_count; i++)
4650
71.2k
      if (lineno_cache[i].line_number == 0)
4651
36.5k
        *p++ = &lineno_cache[i];
4652
4653
126
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4654
4655
    /* Sort by functions.  */
4656
126
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4657
4658
    /* Create the new sorted table.  */
4659
126
    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
126
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4665
126
      {
4666
126
        alent *n_cache_ptr = n_lineno_cache;
4667
4668
36.6k
        for (i = 0; i < nbr_func; i++)
4669
36.5k
    {
4670
36.5k
      coff_symbol_type *sym;
4671
36.5k
      alent *old_ptr = func_table[i];
4672
4673
      /* Update the function entry.  */
4674
36.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
36.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4678
      /* Copy the function and line number entries.  */
4679
36.5k
      do
4680
71.2k
        *n_cache_ptr++ = *old_ptr++;
4681
71.2k
      while (old_ptr->line_number != 0);
4682
36.5k
    }
4683
4684
126
        memcpy (lineno_cache, n_lineno_cache,
4685
126
          asect->lineno_count * sizeof (alent));
4686
126
      }
4687
0
    else
4688
0
      ret = false;
4689
126
    bfd_release (abfd, func_table);
4690
126
  }
4691
0
      else
4692
0
  ret = false;
4693
126
    }
4694
4695
182
  return ret;
4696
182
}
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
55.1k
{
4705
55.1k
  combined_entry_type *native_symbols;
4706
55.1k
  coff_symbol_type *cached_area;
4707
55.1k
  unsigned int *table_ptr;
4708
55.1k
  unsigned int number_of_symbols = 0;
4709
55.1k
  bool ret = true;
4710
55.1k
  size_t amt;
4711
4712
55.1k
  if (obj_symbols (abfd))
4713
12.1k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
42.9k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
30.4k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
12.5k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
12.5k
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
12.5k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
12.5k
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
12.5k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
12.5k
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
12.5k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
12.5k
  if (table_ptr == NULL)
4738
0
    return false;
4739
12.5k
  else
4740
12.5k
    {
4741
12.5k
      coff_symbol_type *dst = cached_area;
4742
12.5k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
12.5k
      unsigned int this_index = 0;
4744
4745
2.96M
      while (this_index < last_native_index)
4746
2.95M
  {
4747
2.95M
    combined_entry_type *src = native_symbols + this_index;
4748
2.95M
    table_ptr[this_index] = number_of_symbols;
4749
4750
2.95M
    dst->symbol.the_bfd = abfd;
4751
2.95M
    BFD_ASSERT (src->is_sym);
4752
2.95M
    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
2.95M
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
2.95M
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
2.95M
                 src->u.syment.n_scnum);
4757
2.95M
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
2.95M
    dst->symbol.value = 0;
4760
2.95M
    dst->done_lineno = false;
4761
4762
2.95M
    switch (src->u.syment.n_sclass)
4763
2.95M
      {
4764
77.1k
      case C_EXT:
4765
80.7k
      case C_WEAKEXT:
4766
#if defined ARM
4767
3.61k
      case C_THUMBEXT:
4768
3.67k
      case C_THUMBEXTFUNC:
4769
#endif
4770
#ifdef RS6000COFF_C
4771
18.8k
      case C_HIDEXT:
4772
18.8k
#ifndef AIX_WEAK_SUPPORT
4773
20.5k
      case C_AIX_WEAKEXT:
4774
#endif
4775
#endif
4776
20.5k
#ifdef C_SYSTEM
4777
93.2k
      case C_SYSTEM: /* System Wide variable.  */
4778
93.2k
#endif
4779
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
57.6k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
79.2k
      case C_NT_WEAK:
4784
#endif
4785
79.2k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
79.2k
    {
4787
101k
    case COFF_SYMBOL_GLOBAL:
4788
101k
      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
101k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
5.05k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
101k
      break;
4802
4803
8.65k
    case COFF_SYMBOL_COMMON:
4804
8.65k
      dst->symbol.section = bfd_com_section_ptr;
4805
8.65k
      dst->symbol.value = src->u.syment.n_value;
4806
8.65k
      break;
4807
4808
5.02k
    case COFF_SYMBOL_UNDEFINED:
4809
5.02k
      dst->symbol.section = bfd_und_section_ptr;
4810
5.02k
      dst->symbol.value = 0;
4811
5.02k
      break;
4812
4813
320
    case COFF_SYMBOL_PE_SECTION:
4814
320
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
320
      dst->symbol.value = 0;
4816
320
      break;
4817
4818
776
    case COFF_SYMBOL_LOCAL:
4819
776
      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
776
      if (ISFCN ((src->u.syment.n_type)))
4829
458
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
776
      break;
4831
79.2k
    }
4832
4833
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
22.1k
        if (src->u.syment.n_numaux > 0)
4836
20.2k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
#endif
4838
4839
#ifdef COFF_WITH_PE
4840
79.2k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
21.6k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
79.2k
        if (src->u.syment.n_sclass == C_SECTION
4844
79.2k
      && src->u.syment.n_scnum > 0)
4845
320
    dst->symbol.flags = BSF_LOCAL;
4846
#endif
4847
116k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
21.6k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
14.7k
      )
4852
5.33k
    dst->symbol.flags |= BSF_WEAK;
4853
4854
14.7k
        break;
4855
4856
48.7k
      case C_STAT:  /* Static.  */
4857
#if defined ARM
4858
2.31k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
2.37k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
2.50k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
#endif
4862
#ifdef RS6000COFF_C
4863
2.63k
      case C_DWARF:  /* A label in a dwarf section.  */
4864
4.96k
      case C_INFO:  /* A label in a comment section.  */
4865
#endif
4866
68.2k
      case C_LABEL:  /* Label.  */
4867
68.2k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
48
    dst->symbol.flags = BSF_DEBUGGING;
4869
68.2k
        else
4870
68.2k
    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
68.2k
        if (dst->symbol.section)
4875
68.2k
    {
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
68.2k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
68.2k
        break;
4888
4889
17.3k
      case C_FILE: /* File name.  */
4890
17.3k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
35.7k
      case C_MOS:   /* Member of structure.  */
4893
44.3k
      case C_EOS:   /* End of structure.  */
4894
51.4k
      case C_REGPARM: /* Register parameter.  */
4895
80.0k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
92.0k
      case C_TPDEF: /* Type definition.  */
4898
112k
      case C_ARG:
4899
228k
      case C_AUTO: /* Automatic variable.  */
4900
239k
      case C_FIELD: /* Bit field.  */
4901
246k
      case C_ENTAG: /* Enumeration tag.  */
4902
262k
      case C_MOE:   /* Member of enumeration.  */
4903
276k
      case C_MOU:   /* Member of union.  */
4904
288k
      case C_UNTAG: /* Union tag.  */
4905
307k
      case C_STRTAG: /* Structure tag.  */
4906
#ifdef RS6000COFF_C
4907
34.5k
      case C_GSYM:
4908
36.5k
      case C_LSYM:
4909
36.7k
      case C_PSYM:
4910
38.1k
      case C_RSYM:
4911
38.6k
      case C_RPSYM:
4912
38.9k
      case C_STSYM:
4913
39.3k
      case C_TCSYM:
4914
39.6k
      case C_BCOMM:
4915
40.0k
      case C_ECOML:
4916
40.4k
      case C_ECOMM:
4917
40.9k
      case C_DECL:
4918
41.0k
      case C_ENTRY:
4919
41.1k
      case C_FUN:
4920
41.6k
      case C_ESTAT:
4921
#endif
4922
314k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
41.6k
        dst->symbol.value = (src->u.syment.n_value);
4924
41.6k
        break;
4925
4926
#ifdef RS6000COFF_C
4927
3.54k
      case C_BINCL: /* Beginning of include file.  */
4928
4.65k
      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
4.65k
        {
4934
4.65k
    asection *sec;
4935
4936
4.65k
    dst->symbol.flags = BSF_DEBUGGING;
4937
1.11M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
1.10M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
1.10M
          && ((file_ptr) (sec->line_filepos
4940
946k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
946k
        > (file_ptr) src->u.syment.n_value))
4942
1.79k
        break;
4943
4.65k
    if (sec == NULL)
4944
2.86k
      dst->symbol.value = 0;
4945
1.79k
    else
4946
1.79k
      {
4947
1.79k
        dst->symbol.section = sec;
4948
1.79k
        dst->symbol.value = ((src->u.syment.n_value
4949
1.79k
            - sec->line_filepos)
4950
1.79k
           / bfd_coff_linesz (abfd));
4951
1.79k
        src->fix_line = 1;
4952
1.79k
      }
4953
4.65k
        }
4954
4.65k
        break;
4955
4956
637
      case C_BSTAT:
4957
637
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
637
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
627
    dst->symbol.value = 0;
4961
10
        else
4962
10
    {
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
10
      src->u.syment.n_value
4967
10
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
10
      dst->symbol.value = src->u.syment.n_value;
4969
10
      src->fix_value = 1;
4970
10
    }
4971
637
        break;
4972
0
#endif
4973
4974
5.90k
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
43.0k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
55.8k
      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
40.3k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
40.3k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
40.3k
      dst->symbol.flags = BSF_DEBUGGING;
4986
40.3k
    }
4987
17
        else
4988
17
    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
15.4k
        dst->symbol.flags = BSF_LOCAL;
4993
        dst->symbol.value = (src->u.syment.n_value
4994
           - dst->symbol.section->vma);
4995
#endif
4996
55.8k
        break;
4997
4998
9.56k
      case C_STATLAB: /* Static load time label.  */
4999
9.56k
        dst->symbol.value = src->u.syment.n_value;
5000
9.56k
        dst->symbol.flags = BSF_GLOBAL;
5001
9.56k
        break;
5002
5003
1.88M
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
1.88M
        if (src->u.syment.n_type == 0
5007
1.88M
      && src->u.syment.n_value == 0
5008
1.88M
      && src->u.syment.n_scnum == 0)
5009
704k
    break;
5010
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
66.8k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
3
    break;
5014
66.8k
#endif
5015
        /* Fall through.  */
5016
1.18M
      case C_EXTDEF: /* External definition.  */
5017
1.18M
      case C_ULABEL: /* Undefined label.  */
5018
1.18M
      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
387k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
394k
      case C_ALIAS: /* Duplicate tag.  */
5025
394k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
84.1k
      case C_UEXT: /* Tentative external definition.  */
5029
#endif
5030
1.20M
      case C_EXTLAB: /* External load time label.  */
5031
1.67M
      default:
5032
1.67M
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
1.67M
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
1.67M
     abfd, src->u.syment.n_sclass,
5036
1.67M
     dst->symbol.section->name, dst->symbol.name);
5037
1.67M
        ret = false;
5038
        /* Fall through.  */
5039
1.67M
      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
1.67M
        dst->symbol.flags = BSF_DEBUGGING;
5043
1.67M
        dst->symbol.value = (src->u.syment.n_value);
5044
1.67M
        break;
5045
2.95M
      }
5046
5047
2.95M
    dst->native = src;
5048
2.95M
    dst->symbol.udata.i = 0;
5049
2.95M
    dst->lineno = NULL;
5050
5051
2.95M
    this_index += (src->u.syment.n_numaux) + 1;
5052
2.95M
    dst++;
5053
2.95M
    number_of_symbols++;
5054
2.95M
  }
5055
12.5k
    }
5056
5057
12.5k
  obj_symbols (abfd) = cached_area;
5058
12.5k
  obj_raw_syments (abfd) = native_symbols;
5059
5060
12.5k
  abfd->symcount = number_of_symbols;
5061
12.5k
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
12.5k
  {
5064
12.5k
    asection *p;
5065
5066
12.5k
    p = abfd->sections;
5067
48.0k
    while (p)
5068
44.6k
      {
5069
44.6k
  if (! coff_slurp_line_table (abfd, p))
5070
9.14k
    return false;
5071
35.4k
  p = p->next;
5072
35.4k
      }
5073
12.5k
  }
5074
5075
3.38k
  return ret;
5076
12.5k
}
pei-i386.c:coff_slurp_symbol_table
Line
Count
Source
4704
732
{
4705
732
  combined_entry_type *native_symbols;
4706
732
  coff_symbol_type *cached_area;
4707
732
  unsigned int *table_ptr;
4708
732
  unsigned int number_of_symbols = 0;
4709
732
  bool ret = true;
4710
732
  size_t amt;
4711
4712
732
  if (obj_symbols (abfd))
4713
100
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
632
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
238
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
394
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
394
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
394
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
394
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
394
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
394
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
394
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
394
  if (table_ptr == NULL)
4738
0
    return false;
4739
394
  else
4740
394
    {
4741
394
      coff_symbol_type *dst = cached_area;
4742
394
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
394
      unsigned int this_index = 0;
4744
4745
52.0k
      while (this_index < last_native_index)
4746
51.6k
  {
4747
51.6k
    combined_entry_type *src = native_symbols + this_index;
4748
51.6k
    table_ptr[this_index] = number_of_symbols;
4749
4750
51.6k
    dst->symbol.the_bfd = abfd;
4751
51.6k
    BFD_ASSERT (src->is_sym);
4752
51.6k
    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
51.6k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
51.6k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
51.6k
                 src->u.syment.n_scnum);
4757
51.6k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
51.6k
    dst->symbol.value = 0;
4760
51.6k
    dst->done_lineno = false;
4761
4762
51.6k
    switch (src->u.syment.n_sclass)
4763
51.6k
      {
4764
753
      case C_EXT:
4765
805
      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
805
#ifdef C_SYSTEM
4777
902
      case C_SYSTEM: /* System Wide variable.  */
4778
902
#endif
4779
902
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
920
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
1.46k
      case C_NT_WEAK:
4784
1.46k
#endif
4785
1.46k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
1.46k
    {
4787
1.25k
    case COFF_SYMBOL_GLOBAL:
4788
1.25k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
1.25k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
1.25k
      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
1.25k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
43
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
1.25k
      break;
4802
4803
127
    case COFF_SYMBOL_COMMON:
4804
127
      dst->symbol.section = bfd_com_section_ptr;
4805
127
      dst->symbol.value = src->u.syment.n_value;
4806
127
      break;
4807
4808
85
    case COFF_SYMBOL_UNDEFINED:
4809
85
      dst->symbol.section = bfd_und_section_ptr;
4810
85
      dst->symbol.value = 0;
4811
85
      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
1.46k
    }
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
1.46k
#ifdef COFF_WITH_PE
4840
1.46k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
544
    dst->symbol.flags |= BSF_WEAK;
4842
4843
1.46k
        if (src->u.syment.n_sclass == C_SECTION
4844
1.46k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
1.46k
#endif
4847
1.46k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
1.46k
      )
4852
52
    dst->symbol.flags |= BSF_WEAK;
4853
4854
1.46k
        break;
4855
4856
1.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
1.45k
      case C_LABEL:  /* Label.  */
4867
1.45k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.45k
        else
4870
1.45k
    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
1.45k
        if (dst->symbol.section)
4875
1.45k
    {
4876
1.45k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
1.45k
      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
1.45k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.45k
        break;
4888
4889
303
      case C_FILE: /* File name.  */
4890
303
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.00k
      case C_MOS:   /* Member of structure.  */
4893
1.19k
      case C_EOS:   /* End of structure.  */
4894
1.32k
      case C_REGPARM: /* Register parameter.  */
4895
1.68k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
1.79k
      case C_TPDEF: /* Type definition.  */
4898
2.12k
      case C_ARG:
4899
4.30k
      case C_AUTO: /* Automatic variable.  */
4900
4.63k
      case C_FIELD: /* Bit field.  */
4901
4.82k
      case C_ENTAG: /* Enumeration tag.  */
4902
5.08k
      case C_MOE:   /* Member of enumeration.  */
4903
5.17k
      case C_MOU:   /* Member of union.  */
4904
5.26k
      case C_UNTAG: /* Union tag.  */
4905
5.58k
      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
5.58k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
5.58k
        dst->symbol.value = (src->u.syment.n_value);
4924
5.58k
        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
162
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
916
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.15k
      case C_EFCN: /* Physical end of function.  */
4977
1.15k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
1.15k
        dst->symbol.value = src->u.syment.n_value;
4981
1.15k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
1.15k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
1.15k
      dst->symbol.flags = BSF_DEBUGGING;
4986
1.15k
    }
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
1.15k
        break;
4997
4998
160
      case C_STATLAB: /* Static load time label.  */
4999
160
        dst->symbol.value = src->u.syment.n_value;
5000
160
        dst->symbol.flags = BSF_GLOBAL;
5001
160
        break;
5002
5003
31.0k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
31.0k
        if (src->u.syment.n_type == 0
5007
31.0k
      && src->u.syment.n_value == 0
5008
31.0k
      && src->u.syment.n_scnum == 0)
5009
8.90k
    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
22.2k
      case C_EXTDEF: /* External definition.  */
5017
22.4k
      case C_ULABEL: /* Undefined label.  */
5018
22.5k
      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
22.5k
      case C_EXTLAB: /* External load time label.  */
5031
32.8k
      default:
5032
32.8k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
32.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
32.8k
     abfd, src->u.syment.n_sclass,
5036
32.8k
     dst->symbol.section->name, dst->symbol.name);
5037
32.8k
        ret = false;
5038
        /* Fall through.  */
5039
32.8k
      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
32.8k
        dst->symbol.flags = BSF_DEBUGGING;
5043
32.8k
        dst->symbol.value = (src->u.syment.n_value);
5044
32.8k
        break;
5045
51.6k
      }
5046
5047
51.6k
    dst->native = src;
5048
51.6k
    dst->symbol.udata.i = 0;
5049
51.6k
    dst->lineno = NULL;
5050
5051
51.6k
    this_index += (src->u.syment.n_numaux) + 1;
5052
51.6k
    dst++;
5053
51.6k
    number_of_symbols++;
5054
51.6k
  }
5055
394
    }
5056
5057
394
  obj_symbols (abfd) = cached_area;
5058
394
  obj_raw_syments (abfd) = native_symbols;
5059
5060
394
  abfd->symcount = number_of_symbols;
5061
394
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
394
  {
5064
394
    asection *p;
5065
5066
394
    p = abfd->sections;
5067
762
    while (p)
5068
720
      {
5069
720
  if (! coff_slurp_line_table (abfd, p))
5070
352
    return false;
5071
368
  p = p->next;
5072
368
      }
5073
394
  }
5074
5075
42
  return ret;
5076
394
}
pe-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.87k
{
4705
1.87k
  combined_entry_type *native_symbols;
4706
1.87k
  coff_symbol_type *cached_area;
4707
1.87k
  unsigned int *table_ptr;
4708
1.87k
  unsigned int number_of_symbols = 0;
4709
1.87k
  bool ret = true;
4710
1.87k
  size_t amt;
4711
4712
1.87k
  if (obj_symbols (abfd))
4713
515
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.36k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
591
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
769
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
769
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
769
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
769
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
769
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
769
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
769
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
769
  if (table_ptr == NULL)
4738
0
    return false;
4739
769
  else
4740
769
    {
4741
769
      coff_symbol_type *dst = cached_area;
4742
769
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
769
      unsigned int this_index = 0;
4744
4745
127k
      while (this_index < last_native_index)
4746
126k
  {
4747
126k
    combined_entry_type *src = native_symbols + this_index;
4748
126k
    table_ptr[this_index] = number_of_symbols;
4749
4750
126k
    dst->symbol.the_bfd = abfd;
4751
126k
    BFD_ASSERT (src->is_sym);
4752
126k
    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
126k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
126k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
126k
                 src->u.syment.n_scnum);
4757
126k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
126k
    dst->symbol.value = 0;
4760
126k
    dst->done_lineno = false;
4761
4762
126k
    switch (src->u.syment.n_sclass)
4763
126k
      {
4764
1.43k
      case C_EXT:
4765
1.53k
      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.53k
#ifdef C_SYSTEM
4777
1.77k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.77k
#endif
4779
1.77k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
2.18k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
3.39k
      case C_NT_WEAK:
4784
3.39k
#endif
4785
3.39k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.39k
    {
4787
2.55k
    case COFF_SYMBOL_GLOBAL:
4788
2.55k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.55k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.55k
      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.55k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
78
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.55k
      break;
4802
4803
329
    case COFF_SYMBOL_COMMON:
4804
329
      dst->symbol.section = bfd_com_section_ptr;
4805
329
      dst->symbol.value = src->u.syment.n_value;
4806
329
      break;
4807
4808
191
    case COFF_SYMBOL_UNDEFINED:
4809
191
      dst->symbol.section = bfd_und_section_ptr;
4810
191
      dst->symbol.value = 0;
4811
191
      break;
4812
4813
320
    case COFF_SYMBOL_PE_SECTION:
4814
320
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4815
320
      dst->symbol.value = 0;
4816
320
      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
3.39k
    }
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
3.39k
#ifdef COFF_WITH_PE
4840
3.39k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.21k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
3.39k
        if (src->u.syment.n_sclass == C_SECTION
4844
3.39k
      && src->u.syment.n_scnum > 0)
4845
320
    dst->symbol.flags = BSF_LOCAL;
4846
3.39k
#endif
4847
3.39k
        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.39k
      )
4852
101
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.39k
        break;
4855
4856
876
      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
1.37k
      case C_LABEL:  /* Label.  */
4867
1.37k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
4
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.37k
        else
4870
1.37k
    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
1.37k
        if (dst->symbol.section)
4875
1.37k
    {
4876
1.37k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
1.37k
      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
1.37k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.37k
        break;
4888
4889
1.01k
      case C_FILE: /* File name.  */
4890
1.01k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.86k
      case C_MOS:   /* Member of structure.  */
4893
2.18k
      case C_EOS:   /* End of structure.  */
4894
2.72k
      case C_REGPARM: /* Register parameter.  */
4895
3.14k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.42k
      case C_TPDEF: /* Type definition.  */
4898
3.96k
      case C_ARG:
4899
6.63k
      case C_AUTO: /* Automatic variable.  */
4900
7.02k
      case C_FIELD: /* Bit field.  */
4901
7.36k
      case C_ENTAG: /* Enumeration tag.  */
4902
8.29k
      case C_MOE:   /* Member of enumeration.  */
4903
8.59k
      case C_MOU:   /* Member of union.  */
4904
9.01k
      case C_UNTAG: /* Union tag.  */
4905
9.48k
      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
9.48k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
9.48k
        dst->symbol.value = (src->u.syment.n_value);
4924
9.48k
        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
234
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.05k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.74k
      case C_EFCN: /* Physical end of function.  */
4977
2.74k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.74k
        dst->symbol.value = src->u.syment.n_value;
4981
2.74k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.74k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.74k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.74k
    }
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
2.74k
        break;
4997
4998
320
      case C_STATLAB: /* Static load time label.  */
4999
320
        dst->symbol.value = src->u.syment.n_value;
5000
320
        dst->symbol.flags = BSF_GLOBAL;
5001
320
        break;
5002
5003
88.7k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
88.7k
        if (src->u.syment.n_type == 0
5007
88.7k
      && src->u.syment.n_value == 0
5008
88.7k
      && src->u.syment.n_scnum == 0)
5009
41.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
47.8k
      case C_EXTDEF: /* External definition.  */
5017
47.9k
      case C_ULABEL: /* Undefined label.  */
5018
48.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
48.1k
      case C_EXTLAB: /* External load time label.  */
5031
67.7k
      default:
5032
67.7k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
67.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
67.7k
     abfd, src->u.syment.n_sclass,
5036
67.7k
     dst->symbol.section->name, dst->symbol.name);
5037
67.7k
        ret = false;
5038
        /* Fall through.  */
5039
67.8k
      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
67.8k
        dst->symbol.flags = BSF_DEBUGGING;
5043
67.8k
        dst->symbol.value = (src->u.syment.n_value);
5044
67.8k
        break;
5045
126k
      }
5046
5047
126k
    dst->native = src;
5048
126k
    dst->symbol.udata.i = 0;
5049
126k
    dst->lineno = NULL;
5050
5051
126k
    this_index += (src->u.syment.n_numaux) + 1;
5052
126k
    dst++;
5053
126k
    number_of_symbols++;
5054
126k
  }
5055
769
    }
5056
5057
769
  obj_symbols (abfd) = cached_area;
5058
769
  obj_raw_syments (abfd) = native_symbols;
5059
5060
769
  abfd->symcount = number_of_symbols;
5061
769
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
769
  {
5064
769
    asection *p;
5065
5066
769
    p = abfd->sections;
5067
3.38k
    while (p)
5068
3.06k
      {
5069
3.06k
  if (! coff_slurp_line_table (abfd, p))
5070
452
    return false;
5071
2.61k
  p = p->next;
5072
2.61k
      }
5073
769
  }
5074
5075
317
  return ret;
5076
769
}
pei-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
860
{
4705
860
  combined_entry_type *native_symbols;
4706
860
  coff_symbol_type *cached_area;
4707
860
  unsigned int *table_ptr;
4708
860
  unsigned int number_of_symbols = 0;
4709
860
  bool ret = true;
4710
860
  size_t amt;
4711
4712
860
  if (obj_symbols (abfd))
4713
157
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
703
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
258
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
445
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
445
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
445
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
445
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
445
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
445
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
445
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
445
  if (table_ptr == NULL)
4738
0
    return false;
4739
445
  else
4740
445
    {
4741
445
      coff_symbol_type *dst = cached_area;
4742
445
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
445
      unsigned int this_index = 0;
4744
4745
77.2k
      while (this_index < last_native_index)
4746
76.7k
  {
4747
76.7k
    combined_entry_type *src = native_symbols + this_index;
4748
76.7k
    table_ptr[this_index] = number_of_symbols;
4749
4750
76.7k
    dst->symbol.the_bfd = abfd;
4751
76.7k
    BFD_ASSERT (src->is_sym);
4752
76.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
76.7k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
76.7k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
76.7k
                 src->u.syment.n_scnum);
4757
76.7k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
76.7k
    dst->symbol.value = 0;
4760
76.7k
    dst->done_lineno = false;
4761
4762
76.7k
    switch (src->u.syment.n_sclass)
4763
76.7k
      {
4764
10.5k
      case C_EXT:
4765
10.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
10.6k
#ifdef C_SYSTEM
4777
10.8k
      case C_SYSTEM: /* System Wide variable.  */
4778
10.8k
#endif
4779
10.8k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
10.8k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
11.4k
      case C_NT_WEAK:
4784
11.4k
#endif
4785
11.4k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
11.4k
    {
4787
9.76k
    case COFF_SYMBOL_GLOBAL:
4788
9.76k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
9.76k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
9.76k
      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
9.76k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
1.55k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
9.76k
      break;
4802
4803
203
    case COFF_SYMBOL_COMMON:
4804
203
      dst->symbol.section = bfd_com_section_ptr;
4805
203
      dst->symbol.value = src->u.syment.n_value;
4806
203
      break;
4807
4808
1.50k
    case COFF_SYMBOL_UNDEFINED:
4809
1.50k
      dst->symbol.section = bfd_und_section_ptr;
4810
1.50k
      dst->symbol.value = 0;
4811
1.50k
      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.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
11.4k
#ifdef COFF_WITH_PE
4840
11.4k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
623
    dst->symbol.flags |= BSF_WEAK;
4842
4843
11.4k
        if (src->u.syment.n_sclass == C_SECTION
4844
11.4k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
11.4k
#endif
4847
11.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
11.4k
      )
4852
60
    dst->symbol.flags |= BSF_WEAK;
4853
4854
11.4k
        break;
4855
4856
14.9k
      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
15.1k
      case C_LABEL:  /* Label.  */
4867
15.1k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
15.1k
        else
4870
15.1k
    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
15.1k
        if (dst->symbol.section)
4875
15.1k
    {
4876
15.1k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
15.1k
      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
15.1k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
15.1k
        break;
4888
4889
1.52k
      case C_FILE: /* File name.  */
4890
1.52k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.79k
      case C_MOS:   /* Member of structure.  */
4893
1.94k
      case C_EOS:   /* End of structure.  */
4894
2.16k
      case C_REGPARM: /* Register parameter.  */
4895
2.64k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.81k
      case C_TPDEF: /* Type definition.  */
4898
3.16k
      case C_ARG:
4899
5.44k
      case C_AUTO: /* Automatic variable.  */
4900
5.90k
      case C_FIELD: /* Bit field.  */
4901
6.23k
      case C_ENTAG: /* Enumeration tag.  */
4902
6.52k
      case C_MOE:   /* Member of enumeration.  */
4903
6.97k
      case C_MOU:   /* Member of union.  */
4904
7.19k
      case C_UNTAG: /* Union tag.  */
4905
7.56k
      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
7.56k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
7.56k
        dst->symbol.value = (src->u.syment.n_value);
4924
7.56k
        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
102
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
744
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
990
      case C_EFCN: /* Physical end of function.  */
4977
990
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
990
        dst->symbol.value = src->u.syment.n_value;
4981
990
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
987
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
987
      dst->symbol.flags = BSF_DEBUGGING;
4986
987
    }
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
990
        break;
4997
4998
81
      case C_STATLAB: /* Static load time label.  */
4999
81
        dst->symbol.value = src->u.syment.n_value;
5000
81
        dst->symbol.flags = BSF_GLOBAL;
5001
81
        break;
5002
5003
31.3k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
31.3k
        if (src->u.syment.n_type == 0
5007
31.3k
      && src->u.syment.n_value == 0
5008
31.3k
      && src->u.syment.n_scnum == 0)
5009
8.71k
    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
22.7k
      case C_EXTDEF: /* External definition.  */
5017
22.7k
      case C_ULABEL: /* Undefined label.  */
5018
22.8k
      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
22.8k
      case C_EXTLAB: /* External load time label.  */
5031
32.7k
      default:
5032
32.7k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
32.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
32.7k
     abfd, src->u.syment.n_sclass,
5036
32.7k
     dst->symbol.section->name, dst->symbol.name);
5037
32.7k
        ret = false;
5038
        /* Fall through.  */
5039
32.8k
      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
32.8k
        dst->symbol.flags = BSF_DEBUGGING;
5043
32.8k
        dst->symbol.value = (src->u.syment.n_value);
5044
32.8k
        break;
5045
76.7k
      }
5046
5047
76.7k
    dst->native = src;
5048
76.7k
    dst->symbol.udata.i = 0;
5049
76.7k
    dst->lineno = NULL;
5050
5051
76.7k
    this_index += (src->u.syment.n_numaux) + 1;
5052
76.7k
    dst++;
5053
76.7k
    number_of_symbols++;
5054
76.7k
  }
5055
445
    }
5056
5057
445
  obj_symbols (abfd) = cached_area;
5058
445
  obj_raw_syments (abfd) = native_symbols;
5059
5060
445
  abfd->symcount = number_of_symbols;
5061
445
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
445
  {
5064
445
    asection *p;
5065
5066
445
    p = abfd->sections;
5067
2.41k
    while (p)
5068
2.29k
      {
5069
2.29k
  if (! coff_slurp_line_table (abfd, p))
5070
329
    return false;
5071
1.96k
  p = p->next;
5072
1.96k
      }
5073
445
  }
5074
5075
116
  return ret;
5076
445
}
coff-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4704
10.6k
{
4705
10.6k
  combined_entry_type *native_symbols;
4706
10.6k
  coff_symbol_type *cached_area;
4707
10.6k
  unsigned int *table_ptr;
4708
10.6k
  unsigned int number_of_symbols = 0;
4709
10.6k
  bool ret = true;
4710
10.6k
  size_t amt;
4711
4712
10.6k
  if (obj_symbols (abfd))
4713
1.13k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
9.51k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
8.53k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
976
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
976
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
976
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
976
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
976
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
976
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
976
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
976
  if (table_ptr == NULL)
4738
0
    return false;
4739
976
  else
4740
976
    {
4741
976
      coff_symbol_type *dst = cached_area;
4742
976
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
976
      unsigned int this_index = 0;
4744
4745
114k
      while (this_index < last_native_index)
4746
113k
  {
4747
113k
    combined_entry_type *src = native_symbols + this_index;
4748
113k
    table_ptr[this_index] = number_of_symbols;
4749
4750
113k
    dst->symbol.the_bfd = abfd;
4751
113k
    BFD_ASSERT (src->is_sym);
4752
113k
    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
113k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
113k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
113k
                 src->u.syment.n_scnum);
4757
113k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
113k
    dst->symbol.value = 0;
4760
113k
    dst->done_lineno = false;
4761
4762
113k
    switch (src->u.syment.n_sclass)
4763
113k
      {
4764
2.07k
      case C_EXT:
4765
2.19k
      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.19k
#ifdef C_SYSTEM
4777
2.34k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.34k
#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
2.34k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.34k
    {
4787
1.87k
    case COFF_SYMBOL_GLOBAL:
4788
1.87k
      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
1.87k
      dst->symbol.value = (src->u.syment.n_value
4795
1.87k
               - dst->symbol.section->vma);
4796
1.87k
#endif
4797
1.87k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
39
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
1.87k
      break;
4802
4803
365
    case COFF_SYMBOL_COMMON:
4804
365
      dst->symbol.section = bfd_com_section_ptr;
4805
365
      dst->symbol.value = src->u.syment.n_value;
4806
365
      break;
4807
4808
102
    case COFF_SYMBOL_UNDEFINED:
4809
102
      dst->symbol.section = bfd_und_section_ptr;
4810
102
      dst->symbol.value = 0;
4811
102
      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
2.34k
    }
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
2.34k
        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.34k
      )
4852
118
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.34k
        break;
4855
4856
2.86k
      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.25k
      case C_LABEL:  /* Label.  */
4867
3.25k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
4
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.25k
        else
4870
3.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
3.25k
        if (dst->symbol.section)
4875
3.25k
    {
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.25k
      dst->symbol.value = (src->u.syment.n_value
4882
3.25k
               - dst->symbol.section->vma);
4883
3.25k
#endif
4884
3.25k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.25k
        break;
4888
4889
472
      case C_FILE: /* File name.  */
4890
472
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
955
      case C_MOS:   /* Member of structure.  */
4893
1.17k
      case C_EOS:   /* End of structure.  */
4894
1.52k
      case C_REGPARM: /* Register parameter.  */
4895
2.06k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.38k
      case C_TPDEF: /* Type definition.  */
4898
2.91k
      case C_ARG:
4899
8.75k
      case C_AUTO: /* Automatic variable.  */
4900
9.87k
      case C_FIELD: /* Bit field.  */
4901
10.3k
      case C_ENTAG: /* Enumeration tag.  */
4902
10.7k
      case C_MOE:   /* Member of enumeration.  */
4903
11.0k
      case C_MOU:   /* Member of union.  */
4904
11.8k
      case C_UNTAG: /* Union tag.  */
4905
12.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
12.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
12.7k
        dst->symbol.value = (src->u.syment.n_value);
4924
12.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
247
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.45k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.06k
      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
2.06k
        dst->symbol.flags = BSF_LOCAL;
4993
2.06k
        dst->symbol.value = (src->u.syment.n_value
4994
2.06k
           - dst->symbol.section->vma);
4995
2.06k
#endif
4996
2.06k
        break;
4997
4998
310
      case C_STATLAB: /* Static load time label.  */
4999
310
        dst->symbol.value = src->u.syment.n_value;
5000
310
        dst->symbol.flags = BSF_GLOBAL;
5001
310
        break;
5002
5003
74.0k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
74.0k
        if (src->u.syment.n_type == 0
5007
74.0k
      && src->u.syment.n_value == 0
5008
74.0k
      && src->u.syment.n_scnum == 0)
5009
30.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
44.0k
      case C_EXTDEF: /* External definition.  */
5017
44.2k
      case C_ULABEL: /* Undefined label.  */
5018
44.5k
      case C_USTATIC: /* Undefined static.  */
5019
44.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
44.9k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
45.6k
      case C_ALIAS: /* Duplicate tag.  */
5025
45.6k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
45.6k
      case C_EXTLAB: /* External load time label.  */
5031
62.8k
      default:
5032
62.8k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
62.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
62.8k
     abfd, src->u.syment.n_sclass,
5036
62.8k
     dst->symbol.section->name, dst->symbol.name);
5037
62.8k
        ret = false;
5038
        /* Fall through.  */
5039
62.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
62.9k
        dst->symbol.flags = BSF_DEBUGGING;
5043
62.9k
        dst->symbol.value = (src->u.syment.n_value);
5044
62.9k
        break;
5045
113k
      }
5046
5047
113k
    dst->native = src;
5048
113k
    dst->symbol.udata.i = 0;
5049
113k
    dst->lineno = NULL;
5050
5051
113k
    this_index += (src->u.syment.n_numaux) + 1;
5052
113k
    dst++;
5053
113k
    number_of_symbols++;
5054
113k
  }
5055
976
    }
5056
5057
976
  obj_symbols (abfd) = cached_area;
5058
976
  obj_raw_syments (abfd) = native_symbols;
5059
5060
976
  abfd->symcount = number_of_symbols;
5061
976
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
976
  {
5064
976
    asection *p;
5065
5066
976
    p = abfd->sections;
5067
6.44k
    while (p)
5068
6.16k
      {
5069
6.16k
  if (! coff_slurp_line_table (abfd, p))
5070
695
    return false;
5071
5.46k
  p = p->next;
5072
5.46k
      }
5073
976
  }
5074
5075
281
  return ret;
5076
976
}
coff64-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4704
2.16k
{
4705
2.16k
  combined_entry_type *native_symbols;
4706
2.16k
  coff_symbol_type *cached_area;
4707
2.16k
  unsigned int *table_ptr;
4708
2.16k
  unsigned int number_of_symbols = 0;
4709
2.16k
  bool ret = true;
4710
2.16k
  size_t amt;
4711
4712
2.16k
  if (obj_symbols (abfd))
4713
69
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
2.09k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
1.34k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
751
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
751
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
751
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
751
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
751
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
751
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
751
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
751
  if (table_ptr == NULL)
4738
0
    return false;
4739
751
  else
4740
751
    {
4741
751
      coff_symbol_type *dst = cached_area;
4742
751
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
751
      unsigned int this_index = 0;
4744
4745
114k
      while (this_index < last_native_index)
4746
114k
  {
4747
114k
    combined_entry_type *src = native_symbols + this_index;
4748
114k
    table_ptr[this_index] = number_of_symbols;
4749
4750
114k
    dst->symbol.the_bfd = abfd;
4751
114k
    BFD_ASSERT (src->is_sym);
4752
114k
    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
114k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
114k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
114k
                 src->u.syment.n_scnum);
4757
114k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
114k
    dst->symbol.value = 0;
4760
114k
    dst->done_lineno = false;
4761
4762
114k
    switch (src->u.syment.n_sclass)
4763
114k
      {
4764
1.11k
      case C_EXT:
4765
1.21k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
1.21k
#ifdef RS6000COFF_C
4771
1.45k
      case C_HIDEXT:
4772
1.45k
#ifndef AIX_WEAK_SUPPORT
4773
2.33k
      case C_AIX_WEAKEXT:
4774
2.33k
#endif
4775
2.33k
#endif
4776
2.33k
#ifdef C_SYSTEM
4777
2.71k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.71k
#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
2.71k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.71k
    {
4787
2.06k
    case COFF_SYMBOL_GLOBAL:
4788
2.06k
      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.06k
      dst->symbol.value = (src->u.syment.n_value
4795
2.06k
               - dst->symbol.section->vma);
4796
2.06k
#endif
4797
2.06k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
56
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.06k
      break;
4802
4803
146
    case COFF_SYMBOL_COMMON:
4804
146
      dst->symbol.section = bfd_com_section_ptr;
4805
146
      dst->symbol.value = src->u.syment.n_value;
4806
146
      break;
4807
4808
274
    case COFF_SYMBOL_UNDEFINED:
4809
274
      dst->symbol.section = bfd_und_section_ptr;
4810
274
      dst->symbol.value = 0;
4811
274
      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
228
    case COFF_SYMBOL_LOCAL:
4819
228
      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
228
      dst->symbol.value = (src->u.syment.n_value
4826
228
               - dst->symbol.section->vma);
4827
228
#endif
4828
228
      if (ISFCN ((src->u.syment.n_type)))
4829
37
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
228
      break;
4831
2.71k
    }
4832
4833
2.71k
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
2.71k
        if (src->u.syment.n_numaux > 0)
4836
1.22k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
2.71k
#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
2.71k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
2.71k
#ifdef RS6000COFF_C
4849
2.71k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
2.71k
#endif
4851
2.71k
      )
4852
972
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.71k
        break;
4855
4856
537
      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
537
#ifdef RS6000COFF_C
4863
1.74k
      case C_DWARF:  /* A label in a dwarf section.  */
4864
3.35k
      case C_INFO:  /* A label in a comment section.  */
4865
3.35k
#endif
4866
3.91k
      case C_LABEL:  /* Label.  */
4867
3.91k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.91k
        else
4870
3.91k
    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.91k
        if (dst->symbol.section)
4875
3.91k
    {
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.91k
      dst->symbol.value = (src->u.syment.n_value
4882
3.91k
               - dst->symbol.section->vma);
4883
3.91k
#endif
4884
3.91k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.91k
        break;
4888
4889
697
      case C_FILE: /* File name.  */
4890
697
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.41k
      case C_MOS:   /* Member of structure.  */
4893
1.70k
      case C_EOS:   /* End of structure.  */
4894
2.00k
      case C_REGPARM: /* Register parameter.  */
4895
2.52k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.78k
      case C_TPDEF: /* Type definition.  */
4898
3.34k
      case C_ARG:
4899
8.89k
      case C_AUTO: /* Automatic variable.  */
4900
9.06k
      case C_FIELD: /* Bit field.  */
4901
9.21k
      case C_ENTAG: /* Enumeration tag.  */
4902
9.63k
      case C_MOE:   /* Member of enumeration.  */
4903
10.3k
      case C_MOU:   /* Member of union.  */
4904
10.5k
      case C_UNTAG: /* Union tag.  */
4905
11.3k
      case C_STRTAG: /* Structure tag.  */
4906
11.3k
#ifdef RS6000COFF_C
4907
11.4k
      case C_GSYM:
4908
11.5k
      case C_LSYM:
4909
11.6k
      case C_PSYM:
4910
11.7k
      case C_RSYM:
4911
11.7k
      case C_RPSYM:
4912
11.8k
      case C_STSYM:
4913
11.8k
      case C_TCSYM:
4914
11.8k
      case C_BCOMM:
4915
11.9k
      case C_ECOML:
4916
11.9k
      case C_ECOMM:
4917
12.0k
      case C_DECL:
4918
12.0k
      case C_ENTRY:
4919
12.0k
      case C_FUN:
4920
12.2k
      case C_ESTAT:
4921
12.2k
#endif
4922
12.2k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
12.2k
        dst->symbol.value = (src->u.syment.n_value);
4924
12.2k
        break;
4925
4926
0
#ifdef RS6000COFF_C
4927
1.26k
      case C_BINCL: /* Beginning of include file.  */
4928
1.94k
      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
1.94k
        {
4934
1.94k
    asection *sec;
4935
4936
1.94k
    dst->symbol.flags = BSF_DEBUGGING;
4937
888k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
887k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
887k
          && ((file_ptr) (sec->line_filepos
4940
763k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
763k
        > (file_ptr) src->u.syment.n_value))
4942
1.22k
        break;
4943
1.94k
    if (sec == NULL)
4944
720
      dst->symbol.value = 0;
4945
1.22k
    else
4946
1.22k
      {
4947
1.22k
        dst->symbol.section = sec;
4948
1.22k
        dst->symbol.value = ((src->u.syment.n_value
4949
1.22k
            - sec->line_filepos)
4950
1.22k
           / bfd_coff_linesz (abfd));
4951
1.22k
        src->fix_line = 1;
4952
1.22k
      }
4953
1.94k
        }
4954
1.94k
        break;
4955
4956
65
      case C_BSTAT:
4957
65
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
65
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
60
    dst->symbol.value = 0;
4961
5
        else
4962
5
    {
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
5
      src->u.syment.n_value
4967
5
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
5
      dst->symbol.value = src->u.syment.n_value;
4969
5
      src->fix_value = 1;
4970
5
    }
4971
65
        break;
4972
0
#endif
4973
4974
200
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.10k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.41k
      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
2.41k
        dst->symbol.flags = BSF_LOCAL;
4993
2.41k
        dst->symbol.value = (src->u.syment.n_value
4994
2.41k
           - dst->symbol.section->vma);
4995
2.41k
#endif
4996
2.41k
        break;
4997
4998
210
      case C_STATLAB: /* Static load time label.  */
4999
210
        dst->symbol.value = src->u.syment.n_value;
5000
210
        dst->symbol.flags = BSF_GLOBAL;
5001
210
        break;
5002
5003
75.5k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
75.5k
        if (src->u.syment.n_type == 0
5007
75.5k
      && src->u.syment.n_value == 0
5008
75.5k
      && src->u.syment.n_scnum == 0)
5009
28.1k
    break;
5010
47.3k
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
47.3k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
3
    break;
5014
47.3k
#endif
5015
        /* Fall through.  */
5016
47.3k
      case C_EXTDEF: /* External definition.  */
5017
47.5k
      case C_ULABEL: /* Undefined label.  */
5018
47.6k
      case C_USTATIC: /* Undefined static.  */
5019
47.6k
#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
48.3k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
49.6k
      case C_ALIAS: /* Duplicate tag.  */
5025
49.6k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
49.7k
      case C_EXTLAB: /* External load time label.  */
5031
62.2k
      default:
5032
62.2k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
62.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
62.2k
     abfd, src->u.syment.n_sclass,
5036
62.2k
     dst->symbol.section->name, dst->symbol.name);
5037
62.2k
        ret = false;
5038
        /* Fall through.  */
5039
62.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
62.3k
        dst->symbol.flags = BSF_DEBUGGING;
5043
62.3k
        dst->symbol.value = (src->u.syment.n_value);
5044
62.3k
        break;
5045
114k
      }
5046
5047
114k
    dst->native = src;
5048
114k
    dst->symbol.udata.i = 0;
5049
114k
    dst->lineno = NULL;
5050
5051
114k
    this_index += (src->u.syment.n_numaux) + 1;
5052
114k
    dst++;
5053
114k
    number_of_symbols++;
5054
114k
  }
5055
751
    }
5056
5057
751
  obj_symbols (abfd) = cached_area;
5058
751
  obj_raw_syments (abfd) = native_symbols;
5059
5060
751
  abfd->symcount = number_of_symbols;
5061
751
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
751
  {
5064
751
    asection *p;
5065
5066
751
    p = abfd->sections;
5067
3.31k
    while (p)
5068
3.19k
      {
5069
3.19k
  if (! coff_slurp_line_table (abfd, p))
5070
629
    return false;
5071
2.56k
  p = p->next;
5072
2.56k
      }
5073
751
  }
5074
5075
122
  return ret;
5076
751
}
pe-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
1.69k
{
4705
1.69k
  combined_entry_type *native_symbols;
4706
1.69k
  coff_symbol_type *cached_area;
4707
1.69k
  unsigned int *table_ptr;
4708
1.69k
  unsigned int number_of_symbols = 0;
4709
1.69k
  bool ret = true;
4710
1.69k
  size_t amt;
4711
4712
1.69k
  if (obj_symbols (abfd))
4713
301
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
1.39k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
749
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
644
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
644
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
644
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
644
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
644
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
644
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
644
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
644
  if (table_ptr == NULL)
4738
0
    return false;
4739
644
  else
4740
644
    {
4741
644
      coff_symbol_type *dst = cached_area;
4742
644
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
644
      unsigned int this_index = 0;
4744
4745
173k
      while (this_index < last_native_index)
4746
172k
  {
4747
172k
    combined_entry_type *src = native_symbols + this_index;
4748
172k
    table_ptr[this_index] = number_of_symbols;
4749
4750
172k
    dst->symbol.the_bfd = abfd;
4751
172k
    BFD_ASSERT (src->is_sym);
4752
172k
    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
172k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
172k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
172k
                 src->u.syment.n_scnum);
4757
172k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
172k
    dst->symbol.value = 0;
4760
172k
    dst->done_lineno = false;
4761
4762
172k
    switch (src->u.syment.n_sclass)
4763
172k
      {
4764
7.69k
      case C_EXT:
4765
7.85k
      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.85k
#ifdef C_SYSTEM
4777
8.29k
      case C_SYSTEM: /* System Wide variable.  */
4778
8.29k
#endif
4779
8.29k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
8.41k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
10.1k
      case C_NT_WEAK:
4784
10.1k
#endif
4785
10.1k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
10.1k
    {
4787
9.29k
    case COFF_SYMBOL_GLOBAL:
4788
9.29k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
9.29k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
9.29k
      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
9.29k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
292
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
9.29k
      break;
4802
4803
608
    case COFF_SYMBOL_COMMON:
4804
608
      dst->symbol.section = bfd_com_section_ptr;
4805
608
      dst->symbol.value = src->u.syment.n_value;
4806
608
      break;
4807
4808
292
    case COFF_SYMBOL_UNDEFINED:
4809
292
      dst->symbol.section = bfd_und_section_ptr;
4810
292
      dst->symbol.value = 0;
4811
292
      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.1k
    }
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.1k
#ifdef COFF_WITH_PE
4840
10.1k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.78k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
10.1k
        if (src->u.syment.n_sclass == C_SECTION
4844
10.1k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
10.1k
#endif
4847
10.1k
        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.1k
      )
4852
156
    dst->symbol.flags |= BSF_WEAK;
4853
4854
10.1k
        break;
4855
4856
2.54k
      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.84k
      case C_LABEL:  /* Label.  */
4867
2.84k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.84k
        else
4870
2.84k
    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.84k
        if (dst->symbol.section)
4875
2.84k
    {
4876
2.84k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.84k
      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.84k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.84k
        break;
4888
4889
941
      case C_FILE: /* File name.  */
4890
941
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.86k
      case C_MOS:   /* Member of structure.  */
4893
2.35k
      case C_EOS:   /* End of structure.  */
4894
2.72k
      case C_REGPARM: /* Register parameter.  */
4895
3.75k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.51k
      case C_TPDEF: /* Type definition.  */
4898
6.98k
      case C_ARG:
4899
14.1k
      case C_AUTO: /* Automatic variable.  */
4900
14.5k
      case C_FIELD: /* Bit field.  */
4901
14.8k
      case C_ENTAG: /* Enumeration tag.  */
4902
15.9k
      case C_MOE:   /* Member of enumeration.  */
4903
16.3k
      case C_MOU:   /* Member of union.  */
4904
16.9k
      case C_UNTAG: /* Union tag.  */
4905
18.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
18.3k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
18.3k
        dst->symbol.value = (src->u.syment.n_value);
4924
18.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
318
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.26k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.01k
      case C_EFCN: /* Physical end of function.  */
4977
3.01k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.01k
        dst->symbol.value = src->u.syment.n_value;
4981
3.01k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.01k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.01k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.01k
    }
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.01k
        break;
4997
4998
783
      case C_STATLAB: /* Static load time label.  */
4999
783
        dst->symbol.value = src->u.syment.n_value;
5000
783
        dst->symbol.flags = BSF_GLOBAL;
5001
783
        break;
5002
5003
110k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
110k
        if (src->u.syment.n_type == 0
5007
110k
      && src->u.syment.n_value == 0
5008
110k
      && src->u.syment.n_scnum == 0)
5009
40.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
69.5k
      case C_EXTDEF: /* External definition.  */
5017
69.7k
      case C_ULABEL: /* Undefined label.  */
5018
69.8k
      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
69.8k
      case C_EXTLAB: /* External load time label.  */
5031
96.1k
      default:
5032
96.1k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
96.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
96.1k
     abfd, src->u.syment.n_sclass,
5036
96.1k
     dst->symbol.section->name, dst->symbol.name);
5037
96.1k
        ret = false;
5038
        /* Fall through.  */
5039
96.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
96.2k
        dst->symbol.flags = BSF_DEBUGGING;
5043
96.2k
        dst->symbol.value = (src->u.syment.n_value);
5044
96.2k
        break;
5045
172k
      }
5046
5047
172k
    dst->native = src;
5048
172k
    dst->symbol.udata.i = 0;
5049
172k
    dst->lineno = NULL;
5050
5051
172k
    this_index += (src->u.syment.n_numaux) + 1;
5052
172k
    dst++;
5053
172k
    number_of_symbols++;
5054
172k
  }
5055
644
    }
5056
5057
644
  obj_symbols (abfd) = cached_area;
5058
644
  obj_raw_syments (abfd) = native_symbols;
5059
5060
644
  abfd->symcount = number_of_symbols;
5061
644
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
644
  {
5064
644
    asection *p;
5065
5066
644
    p = abfd->sections;
5067
1.75k
    while (p)
5068
1.54k
      {
5069
1.54k
  if (! coff_slurp_line_table (abfd, p))
5070
432
    return false;
5071
1.11k
  p = p->next;
5072
1.11k
      }
5073
644
  }
5074
5075
212
  return ret;
5076
644
}
pei-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
756
{
4705
756
  combined_entry_type *native_symbols;
4706
756
  coff_symbol_type *cached_area;
4707
756
  unsigned int *table_ptr;
4708
756
  unsigned int number_of_symbols = 0;
4709
756
  bool ret = true;
4710
756
  size_t amt;
4711
4712
756
  if (obj_symbols (abfd))
4713
72
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
684
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
305
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
379
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
379
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
379
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
379
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
379
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
379
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
379
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
379
  if (table_ptr == NULL)
4738
0
    return false;
4739
379
  else
4740
379
    {
4741
379
      coff_symbol_type *dst = cached_area;
4742
379
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
379
      unsigned int this_index = 0;
4744
4745
98.5k
      while (this_index < last_native_index)
4746
98.1k
  {
4747
98.1k
    combined_entry_type *src = native_symbols + this_index;
4748
98.1k
    table_ptr[this_index] = number_of_symbols;
4749
4750
98.1k
    dst->symbol.the_bfd = abfd;
4751
98.1k
    BFD_ASSERT (src->is_sym);
4752
98.1k
    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
98.1k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
98.1k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
98.1k
                 src->u.syment.n_scnum);
4757
98.1k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
98.1k
    dst->symbol.value = 0;
4760
98.1k
    dst->done_lineno = false;
4761
4762
98.1k
    switch (src->u.syment.n_sclass)
4763
98.1k
      {
4764
1.04k
      case C_EXT:
4765
1.13k
      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.13k
#ifdef C_SYSTEM
4777
1.75k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.75k
#endif
4779
1.75k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
1.79k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
3.26k
      case C_NT_WEAK:
4784
3.26k
#endif
4785
3.26k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.26k
    {
4787
2.83k
    case COFF_SYMBOL_GLOBAL:
4788
2.83k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.83k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.83k
      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.83k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
164
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.83k
      break;
4802
4803
263
    case COFF_SYMBOL_COMMON:
4804
263
      dst->symbol.section = bfd_com_section_ptr;
4805
263
      dst->symbol.value = src->u.syment.n_value;
4806
263
      break;
4807
4808
160
    case COFF_SYMBOL_UNDEFINED:
4809
160
      dst->symbol.section = bfd_und_section_ptr;
4810
160
      dst->symbol.value = 0;
4811
160
      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
3.26k
    }
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
3.26k
#ifdef COFF_WITH_PE
4840
3.26k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.46k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
3.26k
        if (src->u.syment.n_sclass == C_SECTION
4844
3.26k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
3.26k
#endif
4847
3.26k
        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.26k
      )
4852
83
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.26k
        break;
4855
4856
1.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
5.40k
      case C_LABEL:  /* Label.  */
4867
5.40k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
5.40k
        else
4870
5.40k
    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.40k
        if (dst->symbol.section)
4875
5.40k
    {
4876
5.40k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
5.40k
      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.40k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
5.40k
        break;
4888
4889
774
      case C_FILE: /* File name.  */
4890
774
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.40k
      case C_MOS:   /* Member of structure.  */
4893
1.71k
      case C_EOS:   /* End of structure.  */
4894
2.02k
      case C_REGPARM: /* Register parameter.  */
4895
2.84k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.97k
      case C_TPDEF: /* Type definition.  */
4898
3.61k
      case C_ARG:
4899
7.19k
      case C_AUTO: /* Automatic variable.  */
4900
7.65k
      case C_FIELD: /* Bit field.  */
4901
8.03k
      case C_ENTAG: /* Enumeration tag.  */
4902
8.59k
      case C_MOE:   /* Member of enumeration.  */
4903
9.88k
      case C_MOU:   /* Member of union.  */
4904
10.2k
      case C_UNTAG: /* Union tag.  */
4905
11.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
11.5k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
11.5k
        dst->symbol.value = (src->u.syment.n_value);
4924
11.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
222
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.88k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.21k
      case C_EFCN: /* Physical end of function.  */
4977
2.21k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.21k
        dst->symbol.value = src->u.syment.n_value;
4981
2.21k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.21k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.21k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.21k
    }
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
2.21k
        break;
4997
4998
880
      case C_STATLAB: /* Static load time label.  */
4999
880
        dst->symbol.value = src->u.syment.n_value;
5000
880
        dst->symbol.flags = BSF_GLOBAL;
5001
880
        break;
5002
5003
56.4k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
56.4k
        if (src->u.syment.n_type == 0
5007
56.4k
      && src->u.syment.n_value == 0
5008
56.4k
      && src->u.syment.n_scnum == 0)
5009
18.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
37.8k
      case C_EXTDEF: /* External definition.  */
5017
37.9k
      case C_ULABEL: /* Undefined label.  */
5018
38.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
38.0k
      case C_EXTLAB: /* External load time label.  */
5031
56.0k
      default:
5032
56.0k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
56.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
56.0k
     abfd, src->u.syment.n_sclass,
5036
56.0k
     dst->symbol.section->name, dst->symbol.name);
5037
56.0k
        ret = false;
5038
        /* Fall through.  */
5039
56.0k
      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
56.0k
        dst->symbol.flags = BSF_DEBUGGING;
5043
56.0k
        dst->symbol.value = (src->u.syment.n_value);
5044
56.0k
        break;
5045
98.1k
      }
5046
5047
98.1k
    dst->native = src;
5048
98.1k
    dst->symbol.udata.i = 0;
5049
98.1k
    dst->lineno = NULL;
5050
5051
98.1k
    this_index += (src->u.syment.n_numaux) + 1;
5052
98.1k
    dst++;
5053
98.1k
    number_of_symbols++;
5054
98.1k
  }
5055
379
    }
5056
5057
379
  obj_symbols (abfd) = cached_area;
5058
379
  obj_raw_syments (abfd) = native_symbols;
5059
5060
379
  abfd->symcount = number_of_symbols;
5061
379
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
379
  {
5064
379
    asection *p;
5065
5066
379
    p = abfd->sections;
5067
880
    while (p)
5068
816
      {
5069
816
  if (! coff_slurp_line_table (abfd, p))
5070
315
    return false;
5071
501
  p = p->next;
5072
501
      }
5073
379
  }
5074
5075
64
  return ret;
5076
379
}
pei-ia64.c:coff_slurp_symbol_table
Line
Count
Source
4704
804
{
4705
804
  combined_entry_type *native_symbols;
4706
804
  coff_symbol_type *cached_area;
4707
804
  unsigned int *table_ptr;
4708
804
  unsigned int number_of_symbols = 0;
4709
804
  bool ret = true;
4710
804
  size_t amt;
4711
4712
804
  if (obj_symbols (abfd))
4713
19
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
785
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
338
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
447
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
447
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
447
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
447
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
447
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
447
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
447
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
447
  if (table_ptr == NULL)
4738
0
    return false;
4739
447
  else
4740
447
    {
4741
447
      coff_symbol_type *dst = cached_area;
4742
447
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
447
      unsigned int this_index = 0;
4744
4745
195k
      while (this_index < last_native_index)
4746
195k
  {
4747
195k
    combined_entry_type *src = native_symbols + this_index;
4748
195k
    table_ptr[this_index] = number_of_symbols;
4749
4750
195k
    dst->symbol.the_bfd = abfd;
4751
195k
    BFD_ASSERT (src->is_sym);
4752
195k
    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
195k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
195k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
195k
                 src->u.syment.n_scnum);
4757
195k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
195k
    dst->symbol.value = 0;
4760
195k
    dst->done_lineno = false;
4761
4762
195k
    switch (src->u.syment.n_sclass)
4763
195k
      {
4764
4.87k
      case C_EXT:
4765
5.00k
      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.00k
#ifdef C_SYSTEM
4777
5.45k
      case C_SYSTEM: /* System Wide variable.  */
4778
5.45k
#endif
4779
5.45k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
5.66k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
7.85k
      case C_NT_WEAK:
4784
7.85k
#endif
4785
7.85k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
7.85k
    {
4787
7.05k
    case COFF_SYMBOL_GLOBAL:
4788
7.05k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
7.05k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
7.05k
      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.05k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
564
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
7.05k
      break;
4802
4803
375
    case COFF_SYMBOL_COMMON:
4804
375
      dst->symbol.section = bfd_com_section_ptr;
4805
375
      dst->symbol.value = src->u.syment.n_value;
4806
375
      break;
4807
4808
422
    case COFF_SYMBOL_UNDEFINED:
4809
422
      dst->symbol.section = bfd_und_section_ptr;
4810
422
      dst->symbol.value = 0;
4811
422
      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.85k
    }
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.85k
#ifdef COFF_WITH_PE
4840
7.85k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
2.18k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
7.85k
        if (src->u.syment.n_sclass == C_SECTION
4844
7.85k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
7.85k
#endif
4847
7.85k
        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.85k
      )
4852
131
    dst->symbol.flags |= BSF_WEAK;
4853
4854
7.85k
        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
2.86k
      case C_LABEL:  /* Label.  */
4867
2.86k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.85k
        else
4870
2.85k
    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.86k
        if (dst->symbol.section)
4875
2.86k
    {
4876
2.86k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.86k
      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.86k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.86k
        break;
4888
4889
906
      case C_FILE: /* File name.  */
4890
906
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.70k
      case C_MOS:   /* Member of structure.  */
4893
2.20k
      case C_EOS:   /* End of structure.  */
4894
2.56k
      case C_REGPARM: /* Register parameter.  */
4895
3.86k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.31k
      case C_TPDEF: /* Type definition.  */
4898
5.35k
      case C_ARG:
4899
11.4k
      case C_AUTO: /* Automatic variable.  */
4900
12.0k
      case C_FIELD: /* Bit field.  */
4901
12.7k
      case C_ENTAG: /* Enumeration tag.  */
4902
13.6k
      case C_MOE:   /* Member of enumeration.  */
4903
14.5k
      case C_MOU:   /* Member of union.  */
4904
15.0k
      case C_UNTAG: /* Union tag.  */
4905
15.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
15.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
15.7k
        dst->symbol.value = (src->u.syment.n_value);
4924
15.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
258
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.36k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.64k
      case C_EFCN: /* Physical end of function.  */
4977
3.64k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.64k
        dst->symbol.value = src->u.syment.n_value;
4981
3.64k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.64k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.64k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.64k
    }
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.64k
        break;
4997
4998
192
      case C_STATLAB: /* Static load time label.  */
4999
192
        dst->symbol.value = src->u.syment.n_value;
5000
192
        dst->symbol.flags = BSF_GLOBAL;
5001
192
        break;
5002
5003
131k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
131k
        if (src->u.syment.n_type == 0
5007
131k
      && src->u.syment.n_value == 0
5008
131k
      && src->u.syment.n_scnum == 0)
5009
49.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
83.5k
      case C_EXTDEF: /* External definition.  */
5017
83.7k
      case C_ULABEL: /* Undefined label.  */
5018
83.8k
      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
83.9k
      case C_EXTLAB: /* External load time label.  */
5031
115k
      default:
5032
115k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
115k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
115k
     abfd, src->u.syment.n_sclass,
5036
115k
     dst->symbol.section->name, dst->symbol.name);
5037
115k
        ret = false;
5038
        /* Fall through.  */
5039
115k
      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
115k
        dst->symbol.flags = BSF_DEBUGGING;
5043
115k
        dst->symbol.value = (src->u.syment.n_value);
5044
115k
        break;
5045
195k
      }
5046
5047
195k
    dst->native = src;
5048
195k
    dst->symbol.udata.i = 0;
5049
195k
    dst->lineno = NULL;
5050
5051
195k
    this_index += (src->u.syment.n_numaux) + 1;
5052
195k
    dst++;
5053
195k
    number_of_symbols++;
5054
195k
  }
5055
447
    }
5056
5057
447
  obj_symbols (abfd) = cached_area;
5058
447
  obj_raw_syments (abfd) = native_symbols;
5059
5060
447
  abfd->symcount = number_of_symbols;
5061
447
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
447
  {
5064
447
    asection *p;
5065
5066
447
    p = abfd->sections;
5067
1.25k
    while (p)
5068
1.14k
      {
5069
1.14k
  if (! coff_slurp_line_table (abfd, p))
5070
336
    return false;
5071
810
  p = p->next;
5072
810
      }
5073
447
  }
5074
5075
111
  return ret;
5076
447
}
pei-loongarch64.c:coff_slurp_symbol_table
Line
Count
Source
4704
768
{
4705
768
  combined_entry_type *native_symbols;
4706
768
  coff_symbol_type *cached_area;
4707
768
  unsigned int *table_ptr;
4708
768
  unsigned int number_of_symbols = 0;
4709
768
  bool ret = true;
4710
768
  size_t amt;
4711
4712
768
  if (obj_symbols (abfd))
4713
100
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
668
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
306
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
362
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
362
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
362
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
362
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
362
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
362
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
362
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
362
  if (table_ptr == NULL)
4738
0
    return false;
4739
362
  else
4740
362
    {
4741
362
      coff_symbol_type *dst = cached_area;
4742
362
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
362
      unsigned int this_index = 0;
4744
4745
130k
      while (this_index < last_native_index)
4746
130k
  {
4747
130k
    combined_entry_type *src = native_symbols + this_index;
4748
130k
    table_ptr[this_index] = number_of_symbols;
4749
4750
130k
    dst->symbol.the_bfd = abfd;
4751
130k
    BFD_ASSERT (src->is_sym);
4752
130k
    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
130k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
130k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
130k
                 src->u.syment.n_scnum);
4757
130k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
130k
    dst->symbol.value = 0;
4760
130k
    dst->done_lineno = false;
4761
4762
130k
    switch (src->u.syment.n_sclass)
4763
130k
      {
4764
1.13k
      case C_EXT:
4765
1.28k
      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.28k
#ifdef C_SYSTEM
4777
1.53k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.53k
#endif
4779
1.53k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
1.65k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
3.86k
      case C_NT_WEAK:
4784
3.86k
#endif
4785
3.86k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.86k
    {
4787
3.41k
    case COFF_SYMBOL_GLOBAL:
4788
3.41k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
3.41k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
3.41k
      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
3.41k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
143
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
3.41k
      break;
4802
4803
218
    case COFF_SYMBOL_COMMON:
4804
218
      dst->symbol.section = bfd_com_section_ptr;
4805
218
      dst->symbol.value = src->u.syment.n_value;
4806
218
      break;
4807
4808
231
    case COFF_SYMBOL_UNDEFINED:
4809
231
      dst->symbol.section = bfd_und_section_ptr;
4810
231
      dst->symbol.value = 0;
4811
231
      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
3.86k
    }
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
3.86k
#ifdef COFF_WITH_PE
4840
3.86k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
2.20k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
3.86k
        if (src->u.syment.n_sclass == C_SECTION
4844
3.86k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
3.86k
#endif
4847
3.86k
        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.86k
      )
4852
151
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.86k
        break;
4855
4856
2.06k
      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.31k
      case C_LABEL:  /* Label.  */
4867
2.31k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.31k
        else
4870
2.31k
    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.31k
        if (dst->symbol.section)
4875
2.31k
    {
4876
2.31k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.31k
      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.31k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.31k
        break;
4888
4889
1.23k
      case C_FILE: /* File name.  */
4890
1.23k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.80k
      case C_MOS:   /* Member of structure.  */
4893
2.23k
      case C_EOS:   /* End of structure.  */
4894
2.51k
      case C_REGPARM: /* Register parameter.  */
4895
4.39k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.89k
      case C_TPDEF: /* Type definition.  */
4898
5.75k
      case C_ARG:
4899
8.08k
      case C_AUTO: /* Automatic variable.  */
4900
8.49k
      case C_FIELD: /* Bit field.  */
4901
8.80k
      case C_ENTAG: /* Enumeration tag.  */
4902
9.43k
      case C_MOE:   /* Member of enumeration.  */
4903
9.86k
      case C_MOU:   /* Member of union.  */
4904
10.2k
      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
174
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.78k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.28k
      case C_EFCN: /* Physical end of function.  */
4977
3.28k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.28k
        dst->symbol.value = src->u.syment.n_value;
4981
3.28k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.28k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.28k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.28k
    }
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.28k
        break;
4997
4998
214
      case C_STATLAB: /* Static load time label.  */
4999
214
        dst->symbol.value = src->u.syment.n_value;
5000
214
        dst->symbol.flags = BSF_GLOBAL;
5001
214
        break;
5002
5003
81.5k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
81.5k
        if (src->u.syment.n_type == 0
5007
81.5k
      && src->u.syment.n_value == 0
5008
81.5k
      && src->u.syment.n_scnum == 0)
5009
22.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
59.6k
      case C_EXTDEF: /* External definition.  */
5017
59.7k
      case C_ULABEL: /* Undefined label.  */
5018
59.8k
      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
59.9k
      case C_EXTLAB: /* External load time label.  */
5031
87.0k
      default:
5032
87.0k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
87.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
87.0k
     abfd, src->u.syment.n_sclass,
5036
87.0k
     dst->symbol.section->name, dst->symbol.name);
5037
87.0k
        ret = false;
5038
        /* Fall through.  */
5039
87.1k
      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
87.1k
        dst->symbol.flags = BSF_DEBUGGING;
5043
87.1k
        dst->symbol.value = (src->u.syment.n_value);
5044
87.1k
        break;
5045
130k
      }
5046
5047
130k
    dst->native = src;
5048
130k
    dst->symbol.udata.i = 0;
5049
130k
    dst->lineno = NULL;
5050
5051
130k
    this_index += (src->u.syment.n_numaux) + 1;
5052
130k
    dst++;
5053
130k
    number_of_symbols++;
5054
130k
  }
5055
362
    }
5056
5057
362
  obj_symbols (abfd) = cached_area;
5058
362
  obj_raw_syments (abfd) = native_symbols;
5059
5060
362
  abfd->symcount = number_of_symbols;
5061
362
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
362
  {
5064
362
    asection *p;
5065
5066
362
    p = abfd->sections;
5067
795
    while (p)
5068
711
      {
5069
711
  if (! coff_slurp_line_table (abfd, p))
5070
278
    return false;
5071
433
  p = p->next;
5072
433
      }
5073
362
  }
5074
5075
84
  return ret;
5076
362
}
pei-riscv64.c:coff_slurp_symbol_table
Line
Count
Source
4704
752
{
4705
752
  combined_entry_type *native_symbols;
4706
752
  coff_symbol_type *cached_area;
4707
752
  unsigned int *table_ptr;
4708
752
  unsigned int number_of_symbols = 0;
4709
752
  bool ret = true;
4710
752
  size_t amt;
4711
4712
752
  if (obj_symbols (abfd))
4713
89
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
663
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
281
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
382
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
382
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
382
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
382
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
382
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
382
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
382
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
382
  if (table_ptr == NULL)
4738
0
    return false;
4739
382
  else
4740
382
    {
4741
382
      coff_symbol_type *dst = cached_area;
4742
382
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
382
      unsigned int this_index = 0;
4744
4745
173k
      while (this_index < last_native_index)
4746
173k
  {
4747
173k
    combined_entry_type *src = native_symbols + this_index;
4748
173k
    table_ptr[this_index] = number_of_symbols;
4749
4750
173k
    dst->symbol.the_bfd = abfd;
4751
173k
    BFD_ASSERT (src->is_sym);
4752
173k
    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
173k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
173k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
173k
                 src->u.syment.n_scnum);
4757
173k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
173k
    dst->symbol.value = 0;
4760
173k
    dst->done_lineno = false;
4761
4762
173k
    switch (src->u.syment.n_sclass)
4763
173k
      {
4764
1.63k
      case C_EXT:
4765
1.80k
      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.80k
#ifdef C_SYSTEM
4777
2.11k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.11k
#endif
4779
2.11k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
2.16k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
3.90k
      case C_NT_WEAK:
4784
3.90k
#endif
4785
3.90k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.90k
    {
4787
3.32k
    case COFF_SYMBOL_GLOBAL:
4788
3.32k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
3.32k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
3.32k
      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
3.32k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
138
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
3.32k
      break;
4802
4803
459
    case COFF_SYMBOL_COMMON:
4804
459
      dst->symbol.section = bfd_com_section_ptr;
4805
459
      dst->symbol.value = src->u.syment.n_value;
4806
459
      break;
4807
4808
123
    case COFF_SYMBOL_UNDEFINED:
4809
123
      dst->symbol.section = bfd_und_section_ptr;
4810
123
      dst->symbol.value = 0;
4811
123
      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
3.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
3.90k
#ifdef COFF_WITH_PE
4840
3.90k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.73k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
3.90k
        if (src->u.syment.n_sclass == C_SECTION
4844
3.90k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
3.90k
#endif
4847
3.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
3.90k
      )
4852
169
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.90k
        break;
4855
4856
3.02k
      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.61k
      case C_LABEL:  /* Label.  */
4867
4.61k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
4.61k
        else
4870
4.61k
    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.61k
        if (dst->symbol.section)
4875
4.61k
    {
4876
4.61k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
4.61k
      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.61k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
4.61k
        break;
4888
4889
1.00k
      case C_FILE: /* File name.  */
4890
1.00k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.29k
      case C_MOS:   /* Member of structure.  */
4893
2.02k
      case C_EOS:   /* End of structure.  */
4894
2.25k
      case C_REGPARM: /* Register parameter.  */
4895
3.95k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
4.24k
      case C_TPDEF: /* Type definition.  */
4898
4.81k
      case C_ARG:
4899
10.8k
      case C_AUTO: /* Automatic variable.  */
4900
11.7k
      case C_FIELD: /* Bit field.  */
4901
12.3k
      case C_ENTAG: /* Enumeration tag.  */
4902
12.8k
      case C_MOE:   /* Member of enumeration.  */
4903
13.5k
      case C_MOU:   /* Member of union.  */
4904
14.0k
      case C_UNTAG: /* Union tag.  */
4905
15.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
15.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
15.7k
        dst->symbol.value = (src->u.syment.n_value);
4924
15.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
380
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.66k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.32k
      case C_EFCN: /* Physical end of function.  */
4977
3.32k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.32k
        dst->symbol.value = src->u.syment.n_value;
4981
3.32k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.32k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.32k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.32k
    }
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.32k
        break;
4997
4998
142
      case C_STATLAB: /* Static load time label.  */
4999
142
        dst->symbol.value = src->u.syment.n_value;
5000
142
        dst->symbol.flags = BSF_GLOBAL;
5001
142
        break;
5002
5003
116k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
116k
        if (src->u.syment.n_type == 0
5007
116k
      && src->u.syment.n_value == 0
5008
116k
      && src->u.syment.n_scnum == 0)
5009
48.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
67.9k
      case C_EXTDEF: /* External definition.  */
5017
68.1k
      case C_ULABEL: /* Undefined label.  */
5018
68.2k
      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
68.2k
      case C_EXTLAB: /* External load time label.  */
5031
96.7k
      default:
5032
96.7k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
96.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
96.7k
     abfd, src->u.syment.n_sclass,
5036
96.7k
     dst->symbol.section->name, dst->symbol.name);
5037
96.7k
        ret = false;
5038
        /* Fall through.  */
5039
96.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
96.9k
        dst->symbol.flags = BSF_DEBUGGING;
5043
96.9k
        dst->symbol.value = (src->u.syment.n_value);
5044
96.9k
        break;
5045
173k
      }
5046
5047
173k
    dst->native = src;
5048
173k
    dst->symbol.udata.i = 0;
5049
173k
    dst->lineno = NULL;
5050
5051
173k
    this_index += (src->u.syment.n_numaux) + 1;
5052
173k
    dst++;
5053
173k
    number_of_symbols++;
5054
173k
  }
5055
382
    }
5056
5057
382
  obj_symbols (abfd) = cached_area;
5058
382
  obj_raw_syments (abfd) = native_symbols;
5059
5060
382
  abfd->symcount = number_of_symbols;
5061
382
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
382
  {
5064
382
    asection *p;
5065
5066
382
    p = abfd->sections;
5067
726
    while (p)
5068
647
      {
5069
647
  if (! coff_slurp_line_table (abfd, p))
5070
303
    return false;
5071
344
  p = p->next;
5072
344
      }
5073
382
  }
5074
5075
79
  return ret;
5076
382
}
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
2.62k
{
4705
2.62k
  combined_entry_type *native_symbols;
4706
2.62k
  coff_symbol_type *cached_area;
4707
2.62k
  unsigned int *table_ptr;
4708
2.62k
  unsigned int number_of_symbols = 0;
4709
2.62k
  bool ret = true;
4710
2.62k
  size_t amt;
4711
4712
2.62k
  if (obj_symbols (abfd))
4713
180
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
2.44k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
1.62k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
826
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
826
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
826
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
826
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
826
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
826
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
826
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
826
  if (table_ptr == NULL)
4738
0
    return false;
4739
826
  else
4740
826
    {
4741
826
      coff_symbol_type *dst = cached_area;
4742
826
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
826
      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
16.4k
      case C_EXT:
4765
16.8k
      case C_WEAKEXT:
4766
#if defined ARM
4767
      case C_THUMBEXT:
4768
      case C_THUMBEXTFUNC:
4769
#endif
4770
16.8k
#ifdef RS6000COFF_C
4771
17.3k
      case C_HIDEXT:
4772
17.3k
#ifndef AIX_WEAK_SUPPORT
4773
18.2k
      case C_AIX_WEAKEXT:
4774
18.2k
#endif
4775
18.2k
#endif
4776
18.2k
#ifdef C_SYSTEM
4777
19.4k
      case C_SYSTEM: /* System Wide variable.  */
4778
19.4k
#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
19.4k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
19.4k
    {
4787
18.7k
    case COFF_SYMBOL_GLOBAL:
4788
18.7k
      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
18.7k
      dst->symbol.value = (src->u.syment.n_value
4795
18.7k
               - dst->symbol.section->vma);
4796
18.7k
#endif
4797
18.7k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
633
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
18.7k
      break;
4802
4803
86
    case COFF_SYMBOL_COMMON:
4804
86
      dst->symbol.section = bfd_com_section_ptr;
4805
86
      dst->symbol.value = src->u.syment.n_value;
4806
86
      break;
4807
4808
39
    case COFF_SYMBOL_UNDEFINED:
4809
39
      dst->symbol.section = bfd_und_section_ptr;
4810
39
      dst->symbol.value = 0;
4811
39
      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
548
    case COFF_SYMBOL_LOCAL:
4819
548
      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
548
      dst->symbol.value = (src->u.syment.n_value
4826
548
               - dst->symbol.section->vma);
4827
548
#endif
4828
548
      if (ISFCN ((src->u.syment.n_type)))
4829
421
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4830
548
      break;
4831
19.4k
    }
4832
4833
19.4k
#ifdef RS6000COFF_C
4834
        /* A symbol with a csect entry should not go at the end.  */
4835
19.4k
        if (src->u.syment.n_numaux > 0)
4836
18.9k
    dst->symbol.flags |= BSF_NOT_AT_END;
4837
19.4k
#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
19.4k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
19.4k
#ifdef RS6000COFF_C
4849
19.4k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
19.4k
#endif
4851
19.4k
      )
4852
1.25k
    dst->symbol.flags |= BSF_WEAK;
4853
4854
19.4k
        break;
4855
4856
296
      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
296
#ifdef RS6000COFF_C
4863
891
      case C_DWARF:  /* A label in a dwarf section.  */
4864
1.60k
      case C_INFO:  /* A label in a comment section.  */
4865
1.60k
#endif
4866
1.86k
      case C_LABEL:  /* Label.  */
4867
1.86k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
6
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.85k
        else
4870
1.85k
    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
1.86k
        if (dst->symbol.section)
4875
1.86k
    {
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
1.86k
      dst->symbol.value = (src->u.syment.n_value
4882
1.86k
               - dst->symbol.section->vma);
4883
1.86k
#endif
4884
1.86k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.86k
        break;
4888
4889
328
      case C_FILE: /* File name.  */
4890
328
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.77k
      case C_MOS:   /* Member of structure.  */
4893
2.64k
      case C_EOS:   /* End of structure.  */
4894
3.09k
      case C_REGPARM: /* Register parameter.  */
4895
9.03k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
13.7k
      case C_TPDEF: /* Type definition.  */
4898
15.3k
      case C_ARG:
4899
18.8k
      case C_AUTO: /* Automatic variable.  */
4900
19.6k
      case C_FIELD: /* Bit field.  */
4901
19.7k
      case C_ENTAG: /* Enumeration tag.  */
4902
20.0k
      case C_MOE:   /* Member of enumeration.  */
4903
20.6k
      case C_MOU:   /* Member of union.  */
4904
22.5k
      case C_UNTAG: /* Union tag.  */
4905
22.9k
      case C_STRTAG: /* Structure tag.  */
4906
22.9k
#ifdef RS6000COFF_C
4907
23.1k
      case C_GSYM:
4908
25.0k
      case C_LSYM:
4909
25.1k
      case C_PSYM:
4910
26.3k
      case C_RSYM:
4911
26.8k
      case C_RPSYM:
4912
27.0k
      case C_STSYM:
4913
27.4k
      case C_TCSYM:
4914
27.7k
      case C_BCOMM:
4915
28.0k
      case C_ECOML:
4916
28.4k
      case C_ECOMM:
4917
28.8k
      case C_DECL:
4918
28.9k
      case C_ENTRY:
4919
29.0k
      case C_FUN:
4920
29.3k
      case C_ESTAT:
4921
29.3k
#endif
4922
29.3k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
29.3k
        dst->symbol.value = (src->u.syment.n_value);
4924
29.3k
        break;
4925
4926
0
#ifdef RS6000COFF_C
4927
2.28k
      case C_BINCL: /* Beginning of include file.  */
4928
2.71k
      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
2.71k
        {
4934
2.71k
    asection *sec;
4935
4936
2.71k
    dst->symbol.flags = BSF_DEBUGGING;
4937
223k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4938
221k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4939
221k
          && ((file_ptr) (sec->line_filepos
4940
183k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4941
183k
        > (file_ptr) src->u.syment.n_value))
4942
574
        break;
4943
2.71k
    if (sec == NULL)
4944
2.14k
      dst->symbol.value = 0;
4945
574
    else
4946
574
      {
4947
574
        dst->symbol.section = sec;
4948
574
        dst->symbol.value = ((src->u.syment.n_value
4949
574
            - sec->line_filepos)
4950
574
           / bfd_coff_linesz (abfd));
4951
574
        src->fix_line = 1;
4952
574
      }
4953
2.71k
        }
4954
2.71k
        break;
4955
4956
572
      case C_BSTAT:
4957
572
        dst->symbol.flags = BSF_DEBUGGING;
4958
4959
572
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4960
567
    dst->symbol.value = 0;
4961
5
        else
4962
5
    {
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
5
      src->u.syment.n_value
4967
5
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4968
5
      dst->symbol.value = src->u.syment.n_value;
4969
5
      src->fix_value = 1;
4970
5
    }
4971
572
        break;
4972
0
#endif
4973
4974
413
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.27k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.50k
      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
1.50k
        dst->symbol.flags = BSF_LOCAL;
4993
1.50k
        dst->symbol.value = (src->u.syment.n_value
4994
1.50k
           - dst->symbol.section->vma);
4995
1.50k
#endif
4996
1.50k
        break;
4997
4998
3.02k
      case C_STATLAB: /* Static load time label.  */
4999
3.02k
        dst->symbol.value = src->u.syment.n_value;
5000
3.02k
        dst->symbol.flags = BSF_GLOBAL;
5001
3.02k
        break;
5002
5003
84.7k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
84.7k
        if (src->u.syment.n_type == 0
5007
84.7k
      && src->u.syment.n_value == 0
5008
84.7k
      && src->u.syment.n_scnum == 0)
5009
65.2k
    break;
5010
19.5k
#ifdef RS6000COFF_C
5011
        /* XCOFF specific: deleted entry.  */
5012
19.5k
        if (src->u.syment.n_value == C_NULL_VALUE)
5013
0
    break;
5014
19.5k
#endif
5015
        /* Fall through.  */
5016
19.6k
      case C_EXTDEF: /* External definition.  */
5017
19.7k
      case C_ULABEL: /* Undefined label.  */
5018
19.8k
      case C_USTATIC: /* Undefined static.  */
5019
19.8k
#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
20.3k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
20.8k
      case C_ALIAS: /* Duplicate tag.  */
5025
20.8k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
20.9k
      case C_EXTLAB: /* External load time label.  */
5031
42.0k
      default:
5032
42.0k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
42.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
42.0k
     abfd, src->u.syment.n_sclass,
5036
42.0k
     dst->symbol.section->name, dst->symbol.name);
5037
42.0k
        ret = false;
5038
        /* Fall through.  */
5039
42.1k
      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
42.1k
        dst->symbol.flags = BSF_DEBUGGING;
5043
42.1k
        dst->symbol.value = (src->u.syment.n_value);
5044
42.1k
        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
826
    }
5056
5057
826
  obj_symbols (abfd) = cached_area;
5058
826
  obj_raw_syments (abfd) = native_symbols;
5059
5060
826
  abfd->symcount = number_of_symbols;
5061
826
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
826
  {
5064
826
    asection *p;
5065
5066
826
    p = abfd->sections;
5067
3.60k
    while (p)
5068
3.29k
      {
5069
3.29k
  if (! coff_slurp_line_table (abfd, p))
5070
510
    return false;
5071
2.78k
  p = p->next;
5072
2.78k
      }
5073
826
  }
5074
5075
316
  return ret;
5076
826
}
coff-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
3.80k
{
4705
3.80k
  combined_entry_type *native_symbols;
4706
3.80k
  coff_symbol_type *cached_area;
4707
3.80k
  unsigned int *table_ptr;
4708
3.80k
  unsigned int number_of_symbols = 0;
4709
3.80k
  bool ret = true;
4710
3.80k
  size_t amt;
4711
4712
3.80k
  if (obj_symbols (abfd))
4713
1.08k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
2.72k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
2.13k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
587
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
587
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
587
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
587
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
587
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
587
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
587
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
587
  if (table_ptr == NULL)
4738
0
    return false;
4739
587
  else
4740
587
    {
4741
587
      coff_symbol_type *dst = cached_area;
4742
587
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
587
      unsigned int this_index = 0;
4744
4745
138k
      while (this_index < last_native_index)
4746
138k
  {
4747
138k
    combined_entry_type *src = native_symbols + this_index;
4748
138k
    table_ptr[this_index] = number_of_symbols;
4749
4750
138k
    dst->symbol.the_bfd = abfd;
4751
138k
    BFD_ASSERT (src->is_sym);
4752
138k
    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
138k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
138k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
138k
                 src->u.syment.n_scnum);
4757
138k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
138k
    dst->symbol.value = 0;
4760
138k
    dst->done_lineno = false;
4761
4762
138k
    switch (src->u.syment.n_sclass)
4763
138k
      {
4764
2.89k
      case C_EXT:
4765
3.07k
      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.07k
#ifdef C_SYSTEM
4777
3.29k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.29k
#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.29k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.29k
    {
4787
2.52k
    case COFF_SYMBOL_GLOBAL:
4788
2.52k
      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.52k
      dst->symbol.value = (src->u.syment.n_value
4795
2.52k
               - dst->symbol.section->vma);
4796
2.52k
#endif
4797
2.52k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
32
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.52k
      break;
4802
4803
727
    case COFF_SYMBOL_COMMON:
4804
727
      dst->symbol.section = bfd_com_section_ptr;
4805
727
      dst->symbol.value = src->u.syment.n_value;
4806
727
      break;
4807
4808
43
    case COFF_SYMBOL_UNDEFINED:
4809
43
      dst->symbol.section = bfd_und_section_ptr;
4810
43
      dst->symbol.value = 0;
4811
43
      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.29k
    }
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.29k
        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.29k
      )
4852
173
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.29k
        break;
4855
4856
384
      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
866
      case C_LABEL:  /* Label.  */
4867
866
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
863
        else
4870
863
    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
866
        if (dst->symbol.section)
4875
866
    {
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
866
      dst->symbol.value = (src->u.syment.n_value
4882
866
               - dst->symbol.section->vma);
4883
866
#endif
4884
866
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
866
        break;
4888
4889
327
      case C_FILE: /* File name.  */
4890
327
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
744
      case C_MOS:   /* Member of structure.  */
4893
841
      case C_EOS:   /* End of structure.  */
4894
956
      case C_REGPARM: /* Register parameter.  */
4895
1.80k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.17k
      case C_TPDEF: /* Type definition.  */
4898
3.09k
      case C_ARG:
4899
11.2k
      case C_AUTO: /* Automatic variable.  */
4900
11.4k
      case C_FIELD: /* Bit field.  */
4901
11.6k
      case C_ENTAG: /* Enumeration tag.  */
4902
12.2k
      case C_MOE:   /* Member of enumeration.  */
4903
12.8k
      case C_MOU:   /* Member of union.  */
4904
13.0k
      case C_UNTAG: /* Union tag.  */
4905
14.1k
      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.1k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
14.1k
        dst->symbol.value = (src->u.syment.n_value);
4924
14.1k
        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
179
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
903
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.42k
      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
1.42k
        dst->symbol.flags = BSF_LOCAL;
4993
1.42k
        dst->symbol.value = (src->u.syment.n_value
4994
1.42k
           - dst->symbol.section->vma);
4995
1.42k
#endif
4996
1.42k
        break;
4997
4998
82
      case C_STATLAB: /* Static load time label.  */
4999
82
        dst->symbol.value = src->u.syment.n_value;
5000
82
        dst->symbol.flags = BSF_GLOBAL;
5001
82
        break;
5002
5003
97.5k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
97.5k
        if (src->u.syment.n_type == 0
5007
97.5k
      && src->u.syment.n_value == 0
5008
97.5k
      && src->u.syment.n_scnum == 0)
5009
35.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
62.0k
      case C_EXTDEF: /* External definition.  */
5017
62.1k
      case C_ULABEL: /* Undefined label.  */
5018
62.2k
      case C_USTATIC: /* Undefined static.  */
5019
62.2k
#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
62.5k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
63.0k
      case C_ALIAS: /* Duplicate tag.  */
5025
63.0k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
63.1k
      case C_EXTLAB: /* External load time label.  */
5031
82.6k
      default:
5032
82.6k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
82.6k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
82.6k
     abfd, src->u.syment.n_sclass,
5036
82.6k
     dst->symbol.section->name, dst->symbol.name);
5037
82.6k
        ret = false;
5038
        /* Fall through.  */
5039
82.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
82.7k
        dst->symbol.flags = BSF_DEBUGGING;
5043
82.7k
        dst->symbol.value = (src->u.syment.n_value);
5044
82.7k
        break;
5045
138k
      }
5046
5047
138k
    dst->native = src;
5048
138k
    dst->symbol.udata.i = 0;
5049
138k
    dst->lineno = NULL;
5050
5051
138k
    this_index += (src->u.syment.n_numaux) + 1;
5052
138k
    dst++;
5053
138k
    number_of_symbols++;
5054
138k
  }
5055
587
    }
5056
5057
587
  obj_symbols (abfd) = cached_area;
5058
587
  obj_raw_syments (abfd) = native_symbols;
5059
5060
587
  abfd->symcount = number_of_symbols;
5061
587
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
587
  {
5064
587
    asection *p;
5065
5066
587
    p = abfd->sections;
5067
2.68k
    while (p)
5068
2.57k
      {
5069
2.57k
  if (! coff_slurp_line_table (abfd, p))
5070
475
    return false;
5071
2.09k
  p = p->next;
5072
2.09k
      }
5073
587
  }
5074
5075
112
  return ret;
5076
587
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_symbol_table
coff-tic30.c:coff_slurp_symbol_table
Line
Count
Source
4704
7.60k
{
4705
7.60k
  combined_entry_type *native_symbols;
4706
7.60k
  coff_symbol_type *cached_area;
4707
7.60k
  unsigned int *table_ptr;
4708
7.60k
  unsigned int number_of_symbols = 0;
4709
7.60k
  bool ret = true;
4710
7.60k
  size_t amt;
4711
4712
7.60k
  if (obj_symbols (abfd))
4713
4.44k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
3.16k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
2.41k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
753
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
753
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
753
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
753
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
753
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
753
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
753
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
753
  if (table_ptr == NULL)
4738
0
    return false;
4739
753
  else
4740
753
    {
4741
753
      coff_symbol_type *dst = cached_area;
4742
753
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
753
      unsigned int this_index = 0;
4744
4745
71.8k
      while (this_index < last_native_index)
4746
71.0k
  {
4747
71.0k
    combined_entry_type *src = native_symbols + this_index;
4748
71.0k
    table_ptr[this_index] = number_of_symbols;
4749
4750
71.0k
    dst->symbol.the_bfd = abfd;
4751
71.0k
    BFD_ASSERT (src->is_sym);
4752
71.0k
    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
71.0k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
71.0k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
71.0k
                 src->u.syment.n_scnum);
4757
71.0k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
71.0k
    dst->symbol.value = 0;
4760
71.0k
    dst->done_lineno = false;
4761
4762
71.0k
    switch (src->u.syment.n_sclass)
4763
71.0k
      {
4764
1.60k
      case C_EXT:
4765
1.76k
      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.76k
#ifdef C_SYSTEM
4777
1.90k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.90k
#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
1.90k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
1.90k
    {
4787
1.63k
    case COFF_SYMBOL_GLOBAL:
4788
1.63k
      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
1.63k
      dst->symbol.value = (src->u.syment.n_value
4795
1.63k
               - dst->symbol.section->vma);
4796
1.63k
#endif
4797
1.63k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
34
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
1.63k
      break;
4802
4803
173
    case COFF_SYMBOL_COMMON:
4804
173
      dst->symbol.section = bfd_com_section_ptr;
4805
173
      dst->symbol.value = src->u.syment.n_value;
4806
173
      break;
4807
4808
96
    case COFF_SYMBOL_UNDEFINED:
4809
96
      dst->symbol.section = bfd_und_section_ptr;
4810
96
      dst->symbol.value = 0;
4811
96
      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
1.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
#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
1.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
1.90k
      )
4852
165
    dst->symbol.flags |= BSF_WEAK;
4853
4854
1.90k
        break;
4855
4856
453
      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
828
      case C_LABEL:  /* Label.  */
4867
828
        if (src->u.syment.n_scnum == N_DEBUG)
4868
5
    dst->symbol.flags = BSF_DEBUGGING;
4869
823
        else
4870
823
    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
828
        if (dst->symbol.section)
4875
828
    {
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
828
      dst->symbol.value = (src->u.syment.n_value
4882
828
               - dst->symbol.section->vma);
4883
828
#endif
4884
828
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
828
        break;
4888
4889
275
      case C_FILE: /* File name.  */
4890
275
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
588
      case C_MOS:   /* Member of structure.  */
4893
787
      case C_EOS:   /* End of structure.  */
4894
1.22k
      case C_REGPARM: /* Register parameter.  */
4895
1.87k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.03k
      case C_TPDEF: /* Type definition.  */
4898
2.22k
      case C_ARG:
4899
5.56k
      case C_AUTO: /* Automatic variable.  */
4900
5.89k
      case C_FIELD: /* Bit field.  */
4901
6.15k
      case C_ENTAG: /* Enumeration tag.  */
4902
6.53k
      case C_MOE:   /* Member of enumeration.  */
4903
6.72k
      case C_MOU:   /* Member of union.  */
4904
7.00k
      case C_UNTAG: /* Union tag.  */
4905
7.76k
      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
7.76k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
7.76k
        dst->symbol.value = (src->u.syment.n_value);
4924
7.76k
        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
164
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
925
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.20k
      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
1.20k
        dst->symbol.flags = BSF_LOCAL;
4993
1.20k
        dst->symbol.value = (src->u.syment.n_value
4994
1.20k
           - dst->symbol.section->vma);
4995
1.20k
#endif
4996
1.20k
        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
45.9k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
45.9k
        if (src->u.syment.n_type == 0
5007
45.9k
      && src->u.syment.n_value == 0
5008
45.9k
      && src->u.syment.n_scnum == 0)
5009
12.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
33.6k
      case C_EXTDEF: /* External definition.  */
5017
33.7k
      case C_ULABEL: /* Undefined label.  */
5018
33.8k
      case C_USTATIC: /* Undefined static.  */
5019
33.8k
#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
34.1k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
34.7k
      case C_ALIAS: /* Duplicate tag.  */
5025
34.7k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
34.7k
      case C_EXTLAB: /* External load time label.  */
5031
46.7k
      default:
5032
46.7k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
46.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
46.7k
     abfd, src->u.syment.n_sclass,
5036
46.7k
     dst->symbol.section->name, dst->symbol.name);
5037
46.7k
        ret = false;
5038
        /* Fall through.  */
5039
46.8k
      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
46.8k
        dst->symbol.flags = BSF_DEBUGGING;
5043
46.8k
        dst->symbol.value = (src->u.syment.n_value);
5044
46.8k
        break;
5045
71.0k
      }
5046
5047
71.0k
    dst->native = src;
5048
71.0k
    dst->symbol.udata.i = 0;
5049
71.0k
    dst->lineno = NULL;
5050
5051
71.0k
    this_index += (src->u.syment.n_numaux) + 1;
5052
71.0k
    dst++;
5053
71.0k
    number_of_symbols++;
5054
71.0k
  }
5055
753
    }
5056
5057
753
  obj_symbols (abfd) = cached_area;
5058
753
  obj_raw_syments (abfd) = native_symbols;
5059
5060
753
  abfd->symcount = number_of_symbols;
5061
753
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
753
  {
5064
753
    asection *p;
5065
5066
753
    p = abfd->sections;
5067
3.18k
    while (p)
5068
3.01k
      {
5069
3.01k
  if (! coff_slurp_line_table (abfd, p))
5070
582
    return false;
5071
2.42k
  p = p->next;
5072
2.42k
      }
5073
753
  }
5074
5075
171
  return ret;
5076
753
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_symbol_table
coff-tic54x.c:coff_slurp_symbol_table
Line
Count
Source
4704
4.94k
{
4705
4.94k
  combined_entry_type *native_symbols;
4706
4.94k
  coff_symbol_type *cached_area;
4707
4.94k
  unsigned int *table_ptr;
4708
4.94k
  unsigned int number_of_symbols = 0;
4709
4.94k
  bool ret = true;
4710
4.94k
  size_t amt;
4711
4712
4.94k
  if (obj_symbols (abfd))
4713
316
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
4.62k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
3.97k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
652
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
652
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
652
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
652
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
652
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
652
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
652
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
652
  if (table_ptr == NULL)
4738
0
    return false;
4739
652
  else
4740
652
    {
4741
652
      coff_symbol_type *dst = cached_area;
4742
652
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
652
      unsigned int this_index = 0;
4744
4745
177k
      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
2.41k
      case C_EXT:
4765
2.56k
      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.56k
#ifdef C_SYSTEM
4777
2.84k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.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
2.84k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.84k
    {
4787
2.12k
    case COFF_SYMBOL_GLOBAL:
4788
2.12k
      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.12k
      dst->symbol.value = (src->u.syment.n_value
4795
2.12k
               - dst->symbol.section->vma);
4796
2.12k
#endif
4797
2.12k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
42
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.12k
      break;
4802
4803
593
    case COFF_SYMBOL_COMMON:
4804
593
      dst->symbol.section = bfd_com_section_ptr;
4805
593
      dst->symbol.value = src->u.syment.n_value;
4806
593
      break;
4807
4808
120
    case COFF_SYMBOL_UNDEFINED:
4809
120
      dst->symbol.section = bfd_und_section_ptr;
4810
120
      dst->symbol.value = 0;
4811
120
      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
2.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
2.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
2.84k
      )
4852
154
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.84k
        break;
4855
4856
1.77k
      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.22k
      case C_LABEL:  /* Label.  */
4867
2.22k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
2
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.22k
        else
4870
2.22k
    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.22k
        if (dst->symbol.section)
4875
2.22k
    {
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.22k
      dst->symbol.value = (src->u.syment.n_value
4882
2.22k
               - dst->symbol.section->vma);
4883
2.22k
#endif
4884
2.22k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.22k
        break;
4888
4889
516
      case C_FILE: /* File name.  */
4890
516
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.45k
      case C_MOS:   /* Member of structure.  */
4893
1.73k
      case C_EOS:   /* End of structure.  */
4894
2.05k
      case C_REGPARM: /* Register parameter.  */
4895
6.08k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
6.63k
      case C_TPDEF: /* Type definition.  */
4898
7.97k
      case C_ARG:
4899
20.4k
      case C_AUTO: /* Automatic variable.  */
4900
20.7k
      case C_FIELD: /* Bit field.  */
4901
21.0k
      case C_ENTAG: /* Enumeration tag.  */
4902
21.8k
      case C_MOE:   /* Member of enumeration.  */
4903
22.2k
      case C_MOU:   /* Member of union.  */
4904
22.5k
      case C_UNTAG: /* Union tag.  */
4905
23.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
23.9k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
23.9k
        dst->symbol.value = (src->u.syment.n_value);
4924
23.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
200
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.24k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.00k
      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
2.00k
        dst->symbol.flags = BSF_LOCAL;
4993
2.00k
        dst->symbol.value = (src->u.syment.n_value
4994
2.00k
           - dst->symbol.section->vma);
4995
2.00k
#endif
4996
2.00k
        break;
4997
4998
172
      case C_STATLAB: /* Static load time label.  */
4999
172
        dst->symbol.value = src->u.syment.n_value;
5000
172
        dst->symbol.flags = BSF_GLOBAL;
5001
172
        break;
5002
5003
121k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
121k
        if (src->u.syment.n_type == 0
5007
121k
      && src->u.syment.n_value == 0
5008
121k
      && src->u.syment.n_scnum == 0)
5009
39.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
82.3k
      case C_EXTDEF: /* External definition.  */
5017
82.5k
      case C_ULABEL: /* Undefined label.  */
5018
82.6k
      case C_USTATIC: /* Undefined static.  */
5019
82.6k
#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
83.2k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
84.0k
      case C_ALIAS: /* Duplicate tag.  */
5025
84.0k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
84.0k
#ifdef TICOFF
5028
84.1k
      case C_UEXT: /* Tentative external definition.  */
5029
84.1k
#endif
5030
84.2k
      case C_EXTLAB: /* External load time label.  */
5031
106k
      default:
5032
106k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
106k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
106k
     abfd, src->u.syment.n_sclass,
5036
106k
     dst->symbol.section->name, dst->symbol.name);
5037
106k
        ret = false;
5038
        /* Fall through.  */
5039
106k
      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
106k
        dst->symbol.flags = BSF_DEBUGGING;
5043
106k
        dst->symbol.value = (src->u.syment.n_value);
5044
106k
        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
652
    }
5056
5057
652
  obj_symbols (abfd) = cached_area;
5058
652
  obj_raw_syments (abfd) = native_symbols;
5059
5060
652
  abfd->symcount = number_of_symbols;
5061
652
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
652
  {
5064
652
    asection *p;
5065
5066
652
    p = abfd->sections;
5067
4.72k
    while (p)
5068
4.56k
      {
5069
4.56k
  if (! coff_slurp_line_table (abfd, p))
5070
491
    return false;
5071
4.07k
  p = p->next;
5072
4.07k
      }
5073
652
  }
5074
5075
161
  return ret;
5076
652
}
coff-z80.c:coff_slurp_symbol_table
Line
Count
Source
4704
5.91k
{
4705
5.91k
  combined_entry_type *native_symbols;
4706
5.91k
  coff_symbol_type *cached_area;
4707
5.91k
  unsigned int *table_ptr;
4708
5.91k
  unsigned int number_of_symbols = 0;
4709
5.91k
  bool ret = true;
4710
5.91k
  size_t amt;
4711
4712
5.91k
  if (obj_symbols (abfd))
4713
1.61k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
4.29k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
3.66k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
630
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
630
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
630
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
630
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
630
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
630
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
630
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
630
  if (table_ptr == NULL)
4738
0
    return false;
4739
630
  else
4740
630
    {
4741
630
      coff_symbol_type *dst = cached_area;
4742
630
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
630
      unsigned int this_index = 0;
4744
4745
73.7k
      while (this_index < last_native_index)
4746
73.0k
  {
4747
73.0k
    combined_entry_type *src = native_symbols + this_index;
4748
73.0k
    table_ptr[this_index] = number_of_symbols;
4749
4750
73.0k
    dst->symbol.the_bfd = abfd;
4751
73.0k
    BFD_ASSERT (src->is_sym);
4752
73.0k
    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
73.0k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
73.0k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
73.0k
                 src->u.syment.n_scnum);
4757
73.0k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
73.0k
    dst->symbol.value = 0;
4760
73.0k
    dst->done_lineno = false;
4761
4762
73.0k
    switch (src->u.syment.n_sclass)
4763
73.0k
      {
4764
1.60k
      case C_EXT:
4765
1.74k
      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.74k
#ifdef C_SYSTEM
4777
1.86k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.86k
#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
1.86k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
1.86k
    {
4787
1.36k
    case COFF_SYMBOL_GLOBAL:
4788
1.36k
      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
1.36k
      dst->symbol.value = (src->u.syment.n_value
4795
1.36k
               - dst->symbol.section->vma);
4796
1.36k
#endif
4797
1.36k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
45
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
1.36k
      break;
4802
4803
411
    case COFF_SYMBOL_COMMON:
4804
411
      dst->symbol.section = bfd_com_section_ptr;
4805
411
      dst->symbol.value = src->u.syment.n_value;
4806
411
      break;
4807
4808
90
    case COFF_SYMBOL_UNDEFINED:
4809
90
      dst->symbol.section = bfd_und_section_ptr;
4810
90
      dst->symbol.value = 0;
4811
90
      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
1.86k
    }
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
1.86k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
1.86k
      )
4852
138
    dst->symbol.flags |= BSF_WEAK;
4853
4854
1.86k
        break;
4855
4856
1.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
1.52k
      case C_LABEL:  /* Label.  */
4867
1.52k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.52k
        else
4870
1.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
1.52k
        if (dst->symbol.section)
4875
1.52k
    {
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
1.52k
      dst->symbol.value = (src->u.syment.n_value
4882
1.52k
               - dst->symbol.section->vma);
4883
1.52k
#endif
4884
1.52k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.52k
        break;
4888
4889
475
      case C_FILE: /* File name.  */
4890
475
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
785
      case C_MOS:   /* Member of structure.  */
4893
948
      case C_EOS:   /* End of structure.  */
4894
1.06k
      case C_REGPARM: /* Register parameter.  */
4895
1.35k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
1.45k
      case C_TPDEF: /* Type definition.  */
4898
1.82k
      case C_ARG:
4899
5.00k
      case C_AUTO: /* Automatic variable.  */
4900
5.26k
      case C_FIELD: /* Bit field.  */
4901
5.47k
      case C_ENTAG: /* Enumeration tag.  */
4902
5.77k
      case C_MOE:   /* Member of enumeration.  */
4903
6.09k
      case C_MOU:   /* Member of union.  */
4904
6.32k
      case C_UNTAG: /* Union tag.  */
4905
6.89k
      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
6.89k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
6.89k
        dst->symbol.value = (src->u.syment.n_value);
4924
6.89k
        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
131
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.08k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.35k
      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
1.35k
        dst->symbol.flags = BSF_LOCAL;
4993
1.35k
        dst->symbol.value = (src->u.syment.n_value
4994
1.35k
           - dst->symbol.section->vma);
4995
1.35k
#endif
4996
1.35k
        break;
4997
4998
86
      case C_STATLAB: /* Static load time label.  */
4999
86
        dst->symbol.value = src->u.syment.n_value;
5000
86
        dst->symbol.flags = BSF_GLOBAL;
5001
86
        break;
5002
5003
48.3k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
48.3k
        if (src->u.syment.n_type == 0
5007
48.3k
      && src->u.syment.n_value == 0
5008
48.3k
      && src->u.syment.n_scnum == 0)
5009
16.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
31.5k
      case C_EXTDEF: /* External definition.  */
5017
31.7k
      case C_ULABEL: /* Undefined label.  */
5018
31.7k
      case C_USTATIC: /* Undefined static.  */
5019
31.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
32.2k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
32.8k
      case C_ALIAS: /* Duplicate tag.  */
5025
32.8k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
32.8k
      case C_EXTLAB: /* External load time label.  */
5031
44.4k
      default:
5032
44.4k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
44.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
44.4k
     abfd, src->u.syment.n_sclass,
5036
44.4k
     dst->symbol.section->name, dst->symbol.name);
5037
44.4k
        ret = false;
5038
        /* Fall through.  */
5039
44.4k
      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
44.4k
        dst->symbol.flags = BSF_DEBUGGING;
5043
44.4k
        dst->symbol.value = (src->u.syment.n_value);
5044
44.4k
        break;
5045
73.0k
      }
5046
5047
73.0k
    dst->native = src;
5048
73.0k
    dst->symbol.udata.i = 0;
5049
73.0k
    dst->lineno = NULL;
5050
5051
73.0k
    this_index += (src->u.syment.n_numaux) + 1;
5052
73.0k
    dst++;
5053
73.0k
    number_of_symbols++;
5054
73.0k
  }
5055
630
    }
5056
5057
630
  obj_symbols (abfd) = cached_area;
5058
630
  obj_raw_syments (abfd) = native_symbols;
5059
5060
630
  abfd->symcount = number_of_symbols;
5061
630
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
630
  {
5064
630
    asection *p;
5065
5066
630
    p = abfd->sections;
5067
3.85k
    while (p)
5068
3.69k
      {
5069
3.69k
  if (! coff_slurp_line_table (abfd, p))
5070
470
    return false;
5071
3.22k
  p = p->next;
5072
3.22k
      }
5073
630
  }
5074
5075
160
  return ret;
5076
630
}
coff-z8k.c:coff_slurp_symbol_table
Line
Count
Source
4704
4.89k
{
4705
4.89k
  combined_entry_type *native_symbols;
4706
4.89k
  coff_symbol_type *cached_area;
4707
4.89k
  unsigned int *table_ptr;
4708
4.89k
  unsigned int number_of_symbols = 0;
4709
4.89k
  bool ret = true;
4710
4.89k
  size_t amt;
4711
4712
4.89k
  if (obj_symbols (abfd))
4713
1.16k
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
3.73k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
3.21k
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
518
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
518
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
518
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
518
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
518
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
518
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
518
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
518
  if (table_ptr == NULL)
4738
0
    return false;
4739
518
  else
4740
518
    {
4741
518
      coff_symbol_type *dst = cached_area;
4742
518
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
518
      unsigned int this_index = 0;
4744
4745
142k
      while (this_index < last_native_index)
4746
141k
  {
4747
141k
    combined_entry_type *src = native_symbols + this_index;
4748
141k
    table_ptr[this_index] = number_of_symbols;
4749
4750
141k
    dst->symbol.the_bfd = abfd;
4751
141k
    BFD_ASSERT (src->is_sym);
4752
141k
    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
141k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
141k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
141k
                 src->u.syment.n_scnum);
4757
141k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
141k
    dst->symbol.value = 0;
4760
141k
    dst->done_lineno = false;
4761
4762
141k
    switch (src->u.syment.n_sclass)
4763
141k
      {
4764
1.79k
      case C_EXT:
4765
2.10k
      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.10k
#ifdef C_SYSTEM
4777
2.50k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.50k
#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
2.50k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.50k
    {
4787
2.05k
    case COFF_SYMBOL_GLOBAL:
4788
2.05k
      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.05k
      dst->symbol.value = (src->u.syment.n_value
4795
2.05k
               - dst->symbol.section->vma);
4796
2.05k
#endif
4797
2.05k
      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.05k
      break;
4802
4803
317
    case COFF_SYMBOL_COMMON:
4804
317
      dst->symbol.section = bfd_com_section_ptr;
4805
317
      dst->symbol.value = src->u.syment.n_value;
4806
317
      break;
4807
4808
133
    case COFF_SYMBOL_UNDEFINED:
4809
133
      dst->symbol.section = bfd_und_section_ptr;
4810
133
      dst->symbol.value = 0;
4811
133
      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
2.50k
    }
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
2.50k
        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.50k
      )
4852
319
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.50k
        break;
4855
4856
649
      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
1.74k
      case C_LABEL:  /* Label.  */
4867
1.74k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.74k
        else
4870
1.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
1.74k
        if (dst->symbol.section)
4875
1.74k
    {
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
1.74k
      dst->symbol.value = (src->u.syment.n_value
4882
1.74k
               - dst->symbol.section->vma);
4883
1.74k
#endif
4884
1.74k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.74k
        break;
4888
4889
862
      case C_FILE: /* File name.  */
4890
862
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.85k
      case C_MOS:   /* Member of structure.  */
4893
2.07k
      case C_EOS:   /* End of structure.  */
4894
2.42k
      case C_REGPARM: /* Register parameter.  */
4895
3.21k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.70k
      case C_TPDEF: /* Type definition.  */
4898
4.47k
      case C_ARG:
4899
10.7k
      case C_AUTO: /* Automatic variable.  */
4900
11.0k
      case C_FIELD: /* Bit field.  */
4901
11.4k
      case C_ENTAG: /* Enumeration tag.  */
4902
12.2k
      case C_MOE:   /* Member of enumeration.  */
4903
12.6k
      case C_MOU:   /* Member of union.  */
4904
13.0k
      case C_UNTAG: /* Union tag.  */
4905
13.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
13.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
13.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
13.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
264
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.75k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.46k
      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.46k
        dst->symbol.flags = BSF_LOCAL;
4993
3.46k
        dst->symbol.value = (src->u.syment.n_value
4994
3.46k
           - dst->symbol.section->vma);
4995
3.46k
#endif
4996
3.46k
        break;
4997
4998
765
      case C_STATLAB: /* Static load time label.  */
4999
765
        dst->symbol.value = src->u.syment.n_value;
5000
765
        dst->symbol.flags = BSF_GLOBAL;
5001
765
        break;
5002
5003
91.0k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
91.0k
        if (src->u.syment.n_type == 0
5007
91.0k
      && src->u.syment.n_value == 0
5008
91.0k
      && 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
60.6k
      case C_EXTDEF: /* External definition.  */
5017
60.9k
      case C_ULABEL: /* Undefined label.  */
5018
61.0k
      case C_USTATIC: /* Undefined static.  */
5019
61.0k
#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
62.1k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5023
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5024
63.5k
      case C_ALIAS: /* Duplicate tag.  */
5025
63.5k
#endif
5026
        /* New storage classes for TI COFF.  */
5027
#ifdef TICOFF
5028
      case C_UEXT:  /* Tentative external definition.  */
5029
#endif
5030
63.6k
      case C_EXTLAB: /* External load time label.  */
5031
88.7k
      default:
5032
88.7k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
88.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
88.7k
     abfd, src->u.syment.n_sclass,
5036
88.7k
     dst->symbol.section->name, dst->symbol.name);
5037
88.7k
        ret = false;
5038
        /* Fall through.  */
5039
88.8k
      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
88.8k
        dst->symbol.flags = BSF_DEBUGGING;
5043
88.8k
        dst->symbol.value = (src->u.syment.n_value);
5044
88.8k
        break;
5045
141k
      }
5046
5047
141k
    dst->native = src;
5048
141k
    dst->symbol.udata.i = 0;
5049
141k
    dst->lineno = NULL;
5050
5051
141k
    this_index += (src->u.syment.n_numaux) + 1;
5052
141k
    dst++;
5053
141k
    number_of_symbols++;
5054
141k
  }
5055
518
    }
5056
5057
518
  obj_symbols (abfd) = cached_area;
5058
518
  obj_raw_syments (abfd) = native_symbols;
5059
5060
518
  abfd->symcount = number_of_symbols;
5061
518
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
518
  {
5064
518
    asection *p;
5065
5066
518
    p = abfd->sections;
5067
1.54k
    while (p)
5068
1.43k
      {
5069
1.43k
  if (! coff_slurp_line_table (abfd, p))
5070
404
    return false;
5071
1.02k
  p = p->next;
5072
1.02k
      }
5073
518
  }
5074
5075
114
  return ret;
5076
518
}
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
599
{
4705
599
  combined_entry_type *native_symbols;
4706
599
  coff_symbol_type *cached_area;
4707
599
  unsigned int *table_ptr;
4708
599
  unsigned int number_of_symbols = 0;
4709
599
  bool ret = true;
4710
599
  size_t amt;
4711
4712
599
  if (obj_symbols (abfd))
4713
119
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
480
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
32
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
448
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
448
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
448
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
448
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
448
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
448
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
448
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
448
  if (table_ptr == NULL)
4738
0
    return false;
4739
448
  else
4740
448
    {
4741
448
      coff_symbol_type *dst = cached_area;
4742
448
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
448
      unsigned int this_index = 0;
4744
4745
161k
      while (this_index < last_native_index)
4746
160k
  {
4747
160k
    combined_entry_type *src = native_symbols + this_index;
4748
160k
    table_ptr[this_index] = number_of_symbols;
4749
4750
160k
    dst->symbol.the_bfd = abfd;
4751
160k
    BFD_ASSERT (src->is_sym);
4752
160k
    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
160k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
160k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
160k
                 src->u.syment.n_scnum);
4757
160k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
160k
    dst->symbol.value = 0;
4760
160k
    dst->done_lineno = false;
4761
4762
160k
    switch (src->u.syment.n_sclass)
4763
160k
      {
4764
4.08k
      case C_EXT:
4765
4.19k
      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.19k
#ifdef C_SYSTEM
4777
6.20k
      case C_SYSTEM: /* System Wide variable.  */
4778
6.20k
#endif
4779
6.20k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
6.23k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
8.59k
      case C_NT_WEAK:
4784
8.59k
#endif
4785
8.59k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
8.59k
    {
4787
7.80k
    case COFF_SYMBOL_GLOBAL:
4788
7.80k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
7.80k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
7.80k
      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.80k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
480
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
7.80k
      break;
4802
4803
602
    case COFF_SYMBOL_COMMON:
4804
602
      dst->symbol.section = bfd_com_section_ptr;
4805
602
      dst->symbol.value = src->u.syment.n_value;
4806
602
      break;
4807
4808
187
    case COFF_SYMBOL_UNDEFINED:
4809
187
      dst->symbol.section = bfd_und_section_ptr;
4810
187
      dst->symbol.value = 0;
4811
187
      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.59k
    }
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.59k
#ifdef COFF_WITH_PE
4840
8.59k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
2.36k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
8.59k
        if (src->u.syment.n_sclass == C_SECTION
4844
8.59k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
8.59k
#endif
4847
8.59k
        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.59k
      )
4852
107
    dst->symbol.flags |= BSF_WEAK;
4853
4854
8.59k
        break;
4855
4856
2.40k
      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.11k
      case C_LABEL:  /* Label.  */
4867
3.11k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
3.11k
        else
4870
3.11k
    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.11k
        if (dst->symbol.section)
4875
3.11k
    {
4876
3.11k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
3.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
3.11k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
3.11k
        break;
4888
4889
1.07k
      case C_FILE: /* File name.  */
4890
1.07k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.73k
      case C_MOS:   /* Member of structure.  */
4893
2.85k
      case C_EOS:   /* End of structure.  */
4894
3.17k
      case C_REGPARM: /* Register parameter.  */
4895
3.77k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
3.99k
      case C_TPDEF: /* Type definition.  */
4898
4.69k
      case C_ARG:
4899
8.72k
      case C_AUTO: /* Automatic variable.  */
4900
9.02k
      case C_FIELD: /* Bit field.  */
4901
9.28k
      case C_ENTAG: /* Enumeration tag.  */
4902
11.0k
      case C_MOE:   /* Member of enumeration.  */
4903
12.8k
      case C_MOU:   /* Member of union.  */
4904
13.1k
      case C_UNTAG: /* Union tag.  */
4905
13.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
13.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
13.7k
        dst->symbol.value = (src->u.syment.n_value);
4924
13.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
376
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.11k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
4.12k
      case C_EFCN: /* Physical end of function.  */
4977
4.12k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
4.12k
        dst->symbol.value = src->u.syment.n_value;
4981
4.12k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
4.12k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
4.12k
      dst->symbol.flags = BSF_DEBUGGING;
4986
4.12k
    }
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
4.12k
        break;
4997
4998
257
      case C_STATLAB: /* Static load time label.  */
4999
257
        dst->symbol.value = src->u.syment.n_value;
5000
257
        dst->symbol.flags = BSF_GLOBAL;
5001
257
        break;
5002
5003
100k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
100k
        if (src->u.syment.n_type == 0
5007
100k
      && src->u.syment.n_value == 0
5008
100k
      && src->u.syment.n_scnum == 0)
5009
33.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
67.0k
      case C_EXTDEF: /* External definition.  */
5017
67.2k
      case C_ULABEL: /* Undefined label.  */
5018
67.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
67.4k
      case C_EXTLAB: /* External load time label.  */
5031
96.9k
      default:
5032
96.9k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
96.9k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
96.9k
     abfd, src->u.syment.n_sclass,
5036
96.9k
     dst->symbol.section->name, dst->symbol.name);
5037
96.9k
        ret = false;
5038
        /* Fall through.  */
5039
97.6k
      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
97.6k
        dst->symbol.flags = BSF_DEBUGGING;
5043
97.6k
        dst->symbol.value = (src->u.syment.n_value);
5044
97.6k
        break;
5045
160k
      }
5046
5047
160k
    dst->native = src;
5048
160k
    dst->symbol.udata.i = 0;
5049
160k
    dst->lineno = NULL;
5050
5051
160k
    this_index += (src->u.syment.n_numaux) + 1;
5052
160k
    dst++;
5053
160k
    number_of_symbols++;
5054
160k
  }
5055
448
    }
5056
5057
448
  obj_symbols (abfd) = cached_area;
5058
448
  obj_raw_syments (abfd) = native_symbols;
5059
5060
448
  abfd->symcount = number_of_symbols;
5061
448
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
448
  {
5064
448
    asection *p;
5065
5066
448
    p = abfd->sections;
5067
795
    while (p)
5068
610
      {
5069
610
  if (! coff_slurp_line_table (abfd, p))
5070
263
    return false;
5071
347
  p = p->next;
5072
347
      }
5073
448
  }
5074
5075
185
  return ret;
5076
448
}
pe-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4704
972
{
4705
972
  combined_entry_type *native_symbols;
4706
972
  coff_symbol_type *cached_area;
4707
972
  unsigned int *table_ptr;
4708
972
  unsigned int number_of_symbols = 0;
4709
972
  bool ret = true;
4710
972
  size_t amt;
4711
4712
972
  if (obj_symbols (abfd))
4713
265
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
707
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
150
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
557
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
557
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
557
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
557
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
557
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
557
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
557
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
557
  if (table_ptr == NULL)
4738
0
    return false;
4739
557
  else
4740
557
    {
4741
557
      coff_symbol_type *dst = cached_area;
4742
557
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
557
      unsigned int this_index = 0;
4744
4745
202k
      while (this_index < last_native_index)
4746
201k
  {
4747
201k
    combined_entry_type *src = native_symbols + this_index;
4748
201k
    table_ptr[this_index] = number_of_symbols;
4749
4750
201k
    dst->symbol.the_bfd = abfd;
4751
201k
    BFD_ASSERT (src->is_sym);
4752
201k
    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
201k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
201k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
201k
                 src->u.syment.n_scnum);
4757
201k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
201k
    dst->symbol.value = 0;
4760
201k
    dst->done_lineno = false;
4761
4762
201k
    switch (src->u.syment.n_sclass)
4763
201k
      {
4764
3.70k
      case C_EXT:
4765
3.94k
      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.94k
#ifdef C_SYSTEM
4777
4.55k
      case C_SYSTEM: /* System Wide variable.  */
4778
4.55k
#endif
4779
4.55k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
4.61k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
6.56k
      case C_NT_WEAK:
4784
6.56k
#endif
4785
6.56k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
6.56k
    {
4787
5.71k
    case COFF_SYMBOL_GLOBAL:
4788
5.71k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
5.71k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
5.71k
      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
5.71k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
96
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
5.71k
      break;
4802
4803
644
    case COFF_SYMBOL_COMMON:
4804
644
      dst->symbol.section = bfd_com_section_ptr;
4805
644
      dst->symbol.value = src->u.syment.n_value;
4806
644
      break;
4807
4808
208
    case COFF_SYMBOL_UNDEFINED:
4809
208
      dst->symbol.section = bfd_und_section_ptr;
4810
208
      dst->symbol.value = 0;
4811
208
      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
6.56k
    }
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
6.56k
#ifdef COFF_WITH_PE
4840
6.56k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.95k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
6.56k
        if (src->u.syment.n_sclass == C_SECTION
4844
6.56k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
6.56k
#endif
4847
6.56k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
6.56k
      )
4852
238
    dst->symbol.flags |= BSF_WEAK;
4853
4854
6.56k
        break;
4855
4856
2.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
2.88k
      case C_LABEL:  /* Label.  */
4867
2.88k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.88k
        else
4870
2.88k
    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.88k
        if (dst->symbol.section)
4875
2.88k
    {
4876
2.88k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.88k
      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.88k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.88k
        break;
4888
4889
1.07k
      case C_FILE: /* File name.  */
4890
1.07k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.77k
      case C_MOS:   /* Member of structure.  */
4893
4.26k
      case C_EOS:   /* End of structure.  */
4894
4.59k
      case C_REGPARM: /* Register parameter.  */
4895
7.29k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
7.71k
      case C_TPDEF: /* Type definition.  */
4898
8.90k
      case C_ARG:
4899
17.9k
      case C_AUTO: /* Automatic variable.  */
4900
18.3k
      case C_FIELD: /* Bit field.  */
4901
18.5k
      case C_ENTAG: /* Enumeration tag.  */
4902
19.2k
      case C_MOE:   /* Member of enumeration.  */
4903
20.7k
      case C_MOU:   /* Member of union.  */
4904
21.3k
      case C_UNTAG: /* Union tag.  */
4905
22.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
22.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
22.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
22.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
522
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
3.27k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
4.07k
      case C_EFCN: /* Physical end of function.  */
4977
4.07k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
4.07k
        dst->symbol.value = src->u.syment.n_value;
4981
4.07k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
4.07k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
4.07k
      dst->symbol.flags = BSF_DEBUGGING;
4986
4.07k
    }
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
4.07k
        break;
4997
4998
468
      case C_STATLAB: /* Static load time label.  */
4999
468
        dst->symbol.value = src->u.syment.n_value;
5000
468
        dst->symbol.flags = BSF_GLOBAL;
5001
468
        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
46.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
84.1k
      case C_EXTDEF: /* External definition.  */
5017
84.3k
      case C_ULABEL: /* Undefined label.  */
5018
84.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
84.5k
      case C_EXTLAB: /* External load time label.  */
5031
118k
      default:
5032
118k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
118k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
118k
     abfd, src->u.syment.n_sclass,
5036
118k
     dst->symbol.section->name, dst->symbol.name);
5037
118k
        ret = false;
5038
        /* Fall through.  */
5039
118k
      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
118k
        dst->symbol.flags = BSF_DEBUGGING;
5043
118k
        dst->symbol.value = (src->u.syment.n_value);
5044
118k
        break;
5045
201k
      }
5046
5047
201k
    dst->native = src;
5048
201k
    dst->symbol.udata.i = 0;
5049
201k
    dst->lineno = NULL;
5050
5051
201k
    this_index += (src->u.syment.n_numaux) + 1;
5052
201k
    dst++;
5053
201k
    number_of_symbols++;
5054
201k
  }
5055
557
    }
5056
5057
557
  obj_symbols (abfd) = cached_area;
5058
557
  obj_raw_syments (abfd) = native_symbols;
5059
5060
557
  abfd->symcount = number_of_symbols;
5061
557
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
557
  {
5064
557
    asection *p;
5065
5066
557
    p = abfd->sections;
5067
1.30k
    while (p)
5068
1.04k
      {
5069
1.04k
  if (! coff_slurp_line_table (abfd, p))
5070
301
    return false;
5071
745
  p = p->next;
5072
745
      }
5073
557
  }
5074
5075
256
  return ret;
5076
557
}
pe-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
839
{
4705
839
  combined_entry_type *native_symbols;
4706
839
  coff_symbol_type *cached_area;
4707
839
  unsigned int *table_ptr;
4708
839
  unsigned int number_of_symbols = 0;
4709
839
  bool ret = true;
4710
839
  size_t amt;
4711
4712
839
  if (obj_symbols (abfd))
4713
233
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
606
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
75
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
531
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
531
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
531
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
531
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
531
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
531
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
531
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
531
  if (table_ptr == NULL)
4738
0
    return false;
4739
531
  else
4740
531
    {
4741
531
      coff_symbol_type *dst = cached_area;
4742
531
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
531
      unsigned int this_index = 0;
4744
4745
130k
      while (this_index < last_native_index)
4746
129k
  {
4747
129k
    combined_entry_type *src = native_symbols + this_index;
4748
129k
    table_ptr[this_index] = number_of_symbols;
4749
4750
129k
    dst->symbol.the_bfd = abfd;
4751
129k
    BFD_ASSERT (src->is_sym);
4752
129k
    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
129k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
129k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
129k
                 src->u.syment.n_scnum);
4757
129k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
129k
    dst->symbol.value = 0;
4760
129k
    dst->done_lineno = false;
4761
4762
129k
    switch (src->u.syment.n_sclass)
4763
129k
      {
4764
2.82k
      case C_EXT:
4765
2.96k
      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.96k
#ifdef C_SYSTEM
4777
3.50k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.50k
#endif
4779
3.50k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
3.54k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
5.09k
      case C_NT_WEAK:
4784
5.09k
#endif
4785
5.09k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
5.09k
    {
4787
4.38k
    case COFF_SYMBOL_GLOBAL:
4788
4.38k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
4.38k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
4.38k
      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.38k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
169
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
4.38k
      break;
4802
4803
501
    case COFF_SYMBOL_COMMON:
4804
501
      dst->symbol.section = bfd_com_section_ptr;
4805
501
      dst->symbol.value = src->u.syment.n_value;
4806
501
      break;
4807
4808
207
    case COFF_SYMBOL_UNDEFINED:
4809
207
      dst->symbol.section = bfd_und_section_ptr;
4810
207
      dst->symbol.value = 0;
4811
207
      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
5.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
5.09k
#ifdef COFF_WITH_PE
4840
5.09k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.54k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
5.09k
        if (src->u.syment.n_sclass == C_SECTION
4844
5.09k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
5.09k
#endif
4847
5.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
5.09k
      )
4852
138
    dst->symbol.flags |= BSF_WEAK;
4853
4854
5.09k
        break;
4855
4856
1.91k
      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
3
    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
722
      case C_FILE: /* File name.  */
4890
722
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.65k
      case C_MOS:   /* Member of structure.  */
4893
2.11k
      case C_EOS:   /* End of structure.  */
4894
2.71k
      case C_REGPARM: /* Register parameter.  */
4895
4.84k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
5.55k
      case C_TPDEF: /* Type definition.  */
4898
8.08k
      case C_ARG:
4899
12.3k
      case C_AUTO: /* Automatic variable.  */
4900
12.8k
      case C_FIELD: /* Bit field.  */
4901
13.6k
      case C_ENTAG: /* Enumeration tag.  */
4902
14.4k
      case C_MOE:   /* Member of enumeration.  */
4903
14.9k
      case C_MOU:   /* Member of union.  */
4904
16.3k
      case C_UNTAG: /* Union tag.  */
4905
16.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
16.9k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
16.9k
        dst->symbol.value = (src->u.syment.n_value);
4924
16.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
304
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.31k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.91k
      case C_EFCN: /* Physical end of function.  */
4977
2.91k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.91k
        dst->symbol.value = src->u.syment.n_value;
4981
2.91k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.91k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.91k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.91k
    }
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
2.91k
        break;
4997
4998
654
      case C_STATLAB: /* Static load time label.  */
4999
654
        dst->symbol.value = src->u.syment.n_value;
5000
654
        dst->symbol.flags = BSF_GLOBAL;
5001
654
        break;
5002
5003
77.9k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
77.9k
        if (src->u.syment.n_type == 0
5007
77.9k
      && src->u.syment.n_value == 0
5008
77.9k
      && src->u.syment.n_scnum == 0)
5009
19.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
58.4k
      case C_EXTDEF: /* External definition.  */
5017
58.5k
      case C_ULABEL: /* Undefined label.  */
5018
58.7k
      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
58.8k
      case C_EXTLAB: /* External load time label.  */
5031
81.8k
      default:
5032
81.8k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
81.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
81.8k
     abfd, src->u.syment.n_sclass,
5036
81.8k
     dst->symbol.section->name, dst->symbol.name);
5037
81.8k
        ret = false;
5038
        /* Fall through.  */
5039
81.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
81.9k
        dst->symbol.flags = BSF_DEBUGGING;
5043
81.9k
        dst->symbol.value = (src->u.syment.n_value);
5044
81.9k
        break;
5045
129k
      }
5046
5047
129k
    dst->native = src;
5048
129k
    dst->symbol.udata.i = 0;
5049
129k
    dst->lineno = NULL;
5050
5051
129k
    this_index += (src->u.syment.n_numaux) + 1;
5052
129k
    dst++;
5053
129k
    number_of_symbols++;
5054
129k
  }
5055
531
    }
5056
5057
531
  obj_symbols (abfd) = cached_area;
5058
531
  obj_raw_syments (abfd) = native_symbols;
5059
5060
531
  abfd->symcount = number_of_symbols;
5061
531
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
531
  {
5064
531
    asection *p;
5065
5066
531
    p = abfd->sections;
5067
1.37k
    while (p)
5068
1.20k
      {
5069
1.20k
  if (! coff_slurp_line_table (abfd, p))
5070
361
    return false;
5071
842
  p = p->next;
5072
842
      }
5073
531
  }
5074
5075
170
  return ret;
5076
531
}
pei-arm-wince.c:coff_slurp_symbol_table
Line
Count
Source
4704
326
{
4705
326
  combined_entry_type *native_symbols;
4706
326
  coff_symbol_type *cached_area;
4707
326
  unsigned int *table_ptr;
4708
326
  unsigned int number_of_symbols = 0;
4709
326
  bool ret = true;
4710
326
  size_t amt;
4711
4712
326
  if (obj_symbols (abfd))
4713
11
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
315
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
20
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
295
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
295
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
295
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
295
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
295
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
295
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
295
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
295
  if (table_ptr == NULL)
4738
0
    return false;
4739
295
  else
4740
295
    {
4741
295
      coff_symbol_type *dst = cached_area;
4742
295
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
295
      unsigned int this_index = 0;
4744
4745
60.7k
      while (this_index < last_native_index)
4746
60.4k
  {
4747
60.4k
    combined_entry_type *src = native_symbols + this_index;
4748
60.4k
    table_ptr[this_index] = number_of_symbols;
4749
4750
60.4k
    dst->symbol.the_bfd = abfd;
4751
60.4k
    BFD_ASSERT (src->is_sym);
4752
60.4k
    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
60.4k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
60.4k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
60.4k
                 src->u.syment.n_scnum);
4757
60.4k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
60.4k
    dst->symbol.value = 0;
4760
60.4k
    dst->done_lineno = false;
4761
4762
60.4k
    switch (src->u.syment.n_sclass)
4763
60.4k
      {
4764
1.02k
      case C_EXT:
4765
1.07k
      case C_WEAKEXT:
4766
1.07k
#if defined ARM
4767
1.10k
      case C_THUMBEXT:
4768
1.12k
      case C_THUMBEXTFUNC:
4769
1.12k
#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.12k
#ifdef C_SYSTEM
4777
1.41k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.41k
#endif
4779
1.41k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
1.44k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
2.25k
      case C_NT_WEAK:
4784
2.25k
#endif
4785
2.25k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.25k
    {
4787
2.04k
    case COFF_SYMBOL_GLOBAL:
4788
2.04k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.04k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.04k
      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.04k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
37
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.04k
      break;
4802
4803
126
    case COFF_SYMBOL_COMMON:
4804
126
      dst->symbol.section = bfd_com_section_ptr;
4805
126
      dst->symbol.value = src->u.syment.n_value;
4806
126
      break;
4807
4808
86
    case COFF_SYMBOL_UNDEFINED:
4809
86
      dst->symbol.section = bfd_und_section_ptr;
4810
86
      dst->symbol.value = 0;
4811
86
      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.25k
    }
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.25k
#ifdef COFF_WITH_PE
4840
2.25k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
804
    dst->symbol.flags |= BSF_WEAK;
4842
4843
2.25k
        if (src->u.syment.n_sclass == C_SECTION
4844
2.25k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
2.25k
#endif
4847
2.25k
        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.25k
      )
4852
54
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.25k
        break;
4855
4856
1.00k
      case C_STAT:  /* Static.  */
4857
1.00k
#if defined ARM
4858
1.06k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
1.08k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
1.12k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
1.12k
#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
1.33k
      case C_LABEL:  /* Label.  */
4867
1.33k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
1
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.33k
        else
4870
1.33k
    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
1.33k
        if (dst->symbol.section)
4875
1.33k
    {
4876
1.33k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
1.33k
      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
1.33k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.33k
        break;
4888
4889
525
      case C_FILE: /* File name.  */
4890
525
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
982
      case C_MOS:   /* Member of structure.  */
4893
1.21k
      case C_EOS:   /* End of structure.  */
4894
1.29k
      case C_REGPARM: /* Register parameter.  */
4895
1.54k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
1.77k
      case C_TPDEF: /* Type definition.  */
4898
2.35k
      case C_ARG:
4899
3.80k
      case C_AUTO: /* Automatic variable.  */
4900
3.88k
      case C_FIELD: /* Bit field.  */
4901
4.16k
      case C_ENTAG: /* Enumeration tag.  */
4902
4.43k
      case C_MOE:   /* Member of enumeration.  */
4903
4.76k
      case C_MOU:   /* Member of union.  */
4904
5.15k
      case C_UNTAG: /* Union tag.  */
4905
5.53k
      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
5.53k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
5.53k
        dst->symbol.value = (src->u.syment.n_value);
4924
5.53k
        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
190
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.69k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.94k
      case C_EFCN: /* Physical end of function.  */
4977
1.94k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
1.94k
        dst->symbol.value = src->u.syment.n_value;
4981
1.94k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
1.94k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
1.94k
      dst->symbol.flags = BSF_DEBUGGING;
4986
1.94k
    }
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
1.94k
        break;
4997
4998
70
      case C_STATLAB: /* Static load time label.  */
4999
70
        dst->symbol.value = src->u.syment.n_value;
5000
70
        dst->symbol.flags = BSF_GLOBAL;
5001
70
        break;
5002
5003
34.6k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
34.6k
        if (src->u.syment.n_type == 0
5007
34.6k
      && src->u.syment.n_value == 0
5008
34.6k
      && src->u.syment.n_scnum == 0)
5009
6.22k
    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
28.4k
      case C_EXTDEF: /* External definition.  */
5017
28.6k
      case C_ULABEL: /* Undefined label.  */
5018
28.7k
      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
28.7k
      case C_EXTLAB: /* External load time label.  */
5031
43.0k
      default:
5032
43.0k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
43.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
43.0k
     abfd, src->u.syment.n_sclass,
5036
43.0k
     dst->symbol.section->name, dst->symbol.name);
5037
43.0k
        ret = false;
5038
        /* Fall through.  */
5039
43.0k
      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
43.0k
        dst->symbol.flags = BSF_DEBUGGING;
5043
43.0k
        dst->symbol.value = (src->u.syment.n_value);
5044
43.0k
        break;
5045
60.4k
      }
5046
5047
60.4k
    dst->native = src;
5048
60.4k
    dst->symbol.udata.i = 0;
5049
60.4k
    dst->lineno = NULL;
5050
5051
60.4k
    this_index += (src->u.syment.n_numaux) + 1;
5052
60.4k
    dst++;
5053
60.4k
    number_of_symbols++;
5054
60.4k
  }
5055
295
    }
5056
5057
295
  obj_symbols (abfd) = cached_area;
5058
295
  obj_raw_syments (abfd) = native_symbols;
5059
5060
295
  abfd->symcount = number_of_symbols;
5061
295
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
295
  {
5064
295
    asection *p;
5065
5066
295
    p = abfd->sections;
5067
504
    while (p)
5068
442
      {
5069
442
  if (! coff_slurp_line_table (abfd, p))
5070
233
    return false;
5071
209
  p = p->next;
5072
209
      }
5073
295
  }
5074
5075
62
  return ret;
5076
295
}
pei-arm.c:coff_slurp_symbol_table
Line
Count
Source
4704
533
{
4705
533
  combined_entry_type *native_symbols;
4706
533
  coff_symbol_type *cached_area;
4707
533
  unsigned int *table_ptr;
4708
533
  unsigned int number_of_symbols = 0;
4709
533
  bool ret = true;
4710
533
  size_t amt;
4711
4712
533
  if (obj_symbols (abfd))
4713
29
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
504
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
67
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
437
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
437
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
437
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
437
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
437
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
437
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
437
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
437
  if (table_ptr == NULL)
4738
0
    return false;
4739
437
  else
4740
437
    {
4741
437
      coff_symbol_type *dst = cached_area;
4742
437
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
437
      unsigned int this_index = 0;
4744
4745
128k
      while (this_index < last_native_index)
4746
127k
  {
4747
127k
    combined_entry_type *src = native_symbols + this_index;
4748
127k
    table_ptr[this_index] = number_of_symbols;
4749
4750
127k
    dst->symbol.the_bfd = abfd;
4751
127k
    BFD_ASSERT (src->is_sym);
4752
127k
    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
127k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
127k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
127k
                 src->u.syment.n_scnum);
4757
127k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
127k
    dst->symbol.value = 0;
4760
127k
    dst->done_lineno = false;
4761
4762
127k
    switch (src->u.syment.n_sclass)
4763
127k
      {
4764
2.35k
      case C_EXT:
4765
2.44k
      case C_WEAKEXT:
4766
2.44k
#if defined ARM
4767
2.50k
      case C_THUMBEXT:
4768
2.54k
      case C_THUMBEXTFUNC:
4769
2.54k
#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.54k
#ifdef C_SYSTEM
4777
2.87k
      case C_SYSTEM: /* System Wide variable.  */
4778
2.87k
#endif
4779
2.87k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
2.88k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
3.69k
      case C_NT_WEAK:
4784
3.69k
#endif
4785
3.69k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
3.69k
    {
4787
2.81k
    case COFF_SYMBOL_GLOBAL:
4788
2.81k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.81k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.81k
      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.81k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
69
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.81k
      break;
4802
4803
792
    case COFF_SYMBOL_COMMON:
4804
792
      dst->symbol.section = bfd_com_section_ptr;
4805
792
      dst->symbol.value = src->u.syment.n_value;
4806
792
      break;
4807
4808
82
    case COFF_SYMBOL_UNDEFINED:
4809
82
      dst->symbol.section = bfd_und_section_ptr;
4810
82
      dst->symbol.value = 0;
4811
82
      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
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
3.69k
#ifdef COFF_WITH_PE
4840
3.69k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
804
    dst->symbol.flags |= BSF_WEAK;
4842
4843
3.69k
        if (src->u.syment.n_sclass == C_SECTION
4844
3.69k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
3.69k
#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
90
    dst->symbol.flags |= BSF_WEAK;
4853
4854
3.69k
        break;
4855
4856
1.16k
      case C_STAT:  /* Static.  */
4857
1.16k
#if defined ARM
4858
1.25k
      case C_THUMBSTAT:    /* Thumb static.  */
4859
1.29k
      case C_THUMBLABEL:   /* Thumb label.  */
4860
1.38k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4861
1.38k
#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
1.62k
      case C_LABEL:  /* Label.  */
4867
1.62k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
8
    dst->symbol.flags = BSF_DEBUGGING;
4869
1.61k
        else
4870
1.61k
    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
1.62k
        if (dst->symbol.section)
4875
1.62k
    {
4876
1.62k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
1.62k
      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
1.62k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
1.62k
        break;
4888
4889
545
      case C_FILE: /* File name.  */
4890
545
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.09k
      case C_MOS:   /* Member of structure.  */
4893
1.34k
      case C_EOS:   /* End of structure.  */
4894
1.48k
      case C_REGPARM: /* Register parameter.  */
4895
1.77k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
1.95k
      case C_TPDEF: /* Type definition.  */
4898
2.34k
      case C_ARG:
4899
13.0k
      case C_AUTO: /* Automatic variable.  */
4900
13.2k
      case C_FIELD: /* Bit field.  */
4901
13.5k
      case C_ENTAG: /* Enumeration tag.  */
4902
14.0k
      case C_MOE:   /* Member of enumeration.  */
4903
14.7k
      case C_MOU:   /* Member of union.  */
4904
15.1k
      case C_UNTAG: /* Union tag.  */
4905
15.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
15.8k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
15.8k
        dst->symbol.value = (src->u.syment.n_value);
4924
15.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
189
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.46k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
2.01k
      case C_EFCN: /* Physical end of function.  */
4977
2.01k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
2.01k
        dst->symbol.value = src->u.syment.n_value;
4981
2.01k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
2.01k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
2.01k
      dst->symbol.flags = BSF_DEBUGGING;
4986
2.01k
    }
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
2.01k
        break;
4997
4998
94
      case C_STATLAB: /* Static load time label.  */
4999
94
        dst->symbol.value = src->u.syment.n_value;
5000
94
        dst->symbol.flags = BSF_GLOBAL;
5001
94
        break;
5002
5003
84.9k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
84.9k
        if (src->u.syment.n_type == 0
5007
84.9k
      && src->u.syment.n_value == 0
5008
84.9k
      && src->u.syment.n_scnum == 0)
5009
22.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
62.9k
      case C_EXTDEF: /* External definition.  */
5017
63.1k
      case C_ULABEL: /* Undefined label.  */
5018
63.2k
      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
63.3k
      case C_EXTLAB: /* External load time label.  */
5031
82.4k
      default:
5032
82.4k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
82.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
82.4k
     abfd, src->u.syment.n_sclass,
5036
82.4k
     dst->symbol.section->name, dst->symbol.name);
5037
82.4k
        ret = false;
5038
        /* Fall through.  */
5039
82.4k
      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
82.4k
        dst->symbol.flags = BSF_DEBUGGING;
5043
82.4k
        dst->symbol.value = (src->u.syment.n_value);
5044
82.4k
        break;
5045
127k
      }
5046
5047
127k
    dst->native = src;
5048
127k
    dst->symbol.udata.i = 0;
5049
127k
    dst->lineno = NULL;
5050
5051
127k
    this_index += (src->u.syment.n_numaux) + 1;
5052
127k
    dst++;
5053
127k
    number_of_symbols++;
5054
127k
  }
5055
437
    }
5056
5057
437
  obj_symbols (abfd) = cached_area;
5058
437
  obj_raw_syments (abfd) = native_symbols;
5059
5060
437
  abfd->symcount = number_of_symbols;
5061
437
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
437
  {
5064
437
    asection *p;
5065
5066
437
    p = abfd->sections;
5067
1.18k
    while (p)
5068
1.13k
      {
5069
1.13k
  if (! coff_slurp_line_table (abfd, p))
5070
383
    return false;
5071
748
  p = p->next;
5072
748
      }
5073
437
  }
5074
5075
54
  return ret;
5076
437
}
pei-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4704
434
{
4705
434
  combined_entry_type *native_symbols;
4706
434
  coff_symbol_type *cached_area;
4707
434
  unsigned int *table_ptr;
4708
434
  unsigned int number_of_symbols = 0;
4709
434
  bool ret = true;
4710
434
  size_t amt;
4711
4712
434
  if (obj_symbols (abfd))
4713
20
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
414
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
65
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
349
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
349
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
349
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
349
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
349
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
349
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
349
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
349
  if (table_ptr == NULL)
4738
0
    return false;
4739
349
  else
4740
349
    {
4741
349
      coff_symbol_type *dst = cached_area;
4742
349
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
349
      unsigned int this_index = 0;
4744
4745
63.7k
      while (this_index < last_native_index)
4746
63.4k
  {
4747
63.4k
    combined_entry_type *src = native_symbols + this_index;
4748
63.4k
    table_ptr[this_index] = number_of_symbols;
4749
4750
63.4k
    dst->symbol.the_bfd = abfd;
4751
63.4k
    BFD_ASSERT (src->is_sym);
4752
63.4k
    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
63.4k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
63.4k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
63.4k
                 src->u.syment.n_scnum);
4757
63.4k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
63.4k
    dst->symbol.value = 0;
4760
63.4k
    dst->done_lineno = false;
4761
4762
63.4k
    switch (src->u.syment.n_sclass)
4763
63.4k
      {
4764
948
      case C_EXT:
4765
1.16k
      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.16k
#ifdef C_SYSTEM
4777
1.37k
      case C_SYSTEM: /* System Wide variable.  */
4778
1.37k
#endif
4779
1.37k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
1.42k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
2.40k
      case C_NT_WEAK:
4784
2.40k
#endif
4785
2.40k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
2.40k
    {
4787
2.06k
    case COFF_SYMBOL_GLOBAL:
4788
2.06k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
2.06k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
2.06k
      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.06k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
56
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
2.06k
      break;
4802
4803
217
    case COFF_SYMBOL_COMMON:
4804
217
      dst->symbol.section = bfd_com_section_ptr;
4805
217
      dst->symbol.value = src->u.syment.n_value;
4806
217
      break;
4807
4808
121
    case COFF_SYMBOL_UNDEFINED:
4809
121
      dst->symbol.section = bfd_und_section_ptr;
4810
121
      dst->symbol.value = 0;
4811
121
      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.40k
    }
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.40k
#ifdef COFF_WITH_PE
4840
2.40k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
981
    dst->symbol.flags |= BSF_WEAK;
4842
4843
2.40k
        if (src->u.syment.n_sclass == C_SECTION
4844
2.40k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
2.40k
#endif
4847
2.40k
        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.40k
      )
4852
214
    dst->symbol.flags |= BSF_WEAK;
4853
4854
2.40k
        break;
4855
4856
1.41k
      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.38k
      case C_LABEL:  /* Label.  */
4867
2.38k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
3
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.37k
        else
4870
2.37k
    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.38k
        if (dst->symbol.section)
4875
2.38k
    {
4876
2.38k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.38k
      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.38k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.38k
        break;
4888
4889
502
      case C_FILE: /* File name.  */
4890
502
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
1.11k
      case C_MOS:   /* Member of structure.  */
4893
1.32k
      case C_EOS:   /* End of structure.  */
4894
1.63k
      case C_REGPARM: /* Register parameter.  */
4895
1.87k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
2.10k
      case C_TPDEF: /* Type definition.  */
4898
2.38k
      case C_ARG:
4899
4.32k
      case C_AUTO: /* Automatic variable.  */
4900
4.61k
      case C_FIELD: /* Bit field.  */
4901
4.76k
      case C_ENTAG: /* Enumeration tag.  */
4902
5.19k
      case C_MOE:   /* Member of enumeration.  */
4903
5.40k
      case C_MOU:   /* Member of union.  */
4904
5.76k
      case C_UNTAG: /* Union tag.  */
4905
6.16k
      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
6.16k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
6.16k
        dst->symbol.value = (src->u.syment.n_value);
4924
6.16k
        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
126
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
1.26k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
1.54k
      case C_EFCN: /* Physical end of function.  */
4977
1.54k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
1.54k
        dst->symbol.value = src->u.syment.n_value;
4981
1.54k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
1.54k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
1.54k
      dst->symbol.flags = BSF_DEBUGGING;
4986
1.54k
    }
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
1.54k
        break;
4997
4998
154
      case C_STATLAB: /* Static load time label.  */
4999
154
        dst->symbol.value = src->u.syment.n_value;
5000
154
        dst->symbol.flags = BSF_GLOBAL;
5001
154
        break;
5002
5003
36.8k
      case C_NULL:
5004
        /* PE DLLs sometimes have zeroed out symbols for some
5005
     reason.  Just ignore them without a warning.  */
5006
36.8k
        if (src->u.syment.n_type == 0
5007
36.8k
      && src->u.syment.n_value == 0
5008
36.8k
      && src->u.syment.n_scnum == 0)
5009
8.71k
    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
28.1k
      case C_EXTDEF: /* External definition.  */
5017
28.3k
      case C_ULABEL: /* Undefined label.  */
5018
28.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
28.4k
      case C_EXTLAB: /* External load time label.  */
5031
42.0k
      default:
5032
42.0k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
42.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
42.0k
     abfd, src->u.syment.n_sclass,
5036
42.0k
     dst->symbol.section->name, dst->symbol.name);
5037
42.0k
        ret = false;
5038
        /* Fall through.  */
5039
42.0k
      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
42.0k
        dst->symbol.flags = BSF_DEBUGGING;
5043
42.0k
        dst->symbol.value = (src->u.syment.n_value);
5044
42.0k
        break;
5045
63.4k
      }
5046
5047
63.4k
    dst->native = src;
5048
63.4k
    dst->symbol.udata.i = 0;
5049
63.4k
    dst->lineno = NULL;
5050
5051
63.4k
    this_index += (src->u.syment.n_numaux) + 1;
5052
63.4k
    dst++;
5053
63.4k
    number_of_symbols++;
5054
63.4k
  }
5055
349
    }
5056
5057
349
  obj_symbols (abfd) = cached_area;
5058
349
  obj_raw_syments (abfd) = native_symbols;
5059
5060
349
  abfd->symcount = number_of_symbols;
5061
349
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
349
  {
5064
349
    asection *p;
5065
5066
349
    p = abfd->sections;
5067
533
    while (p)
5068
441
      {
5069
441
  if (! coff_slurp_line_table (abfd, p))
5070
257
    return false;
5071
184
  p = p->next;
5072
184
      }
5073
349
  }
5074
5075
92
  return ret;
5076
349
}
pei-sh.c:coff_slurp_symbol_table
Line
Count
Source
4704
590
{
4705
590
  combined_entry_type *native_symbols;
4706
590
  coff_symbol_type *cached_area;
4707
590
  unsigned int *table_ptr;
4708
590
  unsigned int number_of_symbols = 0;
4709
590
  bool ret = true;
4710
590
  size_t amt;
4711
4712
590
  if (obj_symbols (abfd))
4713
108
    return true;
4714
4715
  /* Read in the symbol table.  */
4716
482
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4717
88
    return false;
4718
4719
  /* Allocate enough room for all the symbols in cached form.  */
4720
394
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4721
394
       sizeof (*cached_area), &amt))
4722
0
    {
4723
0
      bfd_set_error (bfd_error_file_too_big);
4724
0
      return false;
4725
0
    }
4726
394
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4727
394
  if (cached_area == NULL)
4728
0
    return false;
4729
4730
394
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4731
394
       sizeof (*table_ptr), &amt))
4732
0
    {
4733
0
      bfd_set_error (bfd_error_file_too_big);
4734
0
      return false;
4735
0
    }
4736
394
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4737
394
  if (table_ptr == NULL)
4738
0
    return false;
4739
394
  else
4740
394
    {
4741
394
      coff_symbol_type *dst = cached_area;
4742
394
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4743
394
      unsigned int this_index = 0;
4744
4745
187k
      while (this_index < last_native_index)
4746
186k
  {
4747
186k
    combined_entry_type *src = native_symbols + this_index;
4748
186k
    table_ptr[this_index] = number_of_symbols;
4749
4750
186k
    dst->symbol.the_bfd = abfd;
4751
186k
    BFD_ASSERT (src->is_sym);
4752
186k
    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
186k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4755
186k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4756
186k
                 src->u.syment.n_scnum);
4757
186k
    dst->symbol.flags = 0;
4758
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4759
186k
    dst->symbol.value = 0;
4760
186k
    dst->done_lineno = false;
4761
4762
186k
    switch (src->u.syment.n_sclass)
4763
186k
      {
4764
3.14k
      case C_EXT:
4765
3.44k
      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.44k
#ifdef C_SYSTEM
4777
3.77k
      case C_SYSTEM: /* System Wide variable.  */
4778
3.77k
#endif
4779
3.77k
#ifdef COFF_WITH_PE
4780
      /* In PE, 0x68 (104) denotes a section symbol.  */
4781
3.82k
      case C_SECTION:
4782
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4783
5.24k
      case C_NT_WEAK:
4784
5.24k
#endif
4785
5.24k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4786
5.24k
    {
4787
4.64k
    case COFF_SYMBOL_GLOBAL:
4788
4.64k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4789
4.64k
#if defined COFF_WITH_PE
4790
      /* PE sets the symbol to a value relative to the
4791
         start of the section.  */
4792
4.64k
      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.64k
      if (ISFCN ((src->u.syment.n_type)))
4798
        /* A function ext does not go at the end of a
4799
           file.  */
4800
214
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4801
4.64k
      break;
4802
4803
368
    case COFF_SYMBOL_COMMON:
4804
368
      dst->symbol.section = bfd_com_section_ptr;
4805
368
      dst->symbol.value = src->u.syment.n_value;
4806
368
      break;
4807
4808
233
    case COFF_SYMBOL_UNDEFINED:
4809
233
      dst->symbol.section = bfd_und_section_ptr;
4810
233
      dst->symbol.value = 0;
4811
233
      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
5.24k
    }
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
5.24k
#ifdef COFF_WITH_PE
4840
5.24k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4841
1.42k
    dst->symbol.flags |= BSF_WEAK;
4842
4843
5.24k
        if (src->u.syment.n_sclass == C_SECTION
4844
5.24k
      && src->u.syment.n_scnum > 0)
4845
0
    dst->symbol.flags = BSF_LOCAL;
4846
5.24k
#endif
4847
5.24k
        if (src->u.syment.n_sclass == C_WEAKEXT
4848
#ifdef RS6000COFF_C
4849
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4850
#endif
4851
5.24k
      )
4852
294
    dst->symbol.flags |= BSF_WEAK;
4853
4854
5.24k
        break;
4855
4856
1.79k
      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.13k
      case C_LABEL:  /* Label.  */
4867
2.13k
        if (src->u.syment.n_scnum == N_DEBUG)
4868
0
    dst->symbol.flags = BSF_DEBUGGING;
4869
2.13k
        else
4870
2.13k
    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.13k
        if (dst->symbol.section)
4875
2.13k
    {
4876
2.13k
#if defined COFF_WITH_PE
4877
      /* PE sets the symbol to a value relative to the
4878
         start of the section.  */
4879
2.13k
      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.13k
    }
4885
0
        else
4886
0
    dst->symbol.value = src->u.syment.n_value;
4887
2.13k
        break;
4888
4889
1.21k
      case C_FILE: /* File name.  */
4890
1.21k
        dst->symbol.flags = BSF_FILE;
4891
        /* Fall through.  */
4892
3.11k
      case C_MOS:   /* Member of structure.  */
4893
3.47k
      case C_EOS:   /* End of structure.  */
4894
3.91k
      case C_REGPARM: /* Register parameter.  */
4895
4.66k
      case C_REG:   /* register variable.  */
4896
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4897
5.08k
      case C_TPDEF: /* Type definition.  */
4898
6.30k
      case C_ARG:
4899
10.9k
      case C_AUTO: /* Automatic variable.  */
4900
12.1k
      case C_FIELD: /* Bit field.  */
4901
12.5k
      case C_ENTAG: /* Enumeration tag.  */
4902
14.6k
      case C_MOE:   /* Member of enumeration.  */
4903
15.7k
      case C_MOU:   /* Member of union.  */
4904
16.2k
      case C_UNTAG: /* Union tag.  */
4905
17.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
17.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4923
17.4k
        dst->symbol.value = (src->u.syment.n_value);
4924
17.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
553
      case C_BLOCK: /* ".bb" or ".eb".  */
4975
2.47k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4976
3.38k
      case C_EFCN: /* Physical end of function.  */
4977
3.38k
#if defined COFF_WITH_PE
4978
        /* PE sets the symbol to a value relative to the start
4979
     of the section.  */
4980
3.38k
        dst->symbol.value = src->u.syment.n_value;
4981
3.38k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4982
3.38k
    {
4983
      /* PE uses funny values for .ef and .lf; don't
4984
         relocate them.  */
4985
3.38k
      dst->symbol.flags = BSF_DEBUGGING;
4986
3.38k
    }
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.38k
        break;
4997
4998
295
      case C_STATLAB: /* Static load time label.  */
4999
295
        dst->symbol.value = src->u.syment.n_value;
5000
295
        dst->symbol.flags = BSF_GLOBAL;
5001
295
        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
70.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
60.8k
      case C_EXTDEF: /* External definition.  */
5017
61.3k
      case C_ULABEL: /* Undefined label.  */
5018
61.5k
      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
61.6k
      case C_EXTLAB: /* External load time label.  */
5031
87.6k
      default:
5032
87.6k
        _bfd_error_handler
5033
    /* xgettext:c-format */
5034
87.6k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5035
87.6k
     abfd, src->u.syment.n_sclass,
5036
87.6k
     dst->symbol.section->name, dst->symbol.name);
5037
87.6k
        ret = false;
5038
        /* Fall through.  */
5039
87.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
87.7k
        dst->symbol.flags = BSF_DEBUGGING;
5043
87.7k
        dst->symbol.value = (src->u.syment.n_value);
5044
87.7k
        break;
5045
186k
      }
5046
5047
186k
    dst->native = src;
5048
186k
    dst->symbol.udata.i = 0;
5049
186k
    dst->lineno = NULL;
5050
5051
186k
    this_index += (src->u.syment.n_numaux) + 1;
5052
186k
    dst++;
5053
186k
    number_of_symbols++;
5054
186k
  }
5055
394
    }
5056
5057
394
  obj_symbols (abfd) = cached_area;
5058
394
  obj_raw_syments (abfd) = native_symbols;
5059
5060
394
  abfd->symcount = number_of_symbols;
5061
394
  obj_convert (abfd) = table_ptr;
5062
  /* Slurp the line tables for each section too.  */
5063
394
  {
5064
394
    asection *p;
5065
5066
394
    p = abfd->sections;
5067
984
    while (p)
5068
881
      {
5069
881
  if (! coff_slurp_line_table (abfd, p))
5070
291
    return false;
5071
590
  p = p->next;
5072
590
      }
5073
394
  }
5074
5075
103
  return ret;
5076
394
}
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
122k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
122k
  switch (syment->n_sclass)
5089
122k
    {
5090
77.2k
    case C_EXT:
5091
80.9k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
3.61k
    case C_THUMBEXT:
5094
3.67k
    case C_THUMBEXTFUNC:
5095
#endif
5096
#ifdef RS6000COFF_C
5097
18.8k
    case C_HIDEXT:
5098
18.8k
#ifndef AIX_WEAK_SUPPORT
5099
20.5k
    case C_AIX_WEAKEXT:
5100
#endif
5101
#endif
5102
20.5k
#ifdef C_SYSTEM
5103
93.3k
    case C_SYSTEM:
5104
93.3k
#endif
5105
#ifdef COFF_WITH_PE
5106
78.1k
    case C_NT_WEAK:
5107
#endif
5108
114k
      if (syment->n_scnum == 0)
5109
12.7k
  {
5110
12.7k
    if (syment->n_value == 0)
5111
4.11k
      return COFF_SYMBOL_UNDEFINED;
5112
8.66k
    else
5113
8.66k
      return COFF_SYMBOL_COMMON;
5114
12.7k
  }
5115
#ifdef RS6000COFF_C
5116
21.5k
      if (syment->n_sclass == C_HIDEXT)
5117
776
  return COFF_SYMBOL_LOCAL;
5118
20.8k
#endif
5119
101k
      return COFF_SYMBOL_GLOBAL;
5120
5121
7.40k
    default:
5122
7.40k
      break;
5123
122k
    }
5124
5125
#ifdef COFF_WITH_PE
5126
7.40k
  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
7.12k
  if (syment->n_sclass == C_SECTION)
5156
1.26k
    {
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
1.26k
      syment->n_value = 0;
5161
1.26k
      if (syment->n_scnum == 0)
5162
944
  return COFF_SYMBOL_UNDEFINED;
5163
320
      return COFF_SYMBOL_PE_SECTION;
5164
1.26k
    }
5165
5.86k
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
5.86k
  if (syment->n_scnum == 0)
5169
5.83k
    {
5170
5.83k
      char buf[SYMNMLEN + 1];
5171
5172
5.83k
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
5.83k
  (_("warning: %pB: local symbol `%s' has no section"),
5175
5.83k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
5.83k
    }
5177
5178
5.86k
  return COFF_SYMBOL_LOCAL;
5179
7.12k
}
pei-i386.c:coff_classify_symbol
Line
Count
Source
5085
1.46k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
1.46k
  switch (syment->n_sclass)
5089
1.46k
    {
5090
753
    case C_EXT:
5091
805
    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
805
#ifdef C_SYSTEM
5103
902
    case C_SYSTEM:
5104
902
#endif
5105
902
#ifdef COFF_WITH_PE
5106
1.44k
    case C_NT_WEAK:
5107
1.44k
#endif
5108
1.44k
      if (syment->n_scnum == 0)
5109
194
  {
5110
194
    if (syment->n_value == 0)
5111
67
      return COFF_SYMBOL_UNDEFINED;
5112
127
    else
5113
127
      return COFF_SYMBOL_COMMON;
5114
194
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
1.25k
      return COFF_SYMBOL_GLOBAL;
5120
5121
20
    default:
5122
20
      break;
5123
1.46k
    }
5124
5125
20
#ifdef COFF_WITH_PE
5126
20
  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
20
  if (syment->n_sclass == C_SECTION)
5156
18
    {
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
18
      syment->n_value = 0;
5161
18
      if (syment->n_scnum == 0)
5162
18
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
18
    }
5165
2
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
2
  if (syment->n_scnum == 0)
5169
1
    {
5170
1
      char buf[SYMNMLEN + 1];
5171
5172
1
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
1
  (_("warning: %pB: local symbol `%s' has no section"),
5175
1
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
1
    }
5177
5178
2
  return COFF_SYMBOL_LOCAL;
5179
20
}
pe-x86_64.c:coff_classify_symbol
Line
Count
Source
5085
3.39k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.39k
  switch (syment->n_sclass)
5089
3.39k
    {
5090
1.43k
    case C_EXT:
5091
1.53k
    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.53k
#ifdef C_SYSTEM
5103
1.77k
    case C_SYSTEM:
5104
1.77k
#endif
5105
1.77k
#ifdef COFF_WITH_PE
5106
2.98k
    case C_NT_WEAK:
5107
2.98k
#endif
5108
2.98k
      if (syment->n_scnum == 0)
5109
430
  {
5110
430
    if (syment->n_value == 0)
5111
101
      return COFF_SYMBOL_UNDEFINED;
5112
329
    else
5113
329
      return COFF_SYMBOL_COMMON;
5114
430
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.55k
      return COFF_SYMBOL_GLOBAL;
5120
5121
410
    default:
5122
410
      break;
5123
3.39k
    }
5124
5125
410
#ifdef COFF_WITH_PE
5126
410
  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
410
  if (syment->n_sclass == C_SECTION)
5156
410
    {
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
410
      syment->n_value = 0;
5161
410
      if (syment->n_scnum == 0)
5162
90
  return COFF_SYMBOL_UNDEFINED;
5163
320
      return COFF_SYMBOL_PE_SECTION;
5164
410
    }
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
410
}
pei-x86_64.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
10.7k
    case C_EXT:
5091
10.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
10.7k
#ifdef C_SYSTEM
5103
10.9k
    case C_SYSTEM:
5104
10.9k
#endif
5105
10.9k
#ifdef COFF_WITH_PE
5106
11.5k
    case C_NT_WEAK:
5107
11.5k
#endif
5108
11.5k
      if (syment->n_scnum == 0)
5109
1.73k
  {
5110
1.73k
    if (syment->n_value == 0)
5111
1.52k
      return COFF_SYMBOL_UNDEFINED;
5112
214
    else
5113
214
      return COFF_SYMBOL_COMMON;
5114
1.73k
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
9.82k
      return COFF_SYMBOL_GLOBAL;
5120
5121
321
    default:
5122
321
      break;
5123
11.8k
    }
5124
5125
321
#ifdef COFF_WITH_PE
5126
321
  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
44
  if (syment->n_sclass == C_SECTION)
5156
16
    {
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
16
      syment->n_value = 0;
5161
16
      if (syment->n_scnum == 0)
5162
16
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
16
    }
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
44
}
coff-x86_64.c:coff_classify_symbol
Line
Count
Source
5085
2.34k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.34k
  switch (syment->n_sclass)
5089
2.34k
    {
5090
2.07k
    case C_EXT:
5091
2.19k
    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.19k
#ifdef C_SYSTEM
5103
2.34k
    case C_SYSTEM:
5104
2.34k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
2.34k
      if (syment->n_scnum == 0)
5109
467
  {
5110
467
    if (syment->n_value == 0)
5111
102
      return COFF_SYMBOL_UNDEFINED;
5112
365
    else
5113
365
      return COFF_SYMBOL_COMMON;
5114
467
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
1.87k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
2.34k
    }
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
2.34k
}
coff64-rs6000.c:coff_classify_symbol
Line
Count
Source
5085
2.71k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.71k
  switch (syment->n_sclass)
5089
2.71k
    {
5090
1.11k
    case C_EXT:
5091
1.21k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
1.21k
#ifdef RS6000COFF_C
5097
1.45k
    case C_HIDEXT:
5098
1.45k
#ifndef AIX_WEAK_SUPPORT
5099
2.33k
    case C_AIX_WEAKEXT:
5100
2.33k
#endif
5101
2.33k
#endif
5102
2.33k
#ifdef C_SYSTEM
5103
2.71k
    case C_SYSTEM:
5104
2.71k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
2.71k
      if (syment->n_scnum == 0)
5109
420
  {
5110
420
    if (syment->n_value == 0)
5111
274
      return COFF_SYMBOL_UNDEFINED;
5112
146
    else
5113
146
      return COFF_SYMBOL_COMMON;
5114
420
  }
5115
2.29k
#ifdef RS6000COFF_C
5116
2.29k
      if (syment->n_sclass == C_HIDEXT)
5117
228
  return COFF_SYMBOL_LOCAL;
5118
2.06k
#endif
5119
2.06k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
2.71k
    }
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
2.71k
}
pe-aarch64.c:coff_classify_symbol
Line
Count
Source
5085
10.1k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
10.1k
  switch (syment->n_sclass)
5089
10.1k
    {
5090
7.69k
    case C_EXT:
5091
7.85k
    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.85k
#ifdef C_SYSTEM
5103
8.29k
    case C_SYSTEM:
5104
8.29k
#endif
5105
8.29k
#ifdef COFF_WITH_PE
5106
10.0k
    case C_NT_WEAK:
5107
10.0k
#endif
5108
10.0k
      if (syment->n_scnum == 0)
5109
778
  {
5110
778
    if (syment->n_value == 0)
5111
170
      return COFF_SYMBOL_UNDEFINED;
5112
608
    else
5113
608
      return COFF_SYMBOL_COMMON;
5114
778
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
9.29k
      return COFF_SYMBOL_GLOBAL;
5120
5121
122
    default:
5122
122
      break;
5123
10.1k
    }
5124
5125
122
#ifdef COFF_WITH_PE
5126
122
  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
122
  if (syment->n_sclass == C_SECTION)
5156
122
    {
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
122
      syment->n_value = 0;
5161
122
      if (syment->n_scnum == 0)
5162
122
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
122
    }
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
122
}
pei-aarch64.c:coff_classify_symbol
Line
Count
Source
5085
3.26k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.26k
  switch (syment->n_sclass)
5089
3.26k
    {
5090
1.04k
    case C_EXT:
5091
1.13k
    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.13k
#ifdef C_SYSTEM
5103
1.75k
    case C_SYSTEM:
5104
1.75k
#endif
5105
1.75k
#ifdef COFF_WITH_PE
5106
3.22k
    case C_NT_WEAK:
5107
3.22k
#endif
5108
3.22k
      if (syment->n_scnum == 0)
5109
382
  {
5110
382
    if (syment->n_value == 0)
5111
119
      return COFF_SYMBOL_UNDEFINED;
5112
263
    else
5113
263
      return COFF_SYMBOL_COMMON;
5114
382
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.83k
      return COFF_SYMBOL_GLOBAL;
5120
5121
41
    default:
5122
41
      break;
5123
3.26k
    }
5124
5125
41
#ifdef COFF_WITH_PE
5126
41
  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
41
  if (syment->n_sclass == C_SECTION)
5156
41
    {
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
41
      syment->n_value = 0;
5161
41
      if (syment->n_scnum == 0)
5162
41
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
41
    }
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
41
}
pei-ia64.c:coff_classify_symbol
Line
Count
Source
5085
7.85k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
7.85k
  switch (syment->n_sclass)
5089
7.85k
    {
5090
4.87k
    case C_EXT:
5091
5.00k
    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.00k
#ifdef C_SYSTEM
5103
5.45k
    case C_SYSTEM:
5104
5.45k
#endif
5105
5.45k
#ifdef COFF_WITH_PE
5106
7.63k
    case C_NT_WEAK:
5107
7.63k
#endif
5108
7.63k
      if (syment->n_scnum == 0)
5109
583
  {
5110
583
    if (syment->n_value == 0)
5111
208
      return COFF_SYMBOL_UNDEFINED;
5112
375
    else
5113
375
      return COFF_SYMBOL_COMMON;
5114
583
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
7.05k
      return COFF_SYMBOL_GLOBAL;
5120
5121
214
    default:
5122
214
      break;
5123
7.85k
    }
5124
5125
214
#ifdef COFF_WITH_PE
5126
214
  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
214
  if (syment->n_sclass == C_SECTION)
5156
214
    {
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
214
      syment->n_value = 0;
5161
214
      if (syment->n_scnum == 0)
5162
214
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
214
    }
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
214
}
pei-loongarch64.c:coff_classify_symbol
Line
Count
Source
5085
3.86k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.86k
  switch (syment->n_sclass)
5089
3.86k
    {
5090
1.13k
    case C_EXT:
5091
1.28k
    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.28k
#ifdef C_SYSTEM
5103
1.53k
    case C_SYSTEM:
5104
1.53k
#endif
5105
1.53k
#ifdef COFF_WITH_PE
5106
3.74k
    case C_NT_WEAK:
5107
3.74k
#endif
5108
3.74k
      if (syment->n_scnum == 0)
5109
329
  {
5110
329
    if (syment->n_value == 0)
5111
111
      return COFF_SYMBOL_UNDEFINED;
5112
218
    else
5113
218
      return COFF_SYMBOL_COMMON;
5114
329
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
3.41k
      return COFF_SYMBOL_GLOBAL;
5120
5121
120
    default:
5122
120
      break;
5123
3.86k
    }
5124
5125
120
#ifdef COFF_WITH_PE
5126
120
  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
120
  if (syment->n_sclass == C_SECTION)
5156
120
    {
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
120
      syment->n_value = 0;
5161
120
      if (syment->n_scnum == 0)
5162
120
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
120
    }
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
120
}
pei-riscv64.c:coff_classify_symbol
Line
Count
Source
5085
9.73k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
9.73k
  switch (syment->n_sclass)
5089
9.73k
    {
5090
1.63k
    case C_EXT:
5091
1.80k
    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.80k
#ifdef C_SYSTEM
5103
2.11k
    case C_SYSTEM:
5104
2.11k
#endif
5105
2.11k
#ifdef COFF_WITH_PE
5106
3.85k
    case C_NT_WEAK:
5107
3.85k
#endif
5108
3.85k
      if (syment->n_scnum == 0)
5109
531
  {
5110
531
    if (syment->n_value == 0)
5111
72
      return COFF_SYMBOL_UNDEFINED;
5112
459
    else
5113
459
      return COFF_SYMBOL_COMMON;
5114
531
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
3.32k
      return COFF_SYMBOL_GLOBAL;
5120
5121
5.88k
    default:
5122
5.88k
      break;
5123
9.73k
    }
5124
5125
5.88k
#ifdef COFF_WITH_PE
5126
5.88k
  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
5.88k
  if (syment->n_sclass == C_SECTION)
5156
51
    {
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
51
      syment->n_value = 0;
5161
51
      if (syment->n_scnum == 0)
5162
51
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
51
    }
5165
5.83k
#endif /* COFF_WITH_PE */
5166
5167
  /* If it is not a global symbol, we presume it is a local symbol.  */
5168
5.83k
  if (syment->n_scnum == 0)
5169
5.83k
    {
5170
5.83k
      char buf[SYMNMLEN + 1];
5171
5172
5.83k
      _bfd_error_handler
5173
  /* xgettext:c-format */
5174
5.83k
  (_("warning: %pB: local symbol `%s' has no section"),
5175
5.83k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5176
5.83k
    }
5177
5178
5.83k
  return COFF_SYMBOL_LOCAL;
5179
5.88k
}
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
19.4k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
19.4k
  switch (syment->n_sclass)
5089
19.4k
    {
5090
16.4k
    case C_EXT:
5091
16.8k
    case C_WEAKEXT:
5092
#ifdef ARM
5093
    case C_THUMBEXT:
5094
    case C_THUMBEXTFUNC:
5095
#endif
5096
16.8k
#ifdef RS6000COFF_C
5097
17.3k
    case C_HIDEXT:
5098
17.3k
#ifndef AIX_WEAK_SUPPORT
5099
18.2k
    case C_AIX_WEAKEXT:
5100
18.2k
#endif
5101
18.2k
#endif
5102
18.2k
#ifdef C_SYSTEM
5103
19.4k
    case C_SYSTEM:
5104
19.4k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
19.4k
      if (syment->n_scnum == 0)
5109
125
  {
5110
125
    if (syment->n_value == 0)
5111
39
      return COFF_SYMBOL_UNDEFINED;
5112
86
    else
5113
86
      return COFF_SYMBOL_COMMON;
5114
125
  }
5115
19.2k
#ifdef RS6000COFF_C
5116
19.2k
      if (syment->n_sclass == C_HIDEXT)
5117
548
  return COFF_SYMBOL_LOCAL;
5118
18.7k
#endif
5119
18.7k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
19.4k
    }
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
19.4k
}
coff-sh.c:coff_classify_symbol
Line
Count
Source
5085
3.29k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.29k
  switch (syment->n_sclass)
5089
3.29k
    {
5090
2.89k
    case C_EXT:
5091
3.07k
    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.07k
#ifdef C_SYSTEM
5103
3.29k
    case C_SYSTEM:
5104
3.29k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
3.29k
      if (syment->n_scnum == 0)
5109
770
  {
5110
770
    if (syment->n_value == 0)
5111
43
      return COFF_SYMBOL_UNDEFINED;
5112
727
    else
5113
727
      return COFF_SYMBOL_COMMON;
5114
770
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.52k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
3.29k
    }
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.29k
}
Unexecuted instantiation: coff-stgo32.c:coff_classify_symbol
coff-tic30.c:coff_classify_symbol
Line
Count
Source
5085
1.90k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
1.90k
  switch (syment->n_sclass)
5089
1.90k
    {
5090
1.60k
    case C_EXT:
5091
1.76k
    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.76k
#ifdef C_SYSTEM
5103
1.90k
    case C_SYSTEM:
5104
1.90k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
1.90k
      if (syment->n_scnum == 0)
5109
269
  {
5110
269
    if (syment->n_value == 0)
5111
96
      return COFF_SYMBOL_UNDEFINED;
5112
173
    else
5113
173
      return COFF_SYMBOL_COMMON;
5114
269
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
1.63k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
1.90k
    }
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
1.90k
}
Unexecuted instantiation: coff-tic4x.c:coff_classify_symbol
coff-tic54x.c:coff_classify_symbol
Line
Count
Source
5085
2.84k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.84k
  switch (syment->n_sclass)
5089
2.84k
    {
5090
2.41k
    case C_EXT:
5091
2.56k
    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.56k
#ifdef C_SYSTEM
5103
2.84k
    case C_SYSTEM:
5104
2.84k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
2.84k
      if (syment->n_scnum == 0)
5109
713
  {
5110
713
    if (syment->n_value == 0)
5111
120
      return COFF_SYMBOL_UNDEFINED;
5112
593
    else
5113
593
      return COFF_SYMBOL_COMMON;
5114
713
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.12k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
2.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
2.84k
}
coff-z80.c:coff_classify_symbol
Line
Count
Source
5085
1.86k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
1.86k
  switch (syment->n_sclass)
5089
1.86k
    {
5090
1.60k
    case C_EXT:
5091
1.74k
    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.74k
#ifdef C_SYSTEM
5103
1.86k
    case C_SYSTEM:
5104
1.86k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
1.86k
      if (syment->n_scnum == 0)
5109
501
  {
5110
501
    if (syment->n_value == 0)
5111
90
      return COFF_SYMBOL_UNDEFINED;
5112
411
    else
5113
411
      return COFF_SYMBOL_COMMON;
5114
501
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
1.36k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
1.86k
    }
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
1.86k
}
coff-z8k.c:coff_classify_symbol
Line
Count
Source
5085
2.50k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.50k
  switch (syment->n_sclass)
5089
2.50k
    {
5090
1.79k
    case C_EXT:
5091
2.10k
    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.10k
#ifdef C_SYSTEM
5103
2.50k
    case C_SYSTEM:
5104
2.50k
#endif
5105
#ifdef COFF_WITH_PE
5106
    case C_NT_WEAK:
5107
#endif
5108
2.50k
      if (syment->n_scnum == 0)
5109
450
  {
5110
450
    if (syment->n_value == 0)
5111
133
      return COFF_SYMBOL_UNDEFINED;
5112
317
    else
5113
317
      return COFF_SYMBOL_COMMON;
5114
450
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.05k
      return COFF_SYMBOL_GLOBAL;
5120
5121
0
    default:
5122
0
      break;
5123
2.50k
    }
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
2.50k
}
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
8.59k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
8.59k
  switch (syment->n_sclass)
5089
8.59k
    {
5090
4.08k
    case C_EXT:
5091
4.19k
    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.19k
#ifdef C_SYSTEM
5103
6.20k
    case C_SYSTEM:
5104
6.20k
#endif
5105
6.20k
#ifdef COFF_WITH_PE
5106
8.57k
    case C_NT_WEAK:
5107
8.57k
#endif
5108
8.57k
      if (syment->n_scnum == 0)
5109
766
  {
5110
766
    if (syment->n_value == 0)
5111
164
      return COFF_SYMBOL_UNDEFINED;
5112
602
    else
5113
602
      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
7.80k
      return COFF_SYMBOL_GLOBAL;
5120
5121
23
    default:
5122
23
      break;
5123
8.59k
    }
5124
5125
23
#ifdef COFF_WITH_PE
5126
23
  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
23
  if (syment->n_sclass == C_SECTION)
5156
23
    {
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
23
      syment->n_value = 0;
5161
23
      if (syment->n_scnum == 0)
5162
23
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
23
    }
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
23
}
pe-mcore.c:coff_classify_symbol
Line
Count
Source
5085
6.56k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
6.56k
  switch (syment->n_sclass)
5089
6.56k
    {
5090
3.70k
    case C_EXT:
5091
3.94k
    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.94k
#ifdef C_SYSTEM
5103
4.55k
    case C_SYSTEM:
5104
4.55k
#endif
5105
4.55k
#ifdef COFF_WITH_PE
5106
6.51k
    case C_NT_WEAK:
5107
6.51k
#endif
5108
6.51k
      if (syment->n_scnum == 0)
5109
797
  {
5110
797
    if (syment->n_value == 0)
5111
153
      return COFF_SYMBOL_UNDEFINED;
5112
644
    else
5113
644
      return COFF_SYMBOL_COMMON;
5114
797
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
5.71k
      return COFF_SYMBOL_GLOBAL;
5120
5121
55
    default:
5122
55
      break;
5123
6.56k
    }
5124
5125
55
#ifdef COFF_WITH_PE
5126
55
  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
55
  if (syment->n_sclass == C_SECTION)
5156
55
    {
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
55
      syment->n_value = 0;
5161
55
      if (syment->n_scnum == 0)
5162
55
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
55
    }
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
55
}
pe-sh.c:coff_classify_symbol
Line
Count
Source
5085
5.09k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
5.09k
  switch (syment->n_sclass)
5089
5.09k
    {
5090
2.82k
    case C_EXT:
5091
2.96k
    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.96k
#ifdef C_SYSTEM
5103
3.50k
    case C_SYSTEM:
5104
3.50k
#endif
5105
3.50k
#ifdef COFF_WITH_PE
5106
5.05k
    case C_NT_WEAK:
5107
5.05k
#endif
5108
5.05k
      if (syment->n_scnum == 0)
5109
664
  {
5110
664
    if (syment->n_value == 0)
5111
163
      return COFF_SYMBOL_UNDEFINED;
5112
501
    else
5113
501
      return COFF_SYMBOL_COMMON;
5114
664
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
4.38k
      return COFF_SYMBOL_GLOBAL;
5120
5121
44
    default:
5122
44
      break;
5123
5.09k
    }
5124
5125
44
#ifdef COFF_WITH_PE
5126
44
  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
44
  if (syment->n_sclass == C_SECTION)
5156
44
    {
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
44
      syment->n_value = 0;
5161
44
      if (syment->n_scnum == 0)
5162
44
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
44
    }
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
44
}
pei-arm-wince.c:coff_classify_symbol
Line
Count
Source
5085
2.25k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.25k
  switch (syment->n_sclass)
5089
2.25k
    {
5090
1.02k
    case C_EXT:
5091
1.07k
    case C_WEAKEXT:
5092
1.07k
#ifdef ARM
5093
1.10k
    case C_THUMBEXT:
5094
1.12k
    case C_THUMBEXTFUNC:
5095
1.12k
#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.12k
#ifdef C_SYSTEM
5103
1.41k
    case C_SYSTEM:
5104
1.41k
#endif
5105
1.41k
#ifdef COFF_WITH_PE
5106
2.22k
    case C_NT_WEAK:
5107
2.22k
#endif
5108
2.22k
      if (syment->n_scnum == 0)
5109
183
  {
5110
183
    if (syment->n_value == 0)
5111
57
      return COFF_SYMBOL_UNDEFINED;
5112
126
    else
5113
126
      return COFF_SYMBOL_COMMON;
5114
183
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.04k
      return COFF_SYMBOL_GLOBAL;
5120
5121
29
    default:
5122
29
      break;
5123
2.25k
    }
5124
5125
29
#ifdef COFF_WITH_PE
5126
29
  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
29
  if (syment->n_sclass == C_SECTION)
5156
29
    {
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
29
      syment->n_value = 0;
5161
29
      if (syment->n_scnum == 0)
5162
29
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
29
    }
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
29
}
pei-arm.c:coff_classify_symbol
Line
Count
Source
5085
3.69k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
3.69k
  switch (syment->n_sclass)
5089
3.69k
    {
5090
2.35k
    case C_EXT:
5091
2.44k
    case C_WEAKEXT:
5092
2.44k
#ifdef ARM
5093
2.50k
    case C_THUMBEXT:
5094
2.54k
    case C_THUMBEXTFUNC:
5095
2.54k
#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.54k
#ifdef C_SYSTEM
5103
2.87k
    case C_SYSTEM:
5104
2.87k
#endif
5105
2.87k
#ifdef COFF_WITH_PE
5106
3.67k
    case C_NT_WEAK:
5107
3.67k
#endif
5108
3.67k
      if (syment->n_scnum == 0)
5109
857
  {
5110
857
    if (syment->n_value == 0)
5111
65
      return COFF_SYMBOL_UNDEFINED;
5112
792
    else
5113
792
      return COFF_SYMBOL_COMMON;
5114
857
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.81k
      return COFF_SYMBOL_GLOBAL;
5120
5121
17
    default:
5122
17
      break;
5123
3.69k
    }
5124
5125
17
#ifdef COFF_WITH_PE
5126
17
  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
17
  if (syment->n_sclass == C_SECTION)
5156
17
    {
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
17
      syment->n_value = 0;
5161
17
      if (syment->n_scnum == 0)
5162
17
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
17
    }
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
17
}
pei-mcore.c:coff_classify_symbol
Line
Count
Source
5085
2.40k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
2.40k
  switch (syment->n_sclass)
5089
2.40k
    {
5090
948
    case C_EXT:
5091
1.16k
    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.16k
#ifdef C_SYSTEM
5103
1.37k
    case C_SYSTEM:
5104
1.37k
#endif
5105
1.37k
#ifdef COFF_WITH_PE
5106
2.35k
    case C_NT_WEAK:
5107
2.35k
#endif
5108
2.35k
      if (syment->n_scnum == 0)
5109
287
  {
5110
287
    if (syment->n_value == 0)
5111
70
      return COFF_SYMBOL_UNDEFINED;
5112
217
    else
5113
217
      return COFF_SYMBOL_COMMON;
5114
287
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
2.06k
      return COFF_SYMBOL_GLOBAL;
5120
5121
51
    default:
5122
51
      break;
5123
2.40k
    }
5124
5125
51
#ifdef COFF_WITH_PE
5126
51
  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
51
  if (syment->n_sclass == C_SECTION)
5156
51
    {
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
51
      syment->n_value = 0;
5161
51
      if (syment->n_scnum == 0)
5162
51
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
51
    }
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
51
}
pei-sh.c:coff_classify_symbol
Line
Count
Source
5085
5.24k
{
5086
  /* FIXME: This partially duplicates the switch in
5087
     coff_slurp_symbol_table.  */
5088
5.24k
  switch (syment->n_sclass)
5089
5.24k
    {
5090
3.14k
    case C_EXT:
5091
3.44k
    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.44k
#ifdef C_SYSTEM
5103
3.77k
    case C_SYSTEM:
5104
3.77k
#endif
5105
3.77k
#ifdef COFF_WITH_PE
5106
5.19k
    case C_NT_WEAK:
5107
5.19k
#endif
5108
5.19k
      if (syment->n_scnum == 0)
5109
548
  {
5110
548
    if (syment->n_value == 0)
5111
180
      return COFF_SYMBOL_UNDEFINED;
5112
368
    else
5113
368
      return COFF_SYMBOL_COMMON;
5114
548
  }
5115
#ifdef RS6000COFF_C
5116
      if (syment->n_sclass == C_HIDEXT)
5117
  return COFF_SYMBOL_LOCAL;
5118
#endif
5119
4.64k
      return COFF_SYMBOL_GLOBAL;
5120
5121
53
    default:
5122
53
      break;
5123
5.24k
    }
5124
5125
53
#ifdef COFF_WITH_PE
5126
53
  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
53
  if (syment->n_sclass == C_SECTION)
5156
53
    {
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
53
      syment->n_value = 0;
5161
53
      if (syment->n_scnum == 0)
5162
53
  return COFF_SYMBOL_UNDEFINED;
5163
0
      return COFF_SYMBOL_PE_SECTION;
5164
53
    }
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
53
}
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
672
#define COFF_PE_ADDEND_BIAS(ptr) 0 /* Symbol value not stored in raw data.  */
5217
#else
5218
508
#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
731
  {               \
5224
731
    coff_symbol_type *coffsym = NULL;       \
5225
731
                \
5226
731
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
5227
731
      coffsym = (obj_symbols (abfd)       \
5228
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
5229
731
    else if (ptr)           \
5230
731
      coffsym = coff_symbol_from (ptr);       \
5231
731
    if (coffsym != NULL            \
5232
731
  && coffsym->native->is_sym        \
5233
731
  && coffsym->native->u.syment.n_scnum == 0)   \
5234
731
      cache_ptr->addend = 0;         \
5235
731
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
5236
627
       && ptr->section != NULL)       \
5237
627
      cache_ptr->addend = - (ptr->section->vma      \
5238
376
           + COFF_PE_ADDEND_BIAS (ptr)); \
5239
627
    else              \
5240
627
      cache_ptr->addend = 0;         \
5241
731
  }
5242
#endif
5243
5244
static bool
5245
coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
5246
32.2k
{
5247
32.2k
  bfd_byte *native_relocs;
5248
32.2k
  arelent *reloc_cache;
5249
32.2k
  arelent *cache_ptr;
5250
32.2k
  unsigned int idx;
5251
32.2k
  size_t amt;
5252
5253
32.2k
  if (asect->relocation)
5254
177
    return true;
5255
32.0k
  if (asect->reloc_count == 0)
5256
1.08k
    return true;
5257
30.9k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
30.9k
  if (!coff_slurp_symbol_table (abfd))
5260
21.6k
    return false;
5261
5262
9.34k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
9.34k
               asect->reloc_count,
5264
9.34k
               bfd_coff_relsz (abfd));
5265
9.34k
  if (native_relocs == NULL)
5266
5.73k
    return false;
5267
5268
3.60k
  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
3.60k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
3.60k
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
23.0k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
22.6k
    {
5282
22.6k
      struct internal_reloc dst;
5283
22.6k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
22.6k
      cache_ptr = reloc_cache + idx;
5289
22.6k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
22.6k
      dst.r_offset = 0;
5292
22.6k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
#ifdef RELOC_PROCESSING
5295
7.72k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5296
#else
5297
      cache_ptr->address = dst.r_vaddr;
5298
5299
14.9k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
9.22k
  {
5301
9.22k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
1.61k
      {
5303
1.61k
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
1.61k
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
1.61k
     abfd, dst.r_symndx);
5307
1.61k
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
1.61k
        ptr = NULL;
5309
1.61k
      }
5310
7.61k
    else
5311
7.61k
      {
5312
7.61k
        cache_ptr->sym_ptr_ptr = (symbols
5313
7.61k
          + obj_convert (abfd)[dst.r_symndx]);
5314
7.61k
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
7.61k
      }
5316
9.22k
  }
5317
5.71k
      else
5318
5.71k
  {
5319
5.71k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
5.71k
    ptr = NULL;
5321
5.71k
  }
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
14.9k
      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
14.9k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
#endif  /* RELOC_PROCESSING */
5340
5341
22.6k
      if (cache_ptr->howto == NULL)
5342
3.17k
  {
5343
3.17k
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
3.17k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
3.17k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
3.17k
    bfd_set_error (bfd_error_bad_value);
5348
3.17k
    free (native_relocs);
5349
3.17k
    return false;
5350
3.17k
  }
5351
22.6k
    }
5352
5353
430
  free (native_relocs);
5354
430
  asect->relocation = reloc_cache;
5355
430
  return true;
5356
3.60k
}
pei-i386.c:coff_slurp_reloc_table
Line
Count
Source
5246
76
{
5247
76
  bfd_byte *native_relocs;
5248
76
  arelent *reloc_cache;
5249
76
  arelent *cache_ptr;
5250
76
  unsigned int idx;
5251
76
  size_t amt;
5252
5253
76
  if (asect->relocation)
5254
13
    return true;
5255
63
  if (asect->reloc_count == 0)
5256
63
    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
355
{
5247
355
  bfd_byte *native_relocs;
5248
355
  arelent *reloc_cache;
5249
355
  arelent *cache_ptr;
5250
355
  unsigned int idx;
5251
355
  size_t amt;
5252
5253
355
  if (asect->relocation)
5254
0
    return true;
5255
355
  if (asect->reloc_count == 0)
5256
46
    return true;
5257
309
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
309
  if (!coff_slurp_symbol_table (abfd))
5260
84
    return false;
5261
5262
225
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
225
               asect->reloc_count,
5264
225
               bfd_coff_relsz (abfd));
5265
225
  if (native_relocs == NULL)
5266
74
    return false;
5267
5268
151
  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
151
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
151
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
2.93k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
2.88k
    {
5282
2.88k
      struct internal_reloc dst;
5283
2.88k
      void *src;
5284
2.88k
#ifndef RELOC_PROCESSING
5285
2.88k
      asymbol *ptr;
5286
2.88k
#endif
5287
5288
2.88k
      cache_ptr = reloc_cache + idx;
5289
2.88k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
2.88k
      dst.r_offset = 0;
5292
2.88k
      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
2.88k
      cache_ptr->address = dst.r_vaddr;
5298
5299
2.88k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
1.32k
  {
5301
1.32k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
296
      {
5303
296
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
296
     abfd, dst.r_symndx);
5307
296
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
296
        ptr = NULL;
5309
296
      }
5310
1.02k
    else
5311
1.02k
      {
5312
1.02k
        cache_ptr->sym_ptr_ptr = (symbols
5313
1.02k
          + obj_convert (abfd)[dst.r_symndx]);
5314
1.02k
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
1.02k
      }
5316
1.32k
  }
5317
1.56k
      else
5318
1.56k
  {
5319
1.56k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
1.56k
    ptr = NULL;
5321
1.56k
  }
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
2.88k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
2.88k
      (void) ptr;
5333
5334
2.88k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
2.88k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
2.88k
#endif  /* RELOC_PROCESSING */
5340
5341
2.88k
      if (cache_ptr->howto == NULL)
5342
101
  {
5343
101
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
101
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
101
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
101
    bfd_set_error (bfd_error_bad_value);
5348
101
    free (native_relocs);
5349
101
    return false;
5350
101
  }
5351
2.88k
    }
5352
5353
50
  free (native_relocs);
5354
50
  asect->relocation = reloc_cache;
5355
50
  return true;
5356
151
}
pei-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5246
57
{
5247
57
  bfd_byte *native_relocs;
5248
57
  arelent *reloc_cache;
5249
57
  arelent *cache_ptr;
5250
57
  unsigned int idx;
5251
57
  size_t amt;
5252
5253
57
  if (asect->relocation)
5254
10
    return true;
5255
47
  if (asect->reloc_count == 0)
5256
47
    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
8.08k
{
5247
8.08k
  bfd_byte *native_relocs;
5248
8.08k
  arelent *reloc_cache;
5249
8.08k
  arelent *cache_ptr;
5250
8.08k
  unsigned int idx;
5251
8.08k
  size_t amt;
5252
5253
8.08k
  if (asect->relocation)
5254
61
    return true;
5255
8.02k
  if (asect->reloc_count == 0)
5256
645
    return true;
5257
7.38k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
7.38k
  if (!coff_slurp_symbol_table (abfd))
5260
6.71k
    return false;
5261
5262
664
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
664
               asect->reloc_count,
5264
664
               bfd_coff_relsz (abfd));
5265
664
  if (native_relocs == NULL)
5266
257
    return false;
5267
5268
407
  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
407
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
407
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
8.45k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
8.32k
    {
5282
8.32k
      struct internal_reloc dst;
5283
8.32k
      void *src;
5284
8.32k
#ifndef RELOC_PROCESSING
5285
8.32k
      asymbol *ptr;
5286
8.32k
#endif
5287
5288
8.32k
      cache_ptr = reloc_cache + idx;
5289
8.32k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
8.32k
      dst.r_offset = 0;
5292
8.32k
      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
8.32k
      cache_ptr->address = dst.r_vaddr;
5298
5299
8.32k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
5.50k
  {
5301
5.50k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
502
      {
5303
502
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
502
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
502
     abfd, dst.r_symndx);
5307
502
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
502
        ptr = NULL;
5309
502
      }
5310
5.00k
    else
5311
5.00k
      {
5312
5.00k
        cache_ptr->sym_ptr_ptr = (symbols
5313
5.00k
          + obj_convert (abfd)[dst.r_symndx]);
5314
5.00k
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
5.00k
      }
5316
5.50k
  }
5317
2.81k
      else
5318
2.81k
  {
5319
2.81k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
2.81k
    ptr = NULL;
5321
2.81k
  }
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
8.32k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
8.32k
      (void) ptr;
5333
5334
8.32k
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
8.32k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
8.32k
#endif  /* RELOC_PROCESSING */
5340
5341
8.32k
      if (cache_ptr->howto == NULL)
5342
281
  {
5343
281
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
281
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
281
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
281
    bfd_set_error (bfd_error_bad_value);
5348
281
    free (native_relocs);
5349
281
    return false;
5350
281
  }
5351
8.32k
    }
5352
5353
126
  free (native_relocs);
5354
126
  asect->relocation = reloc_cache;
5355
126
  return true;
5356
407
}
coff64-rs6000.c:coff_slurp_reloc_table
Line
Count
Source
5246
996
{
5247
996
  bfd_byte *native_relocs;
5248
996
  arelent *reloc_cache;
5249
996
  arelent *cache_ptr;
5250
996
  unsigned int idx;
5251
996
  size_t amt;
5252
5253
996
  if (asect->relocation)
5254
0
    return true;
5255
996
  if (asect->reloc_count == 0)
5256
11
    return true;
5257
985
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
985
  if (!coff_slurp_symbol_table (abfd))
5260
935
    return false;
5261
5262
50
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
50
               asect->reloc_count,
5264
50
               bfd_coff_relsz (abfd));
5265
50
  if (native_relocs == NULL)
5266
50
    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
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
10
    return true;
5255
546
  if (asect->reloc_count == 0)
5256
60
    return true;
5257
486
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
486
  if (!coff_slurp_symbol_table (abfd))
5260
351
    return false;
5261
5262
135
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
135
               asect->reloc_count,
5264
135
               bfd_coff_relsz (abfd));
5265
135
  if (native_relocs == NULL)
5266
58
    return false;
5267
5268
77
  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
77
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
77
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
343
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
313
    {
5282
313
      struct internal_reloc dst;
5283
313
      void *src;
5284
313
#ifndef RELOC_PROCESSING
5285
313
      asymbol *ptr;
5286
313
#endif
5287
5288
313
      cache_ptr = reloc_cache + idx;
5289
313
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
313
      dst.r_offset = 0;
5292
313
      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
313
      cache_ptr->address = dst.r_vaddr;
5298
5299
313
      if (dst.r_symndx != -1 && symbols != NULL)
5300
296
  {
5301
296
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
163
      {
5303
163
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
163
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
163
     abfd, dst.r_symndx);
5307
163
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
163
        ptr = NULL;
5309
163
      }
5310
133
    else
5311
133
      {
5312
133
        cache_ptr->sym_ptr_ptr = (symbols
5313
133
          + obj_convert (abfd)[dst.r_symndx]);
5314
133
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
133
      }
5316
296
  }
5317
17
      else
5318
17
  {
5319
17
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
17
    ptr = NULL;
5321
17
  }
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
313
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
313
      (void) ptr;
5333
5334
313
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
313
      RTYPE2HOWTO (cache_ptr, &dst);
5339
313
#endif  /* RELOC_PROCESSING */
5340
5341
313
      if (cache_ptr->howto == NULL)
5342
47
  {
5343
47
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
47
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
47
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
47
    bfd_set_error (bfd_error_bad_value);
5348
47
    free (native_relocs);
5349
47
    return false;
5350
47
  }
5351
313
    }
5352
5353
30
  free (native_relocs);
5354
30
  asect->relocation = reloc_cache;
5355
30
  return true;
5356
77
}
pei-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5246
26
{
5247
26
  bfd_byte *native_relocs;
5248
26
  arelent *reloc_cache;
5249
26
  arelent *cache_ptr;
5250
26
  unsigned int idx;
5251
26
  size_t amt;
5252
5253
26
  if (asect->relocation)
5254
16
    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
}
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
19
{
5247
19
  bfd_byte *native_relocs;
5248
19
  arelent *reloc_cache;
5249
19
  arelent *cache_ptr;
5250
19
  unsigned int idx;
5251
19
  size_t amt;
5252
5253
19
  if (asect->relocation)
5254
18
    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-riscv64.c:coff_slurp_reloc_table
Line
Count
Source
5246
23
{
5247
23
  bfd_byte *native_relocs;
5248
23
  arelent *reloc_cache;
5249
23
  arelent *cache_ptr;
5250
23
  unsigned int idx;
5251
23
  size_t amt;
5252
5253
23
  if (asect->relocation)
5254
19
    return true;
5255
4
  if (asect->reloc_count == 0)
5256
4
    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
1.35k
{
5247
1.35k
  bfd_byte *native_relocs;
5248
1.35k
  arelent *reloc_cache;
5249
1.35k
  arelent *cache_ptr;
5250
1.35k
  unsigned int idx;
5251
1.35k
  size_t amt;
5252
5253
1.35k
  if (asect->relocation)
5254
0
    return true;
5255
1.35k
  if (asect->reloc_count == 0)
5256
8
    return true;
5257
1.34k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
1.34k
  if (!coff_slurp_symbol_table (abfd))
5260
1.23k
    return false;
5261
5262
108
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
108
               asect->reloc_count,
5264
108
               bfd_coff_relsz (abfd));
5265
108
  if (native_relocs == NULL)
5266
108
    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
2.58k
{
5247
2.58k
  bfd_byte *native_relocs;
5248
2.58k
  arelent *reloc_cache;
5249
2.58k
  arelent *cache_ptr;
5250
2.58k
  unsigned int idx;
5251
2.58k
  size_t amt;
5252
5253
2.58k
  if (asect->relocation)
5254
2
    return true;
5255
2.58k
  if (asect->reloc_count == 0)
5256
69
    return true;
5257
2.51k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
2.51k
  if (!coff_slurp_symbol_table (abfd))
5260
1.54k
    return false;
5261
5262
973
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
973
               asect->reloc_count,
5264
973
               bfd_coff_relsz (abfd));
5265
973
  if (native_relocs == NULL)
5266
632
    return false;
5267
5268
341
  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
341
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
341
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
1.64k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
1.56k
    {
5282
1.56k
      struct internal_reloc dst;
5283
1.56k
      void *src;
5284
1.56k
#ifndef RELOC_PROCESSING
5285
1.56k
      asymbol *ptr;
5286
1.56k
#endif
5287
5288
1.56k
      cache_ptr = reloc_cache + idx;
5289
1.56k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
1.56k
      dst.r_offset = 0;
5292
1.56k
      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.56k
      cache_ptr->address = dst.r_vaddr;
5298
5299
1.56k
      if (dst.r_symndx != -1 && symbols != NULL)
5300
534
  {
5301
534
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
211
      {
5303
211
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
211
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
211
     abfd, dst.r_symndx);
5307
211
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
211
        ptr = NULL;
5309
211
      }
5310
323
    else
5311
323
      {
5312
323
        cache_ptr->sym_ptr_ptr = (symbols
5313
323
          + obj_convert (abfd)[dst.r_symndx]);
5314
323
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
323
      }
5316
534
  }
5317
1.03k
      else
5318
1.03k
  {
5319
1.03k
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
1.03k
    ptr = NULL;
5321
1.03k
  }
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.56k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
1.56k
      (void) ptr;
5333
5334
1.56k
      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.56k
      RTYPE2HOWTO (cache_ptr, &dst);
5339
1.56k
#endif  /* RELOC_PROCESSING */
5340
5341
1.56k
      if (cache_ptr->howto == NULL)
5342
266
  {
5343
266
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
266
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
266
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
266
    bfd_set_error (bfd_error_bad_value);
5348
266
    free (native_relocs);
5349
266
    return false;
5350
266
  }
5351
1.56k
    }
5352
5353
75
  free (native_relocs);
5354
75
  asect->relocation = reloc_cache;
5355
75
  return true;
5356
341
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_reloc_table
coff-tic30.c:coff_slurp_reloc_table
Line
Count
Source
5246
5.58k
{
5247
5.58k
  bfd_byte *native_relocs;
5248
5.58k
  arelent *reloc_cache;
5249
5.58k
  arelent *cache_ptr;
5250
5.58k
  unsigned int idx;
5251
5.58k
  size_t amt;
5252
5253
5.58k
  if (asect->relocation)
5254
0
    return true;
5255
5.58k
  if (asect->reloc_count == 0)
5256
41
    return true;
5257
5.54k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
5.54k
  if (!coff_slurp_symbol_table (abfd))
5260
1.28k
    return false;
5261
5262
4.26k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
4.26k
               asect->reloc_count,
5264
4.26k
               bfd_coff_relsz (abfd));
5265
4.26k
  if (native_relocs == NULL)
5266
2.83k
    return false;
5267
5268
1.43k
  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.43k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
1.43k
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
1.50k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
1.49k
    {
5282
1.49k
      struct internal_reloc dst;
5283
1.49k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
1.49k
      cache_ptr = reloc_cache + idx;
5289
1.49k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
1.49k
      dst.r_offset = 0;
5292
1.49k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
1.49k
#ifdef RELOC_PROCESSING
5295
1.49k
      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
1.49k
      if (cache_ptr->howto == NULL)
5342
1.42k
  {
5343
1.42k
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
1.42k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
1.42k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
1.42k
    bfd_set_error (bfd_error_bad_value);
5348
1.42k
    free (native_relocs);
5349
1.42k
    return false;
5350
1.42k
  }
5351
1.49k
    }
5352
5353
11
  free (native_relocs);
5354
11
  asect->relocation = reloc_cache;
5355
11
  return true;
5356
1.43k
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_reloc_table
coff-tic54x.c:coff_slurp_reloc_table
Line
Count
Source
5246
3.52k
{
5247
3.52k
  bfd_byte *native_relocs;
5248
3.52k
  arelent *reloc_cache;
5249
3.52k
  arelent *cache_ptr;
5250
3.52k
  unsigned int idx;
5251
3.52k
  size_t amt;
5252
5253
3.52k
  if (asect->relocation)
5254
0
    return true;
5255
3.52k
  if (asect->reloc_count == 0)
5256
55
    return true;
5257
3.46k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
3.46k
  if (!coff_slurp_symbol_table (abfd))
5260
3.30k
    return false;
5261
5262
164
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
164
               asect->reloc_count,
5264
164
               bfd_coff_relsz (abfd));
5265
164
  if (native_relocs == NULL)
5266
78
    return false;
5267
5268
86
  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
86
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
86
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
151
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
138
    {
5282
138
      struct internal_reloc dst;
5283
138
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
138
      cache_ptr = reloc_cache + idx;
5289
138
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
138
      dst.r_offset = 0;
5292
138
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
138
#ifdef RELOC_PROCESSING
5295
138
      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
138
      if (cache_ptr->howto == NULL)
5342
73
  {
5343
73
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
73
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
73
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
73
    bfd_set_error (bfd_error_bad_value);
5348
73
    free (native_relocs);
5349
73
    return false;
5350
73
  }
5351
138
    }
5352
5353
13
  free (native_relocs);
5354
13
  asect->relocation = reloc_cache;
5355
13
  return true;
5356
86
}
coff-z80.c:coff_slurp_reloc_table
Line
Count
Source
5246
4.73k
{
5247
4.73k
  bfd_byte *native_relocs;
5248
4.73k
  arelent *reloc_cache;
5249
4.73k
  arelent *cache_ptr;
5250
4.73k
  unsigned int idx;
5251
4.73k
  size_t amt;
5252
5253
4.73k
  if (asect->relocation)
5254
0
    return true;
5255
4.73k
  if (asect->reloc_count == 0)
5256
4
    return true;
5257
4.72k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
4.72k
  if (!coff_slurp_symbol_table (abfd))
5260
3.28k
    return false;
5261
5262
1.44k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
1.44k
               asect->reloc_count,
5264
1.44k
               bfd_coff_relsz (abfd));
5265
1.44k
  if (native_relocs == NULL)
5266
774
    return false;
5267
5268
672
  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
672
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
672
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
5.88k
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
5.80k
    {
5282
5.80k
      struct internal_reloc dst;
5283
5.80k
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
5.80k
      cache_ptr = reloc_cache + idx;
5289
5.80k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
5.80k
      dst.r_offset = 0;
5292
5.80k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
5.80k
#ifdef RELOC_PROCESSING
5295
5.80k
      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
5.80k
      if (cache_ptr->howto == NULL)
5342
595
  {
5343
595
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
595
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
595
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
595
    bfd_set_error (bfd_error_bad_value);
5348
595
    free (native_relocs);
5349
595
    return false;
5350
595
  }
5351
5.80k
    }
5352
5353
77
  free (native_relocs);
5354
77
  asect->relocation = reloc_cache;
5355
77
  return true;
5356
672
}
coff-z8k.c:coff_slurp_reloc_table
Line
Count
Source
5246
3.97k
{
5247
3.97k
  bfd_byte *native_relocs;
5248
3.97k
  arelent *reloc_cache;
5249
3.97k
  arelent *cache_ptr;
5250
3.97k
  unsigned int idx;
5251
3.97k
  size_t amt;
5252
5253
3.97k
  if (asect->relocation)
5254
0
    return true;
5255
3.97k
  if (asect->reloc_count == 0)
5256
7
    return true;
5257
3.96k
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
3.96k
  if (!coff_slurp_symbol_table (abfd))
5260
2.86k
    return false;
5261
5262
1.10k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
1.10k
               asect->reloc_count,
5264
1.10k
               bfd_coff_relsz (abfd));
5265
1.10k
  if (native_relocs == NULL)
5266
824
    return false;
5267
5268
279
  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
279
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
279
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
292
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
290
    {
5282
290
      struct internal_reloc dst;
5283
290
      void *src;
5284
#ifndef RELOC_PROCESSING
5285
      asymbol *ptr;
5286
#endif
5287
5288
290
      cache_ptr = reloc_cache + idx;
5289
290
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
290
      dst.r_offset = 0;
5292
290
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5293
5294
290
#ifdef RELOC_PROCESSING
5295
290
      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
290
      if (cache_ptr->howto == NULL)
5342
277
  {
5343
277
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
277
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
277
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
277
    bfd_set_error (bfd_error_bad_value);
5348
277
    free (native_relocs);
5349
277
    return false;
5350
277
  }
5351
290
    }
5352
5353
2
  free (native_relocs);
5354
2
  asect->relocation = reloc_cache;
5355
2
  return true;
5356
279
}
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
33
{
5247
33
  bfd_byte *native_relocs;
5248
33
  arelent *reloc_cache;
5249
33
  arelent *cache_ptr;
5250
33
  unsigned int idx;
5251
33
  size_t amt;
5252
5253
33
  if (asect->relocation)
5254
0
    return true;
5255
33
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
32
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
32
  if (!coff_slurp_symbol_table (abfd))
5260
1
    return false;
5261
5262
31
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
31
               asect->reloc_count,
5264
31
               bfd_coff_relsz (abfd));
5265
31
  if (native_relocs == NULL)
5266
1
    return false;
5267
5268
30
  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
30
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
30
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
369
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
356
    {
5282
356
      struct internal_reloc dst;
5283
356
      void *src;
5284
356
#ifndef RELOC_PROCESSING
5285
356
      asymbol *ptr;
5286
356
#endif
5287
5288
356
      cache_ptr = reloc_cache + idx;
5289
356
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
356
      dst.r_offset = 0;
5292
356
      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
356
      cache_ptr->address = dst.r_vaddr;
5298
5299
356
      if (dst.r_symndx != -1 && symbols != NULL)
5300
348
  {
5301
348
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
111
      {
5303
111
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
111
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
111
     abfd, dst.r_symndx);
5307
111
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
111
        ptr = NULL;
5309
111
      }
5310
237
    else
5311
237
      {
5312
237
        cache_ptr->sym_ptr_ptr = (symbols
5313
237
          + obj_convert (abfd)[dst.r_symndx]);
5314
237
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
237
      }
5316
348
  }
5317
8
      else
5318
8
  {
5319
8
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
8
    ptr = NULL;
5321
8
  }
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
356
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
356
      (void) ptr;
5333
5334
356
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
356
      RTYPE2HOWTO (cache_ptr, &dst);
5339
356
#endif  /* RELOC_PROCESSING */
5340
5341
356
      if (cache_ptr->howto == NULL)
5342
17
  {
5343
17
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
17
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
17
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
17
    bfd_set_error (bfd_error_bad_value);
5348
17
    free (native_relocs);
5349
17
    return false;
5350
17
  }
5351
356
    }
5352
5353
13
  free (native_relocs);
5354
13
  asect->relocation = reloc_cache;
5355
13
  return true;
5356
30
}
pe-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5246
101
{
5247
101
  bfd_byte *native_relocs;
5248
101
  arelent *reloc_cache;
5249
101
  arelent *cache_ptr;
5250
101
  unsigned int idx;
5251
101
  size_t amt;
5252
5253
101
  if (asect->relocation)
5254
1
    return true;
5255
100
  if (asect->reloc_count == 0)
5256
0
    return true;
5257
100
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
100
  if (!coff_slurp_symbol_table (abfd))
5260
8
    return false;
5261
5262
92
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
92
               asect->reloc_count,
5264
92
               bfd_coff_relsz (abfd));
5265
92
  if (native_relocs == NULL)
5266
26
    return false;
5267
5268
66
  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
66
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
66
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
621
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
593
    {
5282
593
      struct internal_reloc dst;
5283
593
      void *src;
5284
593
#ifndef RELOC_PROCESSING
5285
593
      asymbol *ptr;
5286
593
#endif
5287
5288
593
      cache_ptr = reloc_cache + idx;
5289
593
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
593
      dst.r_offset = 0;
5292
593
      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
593
      cache_ptr->address = dst.r_vaddr;
5298
5299
593
      if (dst.r_symndx != -1 && symbols != NULL)
5300
565
  {
5301
565
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
171
      {
5303
171
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
171
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
171
     abfd, dst.r_symndx);
5307
171
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
171
        ptr = NULL;
5309
171
      }
5310
394
    else
5311
394
      {
5312
394
        cache_ptr->sym_ptr_ptr = (symbols
5313
394
          + obj_convert (abfd)[dst.r_symndx]);
5314
394
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
394
      }
5316
565
  }
5317
28
      else
5318
28
  {
5319
28
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
28
    ptr = NULL;
5321
28
  }
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
593
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
593
      (void) ptr;
5333
5334
593
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
593
      RTYPE2HOWTO (cache_ptr, &dst);
5339
593
#endif  /* RELOC_PROCESSING */
5340
5341
593
      if (cache_ptr->howto == NULL)
5342
38
  {
5343
38
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
38
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
38
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
38
    bfd_set_error (bfd_error_bad_value);
5348
38
    free (native_relocs);
5349
38
    return false;
5350
38
  }
5351
593
    }
5352
5353
28
  free (native_relocs);
5354
28
  asect->relocation = reloc_cache;
5355
28
  return true;
5356
66
}
pe-sh.c:coff_slurp_reloc_table
Line
Count
Source
5246
106
{
5247
106
  bfd_byte *native_relocs;
5248
106
  arelent *reloc_cache;
5249
106
  arelent *cache_ptr;
5250
106
  unsigned int idx;
5251
106
  size_t amt;
5252
5253
106
  if (asect->relocation)
5254
0
    return true;
5255
106
  if (asect->reloc_count == 0)
5256
1
    return true;
5257
105
  if (asect->flags & SEC_CONSTRUCTOR)
5258
0
    return true;
5259
105
  if (!coff_slurp_symbol_table (abfd))
5260
21
    return false;
5261
5262
84
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5263
84
               asect->reloc_count,
5264
84
               bfd_coff_relsz (abfd));
5265
84
  if (native_relocs == NULL)
5266
17
    return false;
5267
5268
67
  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
67
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5274
67
  if (reloc_cache == NULL)
5275
0
    {
5276
0
      free (native_relocs);
5277
0
      return false;
5278
0
    }
5279
5280
902
  for (idx = 0; idx < asect->reloc_count; idx++)
5281
897
    {
5282
897
      struct internal_reloc dst;
5283
897
      void *src;
5284
897
#ifndef RELOC_PROCESSING
5285
897
      asymbol *ptr;
5286
897
#endif
5287
5288
897
      cache_ptr = reloc_cache + idx;
5289
897
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5290
5291
897
      dst.r_offset = 0;
5292
897
      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
897
      cache_ptr->address = dst.r_vaddr;
5298
5299
897
      if (dst.r_symndx != -1 && symbols != NULL)
5300
653
  {
5301
653
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5302
163
      {
5303
163
        _bfd_error_handler
5304
    /* xgettext:c-format */
5305
163
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5306
163
     abfd, dst.r_symndx);
5307
163
        cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5308
163
        ptr = NULL;
5309
163
      }
5310
490
    else
5311
490
      {
5312
490
        cache_ptr->sym_ptr_ptr = (symbols
5313
490
          + obj_convert (abfd)[dst.r_symndx]);
5314
490
        ptr = *(cache_ptr->sym_ptr_ptr);
5315
490
      }
5316
653
  }
5317
244
      else
5318
244
  {
5319
244
    cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
5320
244
    ptr = NULL;
5321
244
  }
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
897
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5332
897
      (void) ptr;
5333
5334
897
      cache_ptr->address -= asect->vma;
5335
      /* !! cache_ptr->section = NULL;*/
5336
5337
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5338
897
      RTYPE2HOWTO (cache_ptr, &dst);
5339
897
#endif  /* RELOC_PROCESSING */
5340
5341
897
      if (cache_ptr->howto == NULL)
5342
62
  {
5343
62
    _bfd_error_handler
5344
      /* xgettext:c-format */
5345
62
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5346
62
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5347
62
    bfd_set_error (bfd_error_bad_value);
5348
62
    free (native_relocs);
5349
62
    return false;
5350
62
  }
5351
897
    }
5352
5353
5
  free (native_relocs);
5354
5
  asect->relocation = reloc_cache;
5355
5
  return true;
5356
67
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_reloc_table
pei-arm.c:coff_slurp_reloc_table
Line
Count
Source
5246
9
{
5247
9
  bfd_byte *native_relocs;
5248
9
  arelent *reloc_cache;
5249
9
  arelent *cache_ptr;
5250
9
  unsigned int idx;
5251
9
  size_t amt;
5252
5253
9
  if (asect->relocation)
5254
4
    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
}
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
23
{
5247
23
  bfd_byte *native_relocs;
5248
23
  arelent *reloc_cache;
5249
23
  arelent *cache_ptr;
5250
23
  unsigned int idx;
5251
23
  size_t amt;
5252
5253
23
  if (asect->relocation)
5254
23
    return true;
5255
0
  if (asect->reloc_count == 0)
5256
0
    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
32.2k
{
5397
32.2k
  arelent *tblptr = section->relocation;
5398
32.2k
  unsigned int count = 0;
5399
5400
32.2k
  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
32.2k
  else
5414
32.2k
    {
5415
32.2k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
30.5k
  return -1;
5417
5418
1.68k
      tblptr = section->relocation;
5419
5420
10.5k
      for (; count++ < section->reloc_count;)
5421
8.88k
  *relptr++ = tblptr++;
5422
1.68k
    }
5423
1.68k
  *relptr = 0;
5424
1.68k
  return section->reloc_count;
5425
32.2k
}
pei-i386.c:coff_canonicalize_reloc
Line
Count
Source
5396
76
{
5397
76
  arelent *tblptr = section->relocation;
5398
76
  unsigned int count = 0;
5399
5400
76
  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
76
  else
5414
76
    {
5415
76
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
76
      tblptr = section->relocation;
5419
5420
89
      for (; count++ < section->reloc_count;)
5421
13
  *relptr++ = tblptr++;
5422
76
    }
5423
76
  *relptr = 0;
5424
76
  return section->reloc_count;
5425
76
}
pe-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
355
{
5397
355
  arelent *tblptr = section->relocation;
5398
355
  unsigned int count = 0;
5399
5400
355
  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
355
  else
5414
355
    {
5415
355
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
259
  return -1;
5417
5418
96
      tblptr = section->relocation;
5419
5420
1.71k
      for (; count++ < section->reloc_count;)
5421
1.62k
  *relptr++ = tblptr++;
5422
96
    }
5423
96
  *relptr = 0;
5424
96
  return section->reloc_count;
5425
355
}
pei-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
57
{
5397
57
  arelent *tblptr = section->relocation;
5398
57
  unsigned int count = 0;
5399
5400
57
  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
57
  else
5414
57
    {
5415
57
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
57
      tblptr = section->relocation;
5419
5420
67
      for (; count++ < section->reloc_count;)
5421
10
  *relptr++ = tblptr++;
5422
57
    }
5423
57
  *relptr = 0;
5424
57
  return section->reloc_count;
5425
57
}
coff-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5396
8.08k
{
5397
8.08k
  arelent *tblptr = section->relocation;
5398
8.08k
  unsigned int count = 0;
5399
5400
8.08k
  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
8.08k
  else
5414
8.08k
    {
5415
8.08k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
7.25k
  return -1;
5417
5418
832
      tblptr = section->relocation;
5419
5420
3.89k
      for (; count++ < section->reloc_count;)
5421
3.05k
  *relptr++ = tblptr++;
5422
832
    }
5423
832
  *relptr = 0;
5424
832
  return section->reloc_count;
5425
8.08k
}
coff64-rs6000.c:coff_canonicalize_reloc
Line
Count
Source
5396
996
{
5397
996
  arelent *tblptr = section->relocation;
5398
996
  unsigned int count = 0;
5399
5400
996
  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
996
  else
5414
996
    {
5415
996
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
985
  return -1;
5417
5418
11
      tblptr = section->relocation;
5419
5420
11
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
11
    }
5423
11
  *relptr = 0;
5424
11
  return section->reloc_count;
5425
996
}
pe-aarch64.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
456
  return -1;
5417
5418
100
      tblptr = section->relocation;
5419
5420
316
      for (; count++ < section->reloc_count;)
5421
216
  *relptr++ = tblptr++;
5422
100
    }
5423
100
  *relptr = 0;
5424
100
  return section->reloc_count;
5425
556
}
pei-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5396
26
{
5397
26
  arelent *tblptr = section->relocation;
5398
26
  unsigned int count = 0;
5399
5400
26
  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
26
  else
5414
26
    {
5415
26
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
26
      tblptr = section->relocation;
5419
5420
42
      for (; count++ < section->reloc_count;)
5421
16
  *relptr++ = tblptr++;
5422
26
    }
5423
26
  *relptr = 0;
5424
26
  return section->reloc_count;
5425
26
}
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
19
{
5397
19
  arelent *tblptr = section->relocation;
5398
19
  unsigned int count = 0;
5399
5400
19
  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
19
  else
5414
19
    {
5415
19
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
19
      tblptr = section->relocation;
5419
5420
37
      for (; count++ < section->reloc_count;)
5421
18
  *relptr++ = tblptr++;
5422
19
    }
5423
19
  *relptr = 0;
5424
19
  return section->reloc_count;
5425
19
}
pei-riscv64.c:coff_canonicalize_reloc
Line
Count
Source
5396
23
{
5397
23
  arelent *tblptr = section->relocation;
5398
23
  unsigned int count = 0;
5399
5400
23
  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
23
  else
5414
23
    {
5415
23
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
23
      tblptr = section->relocation;
5419
5420
42
      for (; count++ < section->reloc_count;)
5421
19
  *relptr++ = tblptr++;
5422
23
    }
5423
23
  *relptr = 0;
5424
23
  return section->reloc_count;
5425
23
}
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
1.35k
{
5397
1.35k
  arelent *tblptr = section->relocation;
5398
1.35k
  unsigned int count = 0;
5399
5400
1.35k
  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.35k
  else
5414
1.35k
    {
5415
1.35k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
1.34k
  return -1;
5417
5418
8
      tblptr = section->relocation;
5419
5420
8
      for (; count++ < section->reloc_count;)
5421
0
  *relptr++ = tblptr++;
5422
8
    }
5423
8
  *relptr = 0;
5424
8
  return section->reloc_count;
5425
1.35k
}
coff-sh.c:coff_canonicalize_reloc
Line
Count
Source
5396
2.58k
{
5397
2.58k
  arelent *tblptr = section->relocation;
5398
2.58k
  unsigned int count = 0;
5399
5400
2.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
2.58k
  else
5414
2.58k
    {
5415
2.58k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
2.44k
  return -1;
5417
5418
146
      tblptr = section->relocation;
5419
5420
617
      for (; count++ < section->reloc_count;)
5421
471
  *relptr++ = tblptr++;
5422
146
    }
5423
146
  *relptr = 0;
5424
146
  return section->reloc_count;
5425
2.58k
}
Unexecuted instantiation: coff-stgo32.c:coff_canonicalize_reloc
coff-tic30.c:coff_canonicalize_reloc
Line
Count
Source
5396
5.58k
{
5397
5.58k
  arelent *tblptr = section->relocation;
5398
5.58k
  unsigned int count = 0;
5399
5400
5.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
5.58k
  else
5414
5.58k
    {
5415
5.58k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
5.53k
  return -1;
5417
5418
52
      tblptr = section->relocation;
5419
5420
92
      for (; count++ < section->reloc_count;)
5421
40
  *relptr++ = tblptr++;
5422
52
    }
5423
52
  *relptr = 0;
5424
52
  return section->reloc_count;
5425
5.58k
}
Unexecuted instantiation: coff-tic4x.c:coff_canonicalize_reloc
coff-tic54x.c:coff_canonicalize_reloc
Line
Count
Source
5396
3.52k
{
5397
3.52k
  arelent *tblptr = section->relocation;
5398
3.52k
  unsigned int count = 0;
5399
5400
3.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
3.52k
  else
5414
3.52k
    {
5415
3.52k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
3.45k
  return -1;
5417
5418
68
      tblptr = section->relocation;
5419
5420
89
      for (; count++ < section->reloc_count;)
5421
21
  *relptr++ = tblptr++;
5422
68
    }
5423
68
  *relptr = 0;
5424
68
  return section->reloc_count;
5425
3.52k
}
coff-z80.c:coff_canonicalize_reloc
Line
Count
Source
5396
4.73k
{
5397
4.73k
  arelent *tblptr = section->relocation;
5398
4.73k
  unsigned int count = 0;
5399
5400
4.73k
  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
4.73k
  else
5414
4.73k
    {
5415
4.73k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
4.65k
  return -1;
5417
5418
81
      tblptr = section->relocation;
5419
5420
2.66k
      for (; count++ < section->reloc_count;)
5421
2.58k
  *relptr++ = tblptr++;
5422
81
    }
5423
81
  *relptr = 0;
5424
81
  return section->reloc_count;
5425
4.73k
}
coff-z8k.c:coff_canonicalize_reloc
Line
Count
Source
5396
3.97k
{
5397
3.97k
  arelent *tblptr = section->relocation;
5398
3.97k
  unsigned int count = 0;
5399
5400
3.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
3.97k
  else
5414
3.97k
    {
5415
3.97k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
3.96k
  return -1;
5417
5418
9
      tblptr = section->relocation;
5419
5420
12
      for (; count++ < section->reloc_count;)
5421
3
  *relptr++ = tblptr++;
5422
9
    }
5423
9
  *relptr = 0;
5424
9
  return section->reloc_count;
5425
3.97k
}
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
33
{
5397
33
  arelent *tblptr = section->relocation;
5398
33
  unsigned int count = 0;
5399
5400
33
  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
33
  else
5414
33
    {
5415
33
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
19
  return -1;
5417
5418
14
      tblptr = section->relocation;
5419
5420
190
      for (; count++ < section->reloc_count;)
5421
176
  *relptr++ = tblptr++;
5422
14
    }
5423
14
  *relptr = 0;
5424
14
  return section->reloc_count;
5425
33
}
pe-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5396
101
{
5397
101
  arelent *tblptr = section->relocation;
5398
101
  unsigned int count = 0;
5399
5400
101
  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
101
  else
5414
101
    {
5415
101
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
72
  return -1;
5417
5418
29
      tblptr = section->relocation;
5419
5420
447
      for (; count++ < section->reloc_count;)
5421
418
  *relptr++ = tblptr++;
5422
29
    }
5423
29
  *relptr = 0;
5424
29
  return section->reloc_count;
5425
101
}
pe-sh.c:coff_canonicalize_reloc
Line
Count
Source
5396
106
{
5397
106
  arelent *tblptr = section->relocation;
5398
106
  unsigned int count = 0;
5399
5400
106
  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
106
  else
5414
106
    {
5415
106
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
100
  return -1;
5417
5418
6
      tblptr = section->relocation;
5419
5420
175
      for (; count++ < section->reloc_count;)
5421
169
  *relptr++ = tblptr++;
5422
6
    }
5423
6
  *relptr = 0;
5424
6
  return section->reloc_count;
5425
106
}
Unexecuted instantiation: pei-arm-wince.c:coff_canonicalize_reloc
pei-arm.c:coff_canonicalize_reloc
Line
Count
Source
5396
9
{
5397
9
  arelent *tblptr = section->relocation;
5398
9
  unsigned int count = 0;
5399
5400
9
  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
  else
5414
9
    {
5415
9
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
9
      tblptr = section->relocation;
5419
5420
13
      for (; count++ < section->reloc_count;)
5421
4
  *relptr++ = tblptr++;
5422
9
    }
5423
9
  *relptr = 0;
5424
9
  return section->reloc_count;
5425
9
}
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
23
{
5397
23
  arelent *tblptr = section->relocation;
5398
23
  unsigned int count = 0;
5399
5400
23
  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
23
  else
5414
23
    {
5415
23
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5416
0
  return -1;
5417
5418
23
      tblptr = section->relocation;
5419
5420
46
      for (; count++ < section->reloc_count;)
5421
23
  *relptr++ = tblptr++;
5422
23
    }
5423
23
  *relptr = 0;
5424
23
  return section->reloc_count;
5425
23
}
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
4.89M
{
5711
4.89M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
4.89M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
4.89M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
4.89M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
4.89M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
4.89M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
4.89M
  filehdr_dst->f_symptr =
5719
4.89M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
4.89M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
4.89M
  filehdr_dst->f_opthdr = 0;
5722
4.89M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
4.89M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
4.89M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
4.89M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
4.89M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
4.89M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
4.89M
}
pe-x86_64.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5710
2.45M
{
5711
2.45M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
2.45M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
2.45M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
2.45M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
2.45M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
2.45M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
2.45M
  filehdr_dst->f_symptr =
5719
2.45M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
2.45M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
2.45M
  filehdr_dst->f_opthdr = 0;
5722
2.45M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
2.45M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
2.45M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
2.45M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
2.45M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
2.45M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
2.45M
}
pe-i386.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5710
2.44M
{
5711
2.44M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5712
2.44M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5713
2.44M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5714
5715
2.44M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5716
2.44M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5717
2.44M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5718
2.44M
  filehdr_dst->f_symptr =
5719
2.44M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5720
2.44M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5721
2.44M
  filehdr_dst->f_opthdr = 0;
5722
2.44M
  filehdr_dst->f_flags  = 0;
5723
5724
  /* Check other magic numbers.  */
5725
2.44M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5726
2.44M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5727
2.44M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5728
2.44M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5729
2.44M
    filehdr_dst->f_opthdr = 0xffff;
5730
5731
  /* Note that CLR metadata are ignored.  */
5732
2.44M
}
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
64.0k
{
5760
64.0k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
64.0k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
64.0k
  if (ext->e.e_name[0] == 0)
5764
44.8k
    {
5765
44.8k
      in->_n._n_n._n_zeroes = 0;
5766
44.8k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
44.8k
    }
5768
19.2k
  else
5769
19.2k
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
19.2k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
19.2k
#endif
5775
19.2k
    }
5776
5777
64.0k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
64.0k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
64.0k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
64.0k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
64.0k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
64.0k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
64.0k
}
pe-x86_64.c:coff_bigobj_swap_sym_in
Line
Count
Source
5759
62.8k
{
5760
62.8k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
62.8k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
62.8k
  if (ext->e.e_name[0] == 0)
5764
44.3k
    {
5765
44.3k
      in->_n._n_n._n_zeroes = 0;
5766
44.3k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
44.3k
    }
5768
18.5k
  else
5769
18.5k
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
18.5k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
18.5k
#endif
5775
18.5k
    }
5776
5777
62.8k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
62.8k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
62.8k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
62.8k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
62.8k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
62.8k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
62.8k
}
pe-i386.c:coff_bigobj_swap_sym_in
Line
Count
Source
5759
1.21k
{
5760
1.21k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5761
1.21k
  struct internal_syment *in = (struct internal_syment *) in1;
5762
5763
1.21k
  if (ext->e.e_name[0] == 0)
5764
484
    {
5765
484
      in->_n._n_n._n_zeroes = 0;
5766
484
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5767
484
    }
5768
726
  else
5769
726
    {
5770
#if SYMNMLEN != E_SYMNMLEN
5771
#error we need to cope with truncating or extending SYMNMLEN
5772
#else
5773
726
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5774
726
#endif
5775
726
    }
5776
5777
1.21k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5778
1.21k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5779
1.21k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5780
1.21k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5781
1.21k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5782
1.21k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5783
1.21k
}
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
533k
{
5824
533k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
533k
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
533k
  memset (in, 0, sizeof * in);
5830
533k
  switch (in_class)
5831
533k
    {
5832
2.55k
    case C_FILE:
5833
2.55k
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
2.55k
      break;
5835
5836
1.74k
    case C_STAT:
5837
2.48k
    case C_LEAFSTAT:
5838
3.34k
    case C_HIDDEN:
5839
3.34k
      if (type == T_NULL)
5840
989
  {
5841
989
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
989
    in->x_scn.x_nreloc =
5843
989
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
989
    in->x_scn.x_nlinno =
5845
989
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
989
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
989
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
989
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
989
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
989
    return;
5851
989
  }
5852
2.36k
      break;
5853
5854
527k
    default:
5855
527k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
527k
      break;
5858
533k
    }
5859
533k
}
pe-x86_64.c:coff_bigobj_swap_aux_in
Line
Count
Source
5823
533k
{
5824
533k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
533k
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
533k
  memset (in, 0, sizeof * in);
5830
533k
  switch (in_class)
5831
533k
    {
5832
2.55k
    case C_FILE:
5833
2.55k
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
2.55k
      break;
5835
5836
1.74k
    case C_STAT:
5837
2.48k
    case C_LEAFSTAT:
5838
3.34k
    case C_HIDDEN:
5839
3.34k
      if (type == T_NULL)
5840
989
  {
5841
989
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
989
    in->x_scn.x_nreloc =
5843
989
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
989
    in->x_scn.x_nlinno =
5845
989
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
989
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
989
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
989
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
989
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
989
    return;
5851
989
  }
5852
2.36k
      break;
5853
5854
527k
    default:
5855
527k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
527k
      break;
5858
533k
    }
5859
533k
}
pe-i386.c:coff_bigobj_swap_aux_in
Line
Count
Source
5823
50
{
5824
50
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5825
50
  union internal_auxent *in = (union internal_auxent *) in1;
5826
5827
  /* Make sure that all fields in the aux structure are
5828
     initialised.  */
5829
50
  memset (in, 0, sizeof * in);
5830
50
  switch (in_class)
5831
50
    {
5832
0
    case C_FILE:
5833
0
      memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5834
0
      break;
5835
5836
0
    case C_STAT:
5837
0
    case C_LEAFSTAT:
5838
0
    case C_HIDDEN:
5839
0
      if (type == T_NULL)
5840
0
  {
5841
0
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5842
0
    in->x_scn.x_nreloc =
5843
0
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5844
0
    in->x_scn.x_nlinno =
5845
0
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5846
0
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5847
0
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5848
0
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5849
0
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5850
0
    return;
5851
0
  }
5852
0
      break;
5853
5854
50
    default:
5855
50
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5856
      /* Characteristics is ignored.  */
5857
50
      break;
5858
50
    }
5859
50
}
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
};