Coverage Report

Created: 2023-08-28 06:30

/src/binutils-gdb/bfd/coffcode.h
Line
Count
Source (jump to first uncovered line)
1
/* Support for the generic parts of most COFF variants, for BFD.
2
   Copyright (C) 1990-2023 Free Software Foundation, Inc.
3
   Written by Cygnus Support.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
/* Most of this hacked by  Steve Chamberlain,
23
      sac@cygnus.com.  */
24
/*
25
SECTION
26
  coff backends
27
28
  BFD supports a number of different flavours of coff format.
29
  The major differences between formats are the sizes and
30
  alignments of fields in structures on disk, and the occasional
31
  extra field.
32
33
  Coff in all its varieties is implemented with a few common
34
  files and a number of implementation specific files. For
35
  example, the i386 coff format is implemented in the file
36
  @file{coff-i386.c}.  This file @code{#include}s
37
  @file{coff/i386.h} which defines the external structure of the
38
  coff format for the i386, and @file{coff/internal.h} which
39
  defines the internal structure. @file{coff-i386.c} also
40
  defines the relocations used by the i386 coff format
41
  @xref{Relocations}.
42
43
SUBSECTION
44
  Porting to a new version of coff
45
46
  The recommended method is to select from the existing
47
  implementations the version of coff which is most like the one
48
  you want to use.  For example, we'll say that i386 coff is
49
  the one you select, and that your coff flavour is called foo.
50
  Copy @file{i386coff.c} to @file{foocoff.c}, copy
51
  @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
52
  and add the lines to @file{targets.c} and @file{Makefile.in}
53
  so that your new back end is used. Alter the shapes of the
54
  structures in @file{../include/coff/foo.h} so that they match
55
  what you need. You will probably also have to add
56
  @code{#ifdef}s to the code in @file{coff/internal.h} and
57
  @file{coffcode.h} if your version of coff is too wild.
58
59
  You can verify that your new BFD backend works quite simply by
60
  building @file{objdump} from the @file{binutils} directory,
61
  and making sure that its version of what's going on and your
62
  host system's idea (assuming it has the pretty standard coff
63
  dump utility, usually called @code{att-dump} or just
64
  @code{dump}) are the same.  Then clean up your code, and send
65
  what you've done to Cygnus. Then your stuff will be in the
66
  next release, and you won't have to keep integrating it.
67
68
SUBSECTION
69
  How the coff backend works
70
71
SUBSUBSECTION
72
  File layout
73
74
  The Coff backend is split into generic routines that are
75
  applicable to any Coff target and routines that are specific
76
  to a particular target.  The target-specific routines are
77
  further split into ones which are basically the same for all
78
  Coff targets except that they use the external symbol format
79
  or use different values for certain constants.
80
81
  The generic routines are in @file{coffgen.c}.  These routines
82
  work for any Coff target.  They use some hooks into the target
83
  specific code; the hooks are in a @code{bfd_coff_backend_data}
84
  structure, one of which exists for each target.
85
86
  The essentially similar target-specific routines are in
87
  @file{coffcode.h}.  This header file includes executable C code.
88
  The various Coff targets first include the appropriate Coff
89
  header file, make any special defines that are needed, and
90
  then include @file{coffcode.h}.
91
92
  Some of the Coff targets then also have additional routines in
93
  the target source file itself.
94
95
SUBSUBSECTION
96
  Coff long section names
97
98
  In the standard Coff object format, section names are limited to
99
  the eight bytes available in the @code{s_name} field of the
100
  @code{SCNHDR} section header structure.  The format requires the
101
  field to be NUL-padded, but not necessarily NUL-terminated, so
102
  the longest section names permitted are a full eight characters.
103
104
  The Microsoft PE variants of the Coff object file format add
105
  an extension to support the use of long section names.  This
106
  extension is defined in section 4 of the Microsoft PE/COFF
107
  specification (rev 8.1).  If a section name is too long to fit
108
  into the section header's @code{s_name} field, it is instead
109
  placed into the string table, and the @code{s_name} field is
110
  filled with a slash ("/") followed by the ASCII decimal
111
  representation of the offset of the full name relative to the
112
  string table base.
113
114
  Note that this implies that the extension can only be used in object
115
  files, as executables do not contain a string table.  The standard
116
  specifies that long section names from objects emitted into executable
117
  images are to be truncated.
118
119
  However, as a GNU extension, BFD can generate executable images
120
  that contain a string table and long section names.  This
121
  would appear to be technically valid, as the standard only says
122
  that Coff debugging information is deprecated, not forbidden,
123
  and in practice it works, although some tools that parse PE files
124
  expecting the MS standard format may become confused; @file{PEview} is
125
  one known example.
126
127
  The functionality is supported in BFD by code implemented under
128
  the control of the macro @code{COFF_LONG_SECTION_NAMES}.  If not
129
  defined, the format does not support long section names in any way.
130
  If defined, it is used to initialise a flag,
131
  @code{_bfd_coff_long_section_names}, and a hook function pointer,
132
  @code{_bfd_coff_set_long_section_names}, in the Coff backend data
133
  structure.  The flag controls the generation of long section names
134
  in output BFDs at runtime; if it is false, as it will be by default
135
  when generating an executable image, long section names are truncated;
136
  if true, the long section names extension is employed.  The hook
137
  points to a function that allows the value of a copy of the flag
138
  in coff object tdata to be altered at runtime, on formats that
139
  support long section names at all; on other formats it points
140
  to a stub that returns an error indication.
141
142
  With input BFDs, the flag is set according to whether any long section
143
  names are detected while reading the section headers.  For a completely
144
  new BFD, the flag is set to the default for the target format.  This
145
  information can be used by a client of the BFD library when deciding
146
  what output format to generate, and means that a BFD that is opened
147
  for read and subsequently converted to a writeable BFD and modified
148
  in-place will retain whatever format it had on input.
149
150
  If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
151
  defined to the value "1", then long section names are enabled by
152
  default; if it is defined to the value zero, they are disabled by
153
  default (but still accepted in input BFDs).  The header @file{coffcode.h}
154
  defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
155
  used in the backends to initialise the backend data structure fields
156
  appropriately; see the comments for further detail.
157
158
SUBSUBSECTION
159
  Bit twiddling
160
161
  Each flavour of coff supported in BFD has its own header file
162
  describing the external layout of the structures. There is also
163
  an internal description of the coff layout, in
164
  @file{coff/internal.h}. A major function of the
165
  coff backend is swapping the bytes and twiddling the bits to
166
  translate the external form of the structures into the normal
167
  internal form. This is all performed in the
168
  @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
169
  elements are different sizes between different versions of
170
  coff; it is the duty of the coff version specific include file
171
  to override the definitions of various packing routines in
172
  @file{coffcode.h}. E.g., the size of line number entry in coff is
173
  sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
174
  @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
175
  correct one. No doubt, some day someone will find a version of
176
  coff which has a varying field size not catered to at the
177
  moment. To port BFD, that person will have to add more @code{#defines}.
178
  Three of the bit twiddling routines are exported to
179
  @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
180
  and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
181
  table on its own, but uses BFD to fix things up.  More of the
182
  bit twiddlers are exported for @code{gas};
183
  @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
184
  @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
185
  @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
186
  @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
187
  of all the symbol table and reloc drudgery itself, thereby
188
  saving the internal BFD overhead, but uses BFD to swap things
189
  on the way out, making cross ports much safer.  Doing so also
190
  allows BFD (and thus the linker) to use the same header files
191
  as @code{gas}, which makes one avenue to disaster disappear.
192
193
SUBSUBSECTION
194
  Symbol reading
195
196
  The simple canonical form for symbols used by BFD is not rich
197
  enough to keep all the information available in a coff symbol
198
  table. The back end gets around this problem by keeping the original
199
  symbol table around, "behind the scenes".
200
201
  When a symbol table is requested (through a call to
202
  @code{bfd_canonicalize_symtab}), a request gets through to
203
  @code{coff_get_normalized_symtab}. This reads the symbol table from
204
  the coff file and swaps all the structures inside into the
205
  internal form. It also fixes up all the pointers in the table
206
  (represented in the file by offsets from the first symbol in
207
  the table) into physical pointers to elements in the new
208
  internal table. This involves some work since the meanings of
209
  fields change depending upon context: a field that is a
210
  pointer to another structure in the symbol table at one moment
211
  may be the size in bytes of a structure at the next.  Another
212
  pass is made over the table. All symbols which mark file names
213
  (<<C_FILE>> symbols) are modified so that the internal
214
  string points to the value in the auxent (the real filename)
215
  rather than the normal text associated with the symbol
216
  (@code{".file"}).
217
218
  At this time the symbol names are moved around. Coff stores
219
  all symbols less than nine characters long physically
220
  within the symbol table; longer strings are kept at the end of
221
  the file in the string table. This pass moves all strings
222
  into memory and replaces them with pointers to the strings.
223
224
  The symbol table is massaged once again, this time to create
225
  the canonical table used by the BFD application. Each symbol
226
  is inspected in turn, and a decision made (using the
227
  @code{sclass} field) about the various flags to set in the
228
  @code{asymbol}.  @xref{Symbols}. The generated canonical table
229
  shares strings with the hidden internal symbol table.
230
231
  Any linenumbers are read from the coff file too, and attached
232
  to the symbols which own the functions the linenumbers belong to.
233
234
SUBSUBSECTION
235
  Symbol writing
236
237
  Writing a symbol to a coff file which didn't come from a coff
238
  file will lose any debugging information. The @code{asymbol}
239
  structure remembers the BFD from which the symbol was taken, and on
240
  output the back end makes sure that the same destination target as
241
  source target is present.
242
243
  When the symbols have come from a coff file then all the
244
  debugging information is preserved.
245
246
  Symbol tables are provided for writing to the back end in a
247
  vector of pointers to pointers. This allows applications like
248
  the linker to accumulate and output large symbol tables
249
  without having to do too much byte copying.
250
251
  This function runs through the provided symbol table and
252
  patches each symbol marked as a file place holder
253
  (@code{C_FILE}) to point to the next file place holder in the
254
  list. It also marks each @code{offset} field in the list with
255
  the offset from the first symbol of the current symbol.
256
257
  Another function of this procedure is to turn the canonical
258
  value form of BFD into the form used by coff. Internally, BFD
259
  expects symbol values to be offsets from a section base; so a
260
  symbol physically at 0x120, but in a section starting at
261
  0x100, would have the value 0x20. Coff expects symbols to
262
  contain their final value, so symbols have their values
263
  changed at this point to reflect their sum with their owning
264
  section.  This transformation uses the
265
  <<output_section>> field of the @code{asymbol}'s
266
  @code{asection} @xref{Sections}.
267
268
  o <<coff_mangle_symbols>>
269
270
  This routine runs though the provided symbol table and uses
271
  the offsets generated by the previous pass and the pointers
272
  generated when the symbol table was read in to create the
273
  structured hierarchy required by coff. It changes each pointer
274
  to a symbol into the index into the symbol table of the asymbol.
275
276
  o <<coff_write_symbols>>
277
278
  This routine runs through the symbol table and patches up the
279
  symbols from their internal form into the coff way, calls the
280
  bit twiddlers, and writes out the table to the file.
281
282
*/
283
284
/*
285
INTERNAL_DEFINITION
286
  coff_symbol_type
287
288
DESCRIPTION
289
  The hidden information for an <<asymbol>> is described in a
290
  <<combined_entry_type>>:
291
292
CODE_FRAGMENT
293
.typedef struct coff_ptr_struct
294
.{
295
.  {* Remembers the offset from the first symbol in the file for
296
.     this symbol.  Generated by coff_renumber_symbols.  *}
297
.  unsigned int offset;
298
.
299
.  {* Selects between the elements of the union below.  *}
300
.  unsigned int is_sym : 1;
301
.
302
.  {* Selects between the elements of the x_sym.x_tagndx union.  If set,
303
.     p is valid and the field will be renumbered.  *}
304
.  unsigned int fix_tag : 1;
305
.
306
.  {* Selects between the elements of the x_sym.x_fcnary.x_fcn.x_endndx
307
.     union.  If set, p is valid and the field will be renumbered.  *}
308
.  unsigned int fix_end : 1;
309
.
310
.  {* Selects between the elements of the x_csect.x_scnlen union.  If set,
311
.     p is valid and the field will be renumbered.  *}
312
.  unsigned int fix_scnlen : 1;
313
.
314
.  {* If set, u.syment.n_value contains a pointer to a symbol.  The final
315
.     value will be the offset field.  Used for XCOFF C_BSTAT symbols.  *}
316
.  unsigned int fix_value : 1;
317
.
318
.  {* If set, u.syment.n_value is an index into the line number entries.
319
.     Used for XCOFF C_BINCL/C_EINCL symbols.  *}
320
.  unsigned int fix_line : 1;
321
.
322
.  {* The container for the symbol structure as read and translated
323
.     from the file.  *}
324
.  union
325
.  {
326
.    union internal_auxent auxent;
327
.    struct internal_syment syment;
328
.  } u;
329
.
330
. {* An extra pointer which can used by format based on COFF (like XCOFF)
331
.    to provide extra information to their backend.  *}
332
. void *extrap;
333
.} combined_entry_type;
334
.
335
.{* Each canonical asymbol really looks like this: *}
336
.
337
.typedef struct coff_symbol_struct
338
.{
339
.  {* The actual symbol which the rest of BFD works with *}
340
.  asymbol symbol;
341
.
342
.  {* A pointer to the hidden information for this symbol *}
343
.  combined_entry_type *native;
344
.
345
.  {* A pointer to the linenumber information for this symbol *}
346
.  struct lineno_cache_entry *lineno;
347
.
348
.  {* Have the line numbers been relocated yet ? *}
349
.  bool done_lineno;
350
.} coff_symbol_type;
351
.
352
*/
353
354
#include "libiberty.h"
355
#include <string.h>
356
357
#ifdef COFF_WITH_PE
358
#include "peicode.h"
359
#else
360
#include "coffswap.h"
361
#endif
362
363
0
#define STRING_SIZE_SIZE 4
364
365
111k
#define DOT_DEBUG ".debug"
366
111k
#define DOT_ZDEBUG  ".zdebug"
367
33.1k
#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
368
33.1k
#define GNU_LINKONCE_WT ".gnu.linkonce.wt."
369
0
#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
38.8k
{
411
38.8k
  bfd_coff_long_section_names (abfd) = enable;
412
38.8k
  return true;
413
38.8k
}
pei-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.17k
{
411
1.17k
  bfd_coff_long_section_names (abfd) = enable;
412
1.17k
  return true;
413
1.17k
}
pe-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.96k
{
411
1.96k
  bfd_coff_long_section_names (abfd) = enable;
412
1.96k
  return true;
413
1.96k
}
pei-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
951
{
411
951
  bfd_coff_long_section_names (abfd) = enable;
412
951
  return true;
413
951
}
pe-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
2.30k
{
411
2.30k
  bfd_coff_long_section_names (abfd) = enable;
412
2.30k
  return true;
413
2.30k
}
pei-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
15.0k
{
411
15.0k
  bfd_coff_long_section_names (abfd) = enable;
412
15.0k
  return true;
413
15.0k
}
pei-ia64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
2.44k
{
411
2.44k
  bfd_coff_long_section_names (abfd) = enable;
412
2.44k
  return true;
413
2.44k
}
pei-loongarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
673
{
411
673
  bfd_coff_long_section_names (abfd) = enable;
412
673
  return true;
413
673
}
coff-go32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
6.18k
{
411
6.18k
  bfd_coff_long_section_names (abfd) = enable;
412
6.18k
  return true;
413
6.18k
}
coff-stgo32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.93k
{
411
1.93k
  bfd_coff_long_section_names (abfd) = enable;
412
1.93k
  return true;
413
1.93k
}
pe-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
119
{
411
119
  bfd_coff_long_section_names (abfd) = enable;
412
119
  return true;
413
119
}
pe-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
119
{
411
119
  bfd_coff_long_section_names (abfd) = enable;
412
119
  return true;
413
119
}
pe-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
2.03k
{
411
2.03k
  bfd_coff_long_section_names (abfd) = enable;
412
2.03k
  return true;
413
2.03k
}
pe-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
540
{
411
540
  bfd_coff_long_section_names (abfd) = enable;
412
540
  return true;
413
540
}
pe-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
287
{
411
287
  bfd_coff_long_section_names (abfd) = enable;
412
287
  return true;
413
287
}
pei-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
337
{
411
337
  bfd_coff_long_section_names (abfd) = enable;
412
337
  return true;
413
337
}
pei-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
1.03k
{
411
1.03k
  bfd_coff_long_section_names (abfd) = enable;
412
1.03k
  return true;
413
1.03k
}
pei-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
851
{
411
851
  bfd_coff_long_section_names (abfd) = enable;
412
851
  return true;
413
851
}
pei-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
797
{
411
797
  bfd_coff_long_section_names (abfd) = enable;
412
797
  return true;
413
797
}
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
167k
{
419
167k
  return false;
420
167k
}
coff-x86_64.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
6.18k
{
419
6.18k
  return false;
420
6.18k
}
coff64-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
2.70k
{
419
2.70k
  return false;
420
2.70k
}
cf-i386lynx.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
9.20k
{
419
9.20k
  return false;
420
9.20k
}
coff-i386.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
7.30k
{
419
7.30k
  return false;
420
7.30k
}
coff-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
2.14k
{
419
2.14k
  return false;
420
2.14k
}
coff-sh.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
10.6k
{
419
10.6k
  return false;
420
10.6k
}
coff-tic30.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
110k
{
419
110k
  return false;
420
110k
}
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
11.4k
{
419
11.4k
  return false;
420
11.4k
}
coff-z80.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
2.51k
{
419
2.51k
  return false;
420
2.51k
}
coff-z8k.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
4.89k
{
419
4.89k
  return false;
420
4.89k
}
421
#endif /* defined (COFF_LONG_SECTION_NAMES) */
422
423
/* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
424
   the incoming SEC_* flags.  The inverse of this function is
425
   styp_to_sec_flags().  NOTE: If you add to/change this routine, you
426
   should probably mirror the changes in styp_to_sec_flags().  */
427
428
#ifndef COFF_WITH_PE
429
430
/* Macros for setting debugging flags.  */
431
432
#ifdef STYP_DEBUG
433
0
#define STYP_XCOFF_DEBUG STYP_DEBUG
434
#else
435
0
#define STYP_XCOFF_DEBUG STYP_INFO
436
#endif
437
438
#ifdef COFF_ALIGN_IN_S_FLAGS
439
0
#define STYP_DEBUG_INFO STYP_DSECT
440
#else
441
0
#define STYP_DEBUG_INFO STYP_INFO
442
#endif
443
444
static long
445
sec_to_styp_flags (const char *sec_name, flagword sec_flags)
446
0
{
447
0
  long styp_flags = 0;
448
449
0
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
0
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
0
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
#ifdef _COMMENT
461
    }
462
0
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
#endif /* _COMMENT */
466
#ifdef _LIB
467
    }
468
0
  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
0
  else if (startswith (sec_name, DOT_DEBUG)
480
0
     || 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
0
  else if (startswith (sec_name, ".stab"))
489
0
    {
490
0
      styp_flags = STYP_DEBUG_INFO;
491
0
    }
492
#ifdef COFF_LONG_SECTION_NAMES
493
0
  else if (startswith (sec_name, GNU_LINKONCE_WI)
494
0
     || startswith (sec_name, GNU_LINKONCE_WT))
495
0
    {
496
0
      styp_flags = STYP_DEBUG_INFO;
497
0
    }
498
0
#endif
499
#ifdef RS6000COFF_C
500
0
  else if (!strcmp (sec_name, _TDATA))
501
0
    {
502
0
      styp_flags = STYP_TDATA;
503
0
    }
504
0
  else if (!strcmp (sec_name, _TBSS))
505
0
    {
506
0
      styp_flags = STYP_TBSS;
507
0
    }
508
0
  else if (!strcmp (sec_name, _PAD))
509
0
    {
510
0
      styp_flags = STYP_PAD;
511
0
    }
512
0
  else if (!strcmp (sec_name, _LOADER))
513
0
    {
514
0
      styp_flags = STYP_LOADER;
515
0
    }
516
0
  else if (!strcmp (sec_name, _EXCEPT))
517
0
    {
518
0
      styp_flags = STYP_EXCEPT;
519
0
    }
520
0
  else if (!strcmp (sec_name, _TYPCHK))
521
0
    {
522
0
      styp_flags = STYP_TYPCHK;
523
0
    }
524
0
  else if (sec_flags & SEC_DEBUGGING)
525
0
    {
526
0
      int i;
527
528
0
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
529
0
  if (!strcmp (sec_name, xcoff_dwsect_names[i].xcoff_name))
530
0
    {
531
0
      styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
532
0
      break;
533
0
    }
534
0
    }
535
0
#endif
536
  /* Try and figure out what it should be */
537
0
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
0
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
0
  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
0
  else if (sec_flags & SEC_LOAD)
554
0
    {
555
0
      styp_flags = STYP_TEXT;
556
0
    }
557
0
  else if (sec_flags & SEC_ALLOC)
558
0
    {
559
0
      styp_flags = STYP_BSS;
560
0
    }
561
562
#ifdef STYP_CLINK
563
0
  if (sec_flags & SEC_TIC54X_CLINK)
564
0
    styp_flags |= STYP_CLINK;
565
#endif
566
567
#ifdef STYP_BLOCK
568
0
  if (sec_flags & SEC_TIC54X_BLOCK)
569
0
    styp_flags |= STYP_BLOCK;
570
#endif
571
572
0
#ifdef STYP_NOLOAD
573
0
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
0
#endif
576
577
0
  return styp_flags;
578
0
}
Unexecuted instantiation: coff-x86_64.c:sec_to_styp_flags
Unexecuted instantiation: coff64-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: cf-i386lynx.c:sec_to_styp_flags
Unexecuted instantiation: coff-go32.c:sec_to_styp_flags
Unexecuted instantiation: coff-i386.c:sec_to_styp_flags
Unexecuted instantiation: coff-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: coff-sh.c:sec_to_styp_flags
Unexecuted instantiation: coff-stgo32.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic30.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic4x.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic54x.c:sec_to_styp_flags
Unexecuted instantiation: coff-z80.c:sec_to_styp_flags
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
0
{
591
0
  long styp_flags = 0;
592
0
  bool is_dbg = false;
593
594
0
  if (startswith (sec_name, DOT_DEBUG)
595
0
      || startswith (sec_name, DOT_ZDEBUG)
596
0
#ifdef COFF_LONG_SECTION_NAMES
597
0
      || startswith (sec_name, GNU_LINKONCE_WI)
598
0
      || startswith (sec_name, GNU_LINKONCE_WT)
599
0
#endif
600
0
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
0
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
0
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
0
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
0
  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
0
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
0
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
0
  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
0
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
0
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
0
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
0
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
0
  return styp_flags;
670
0
}
Unexecuted instantiation: pei-i386.c:sec_to_styp_flags
Unexecuted instantiation: pe-x86_64.c:sec_to_styp_flags
Unexecuted instantiation: pei-x86_64.c:sec_to_styp_flags
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
Unexecuted instantiation: pei-loongarch64.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm-wince.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm.c:sec_to_styp_flags
Unexecuted instantiation: pe-i386.c:sec_to_styp_flags
Unexecuted instantiation: pe-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pe-sh.c:sec_to_styp_flags
Unexecuted instantiation: pei-arm-wince.c:sec_to_styp_flags
Unexecuted instantiation: pei-arm.c:sec_to_styp_flags
Unexecuted instantiation: pei-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pei-sh.c:sec_to_styp_flags
671
672
#endif /* COFF_WITH_PE */
673
674
/* Return a word with SEC_* flags set to represent the incoming STYP_*
675
   flags (from scnhdr.s_flags).  The inverse of this function is
676
   sec_to_styp_flags().  NOTE: If you add to/change this routine, you
677
   should probably mirror the changes in sec_to_styp_flags().  */
678
679
#ifndef COFF_WITH_PE
680
681
static bool
682
styp_to_sec_flags (bfd *abfd,
683
       void * hdr,
684
       const char *name,
685
       asection *section ATTRIBUTE_UNUSED,
686
       flagword *flags_ptr)
687
175k
{
688
175k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
175k
  unsigned long styp_flags = internal_s->s_flags;
690
175k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
11.4k
  if (styp_flags & STYP_BLOCK)
694
3.90k
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
11.4k
  if (styp_flags & STYP_CLINK)
699
4.29k
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
175k
#ifdef STYP_NOLOAD
703
175k
  if (styp_flags & STYP_NOLOAD)
704
53.0k
    sec_flags |= SEC_NEVER_LOAD;
705
175k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
175k
  if (styp_flags & STYP_TEXT)
710
43.8k
    {
711
43.8k
      if (sec_flags & SEC_NEVER_LOAD)
712
24.5k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
19.2k
      else
714
19.2k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
43.8k
    }
716
131k
  else if (styp_flags & STYP_DATA)
717
23.0k
    {
718
23.0k
      if (sec_flags & SEC_NEVER_LOAD)
719
13.6k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
9.38k
      else
721
9.38k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
23.0k
    }
723
108k
  else if (styp_flags & STYP_BSS)
724
8.09k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
2.22k
      if (sec_flags & SEC_NEVER_LOAD)
727
1.17k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
1.05k
      else
729
1.05k
#endif
730
6.92k
  sec_flags |= SEC_ALLOC;
731
8.09k
    }
732
100k
  else if (styp_flags & STYP_INFO)
733
14.6k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
2.05k
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
14.6k
    }
744
85.7k
  else if (styp_flags & STYP_PAD)
745
4.16k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
1.82k
  else if (styp_flags & STYP_TDATA)
748
139
    {
749
139
      if (sec_flags & SEC_NEVER_LOAD)
750
27
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
112
      else
752
112
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
139
    }
754
1.68k
  else if (styp_flags & STYP_TBSS)
755
50
    {
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
50
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
50
    }
763
1.63k
  else if (styp_flags & STYP_EXCEPT)
764
123
    sec_flags |= SEC_LOAD;
765
1.51k
  else if (styp_flags & STYP_LOADER)
766
49
    sec_flags |= SEC_LOAD;
767
1.46k
  else if (styp_flags & STYP_TYPCHK)
768
15
    sec_flags |= SEC_LOAD;
769
1.45k
  else if (styp_flags & STYP_DWARF)
770
37
    sec_flags |= SEC_DEBUGGING;
771
1.41k
#endif
772
81.1k
  else if (strcmp (name, _TEXT) == 0)
773
12
    {
774
12
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
12
      else
777
12
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
12
    }
779
81.1k
  else if (strcmp (name, _DATA) == 0)
780
16
    {
781
16
      if (sec_flags & SEC_NEVER_LOAD)
782
12
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4
      else
784
4
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
16
    }
786
81.1k
  else if (strcmp (name, _BSS) == 0)
787
5
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
5
      if (sec_flags & SEC_NEVER_LOAD)
790
2
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
3
      else
792
3
#endif
793
3
  sec_flags |= SEC_ALLOC;
794
5
    }
795
81.1k
  else if (startswith (name, DOT_DEBUG)
796
81.1k
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
75.9k
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
2.67k
     || startswith (name, GNU_LINKONCE_WI)
802
2.67k
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
81.1k
     || startswith (name, ".stab"))
805
71
    {
806
#ifdef COFF_PAGE_SIZE
807
50
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
71
    }
810
#ifdef _LIB
811
75.9k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
75.9k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
75.9k
  else
819
81.0k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
175k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
175k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
20.6k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
175k
#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
175k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
175k
      && (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
8.07k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
175k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
175k
  * flags_ptr = sec_flags;
851
175k
  return true;
852
175k
}
coff-x86_64.c:styp_to_sec_flags
Line
Count
Source
687
6.18k
{
688
6.18k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
6.18k
  unsigned long styp_flags = internal_s->s_flags;
690
6.18k
  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.18k
#ifdef STYP_NOLOAD
703
6.18k
  if (styp_flags & STYP_NOLOAD)
704
1.69k
    sec_flags |= SEC_NEVER_LOAD;
705
6.18k
#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.18k
  if (styp_flags & STYP_TEXT)
710
1.63k
    {
711
1.63k
      if (sec_flags & SEC_NEVER_LOAD)
712
856
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
776
      else
714
776
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.63k
    }
716
4.54k
  else if (styp_flags & STYP_DATA)
717
547
    {
718
547
      if (sec_flags & SEC_NEVER_LOAD)
719
277
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
270
      else
721
270
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
547
    }
723
4.00k
  else if (styp_flags & STYP_BSS)
724
371
    {
725
371
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
371
      if (sec_flags & SEC_NEVER_LOAD)
727
192
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
179
      else
729
179
#endif
730
179
  sec_flags |= SEC_ALLOC;
731
371
    }
732
3.63k
  else if (styp_flags & STYP_INFO)
733
432
    {
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
432
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
432
      sec_flags |= SEC_DEBUGGING;
742
432
#endif
743
432
    }
744
3.19k
  else if (styp_flags & STYP_PAD)
745
213
    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.98k
  else if (strcmp (name, _TEXT) == 0)
773
3
    {
774
3
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3
      else
777
3
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
3
    }
779
2.98k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
2.98k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
0
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
0
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
0
      else
792
0
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
2.98k
  else if (startswith (name, DOT_DEBUG)
796
2.98k
     || startswith (name, DOT_ZDEBUG)
797
2.98k
#ifdef _COMMENT
798
2.98k
     || strcmp (name, _COMMENT) == 0
799
2.98k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.98k
     || startswith (name, ".stab"))
805
8
    {
806
8
#ifdef COFF_PAGE_SIZE
807
8
      sec_flags |= SEC_DEBUGGING;
808
8
#endif
809
8
    }
810
2.97k
#ifdef _LIB
811
2.97k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
2.97k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.97k
  else
819
2.97k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
6.18k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
6.18k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
565
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
6.18k
#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.18k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
6.18k
      && (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.18k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
6.18k
  * flags_ptr = sec_flags;
851
6.18k
  return true;
852
6.18k
}
coff64-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
2.70k
{
688
2.70k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
2.70k
  unsigned long styp_flags = internal_s->s_flags;
690
2.70k
  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.70k
#ifdef STYP_NOLOAD
703
2.70k
  if (styp_flags & STYP_NOLOAD)
704
637
    sec_flags |= SEC_NEVER_LOAD;
705
2.70k
#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.70k
  if (styp_flags & STYP_TEXT)
710
592
    {
711
592
      if (sec_flags & SEC_NEVER_LOAD)
712
288
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
304
      else
714
304
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
592
    }
716
2.11k
  else if (styp_flags & STYP_DATA)
717
287
    {
718
287
      if (sec_flags & SEC_NEVER_LOAD)
719
149
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
138
      else
721
138
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
287
    }
723
1.82k
  else if (styp_flags & STYP_BSS)
724
162
    {
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
162
  sec_flags |= SEC_ALLOC;
731
162
    }
732
1.66k
  else if (styp_flags & STYP_INFO)
733
748
    {
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
748
    }
744
914
  else if (styp_flags & STYP_PAD)
745
49
    sec_flags = 0;
746
865
#ifdef RS6000COFF_C
747
865
  else if (styp_flags & STYP_TDATA)
748
34
    {
749
34
      if (sec_flags & SEC_NEVER_LOAD)
750
4
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
30
      else
752
30
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
34
    }
754
831
  else if (styp_flags & STYP_TBSS)
755
23
    {
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
23
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
23
    }
763
808
  else if (styp_flags & STYP_EXCEPT)
764
66
    sec_flags |= SEC_LOAD;
765
742
  else if (styp_flags & STYP_LOADER)
766
29
    sec_flags |= SEC_LOAD;
767
713
  else if (styp_flags & STYP_TYPCHK)
768
8
    sec_flags |= SEC_LOAD;
769
705
  else if (styp_flags & STYP_DWARF)
770
18
    sec_flags |= SEC_DEBUGGING;
771
687
#endif
772
687
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
687
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
687
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
687
  else if (startswith (name, DOT_DEBUG)
796
687
     || 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
687
     || startswith (name, ".stab"))
805
1
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
1
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
686
  else
819
686
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
2.70k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
2.70k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
284
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
2.70k
#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.70k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
2.70k
      && (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.70k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
2.70k
  * flags_ptr = sec_flags;
851
2.70k
  return true;
852
2.70k
}
cf-i386lynx.c:styp_to_sec_flags
Line
Count
Source
687
9.20k
{
688
9.20k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
9.20k
  unsigned long styp_flags = internal_s->s_flags;
690
9.20k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
9.20k
#ifdef STYP_NOLOAD
703
9.20k
  if (styp_flags & STYP_NOLOAD)
704
3.15k
    sec_flags |= SEC_NEVER_LOAD;
705
9.20k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
9.20k
  if (styp_flags & STYP_TEXT)
710
3.01k
    {
711
3.01k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.57k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.43k
      else
714
1.43k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.01k
    }
716
6.19k
  else if (styp_flags & STYP_DATA)
717
1.45k
    {
718
1.45k
      if (sec_flags & SEC_NEVER_LOAD)
719
725
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
730
      else
721
730
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.45k
    }
723
4.73k
  else if (styp_flags & STYP_BSS)
724
656
    {
725
656
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
656
      if (sec_flags & SEC_NEVER_LOAD)
727
345
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
311
      else
729
311
#endif
730
311
  sec_flags |= SEC_ALLOC;
731
656
    }
732
4.08k
  else if (styp_flags & STYP_INFO)
733
618
    {
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
618
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
618
      sec_flags |= SEC_DEBUGGING;
742
618
#endif
743
618
    }
744
3.46k
  else if (styp_flags & STYP_PAD)
745
255
    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.20k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
3.20k
  else if (strcmp (name, _DATA) == 0)
780
8
    {
781
8
      if (sec_flags & SEC_NEVER_LOAD)
782
6
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
2
      else
784
2
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
8
    }
786
3.20k
  else if (strcmp (name, _BSS) == 0)
787
2
    {
788
2
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
2
      if (sec_flags & SEC_NEVER_LOAD)
790
1
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
1
      else
792
1
#endif
793
1
  sec_flags |= SEC_ALLOC;
794
2
    }
795
3.19k
  else if (startswith (name, DOT_DEBUG)
796
3.19k
     || startswith (name, DOT_ZDEBUG)
797
3.19k
#ifdef _COMMENT
798
3.19k
     || strcmp (name, _COMMENT) == 0
799
3.19k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.19k
     || startswith (name, ".stab"))
805
20
    {
806
20
#ifdef COFF_PAGE_SIZE
807
20
      sec_flags |= SEC_DEBUGGING;
808
20
#endif
809
20
    }
810
3.17k
#ifdef _LIB
811
3.17k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
3.17k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.17k
  else
819
3.17k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
9.20k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
9.20k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.42k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
9.20k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
9.20k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
9.20k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
9.20k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
9.20k
  * flags_ptr = sec_flags;
851
9.20k
  return true;
852
9.20k
}
coff-go32.c:styp_to_sec_flags
Line
Count
Source
687
6.15k
{
688
6.15k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
6.15k
  unsigned long styp_flags = internal_s->s_flags;
690
6.15k
  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.15k
#ifdef STYP_NOLOAD
703
6.15k
  if (styp_flags & STYP_NOLOAD)
704
2.23k
    sec_flags |= SEC_NEVER_LOAD;
705
6.15k
#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.15k
  if (styp_flags & STYP_TEXT)
710
2.23k
    {
711
2.23k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.15k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.07k
      else
714
1.07k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.23k
    }
716
3.91k
  else if (styp_flags & STYP_DATA)
717
1.03k
    {
718
1.03k
      if (sec_flags & SEC_NEVER_LOAD)
719
460
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
577
      else
721
577
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.03k
    }
723
2.88k
  else if (styp_flags & STYP_BSS)
724
538
    {
725
538
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
538
      if (sec_flags & SEC_NEVER_LOAD)
727
289
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
249
      else
729
249
#endif
730
249
  sec_flags |= SEC_ALLOC;
731
538
    }
732
2.34k
  else if (styp_flags & STYP_INFO)
733
387
    {
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
387
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
387
      sec_flags |= SEC_DEBUGGING;
742
387
#endif
743
387
    }
744
1.95k
  else if (styp_flags & STYP_PAD)
745
150
    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.80k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
1.80k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
1.80k
  else if (strcmp (name, _BSS) == 0)
787
1
    {
788
1
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
1
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
1
      else
792
1
#endif
793
1
  sec_flags |= SEC_ALLOC;
794
1
    }
795
1.80k
  else if (startswith (name, DOT_DEBUG)
796
1.80k
     || startswith (name, DOT_ZDEBUG)
797
1.80k
#ifdef _COMMENT
798
1.80k
     || strcmp (name, _COMMENT) == 0
799
1.80k
#endif
800
1.80k
#ifdef COFF_LONG_SECTION_NAMES
801
1.80k
     || startswith (name, GNU_LINKONCE_WI)
802
1.80k
     || startswith (name, GNU_LINKONCE_WT)
803
1.80k
#endif
804
1.80k
     || startswith (name, ".stab"))
805
2
    {
806
2
#ifdef COFF_PAGE_SIZE
807
2
      sec_flags |= SEC_DEBUGGING;
808
2
#endif
809
2
    }
810
1.80k
#ifdef _LIB
811
1.80k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
1.80k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.80k
  else
819
1.80k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
6.15k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
6.15k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.09k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
6.15k
#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.15k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
6.15k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
6.15k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
6.15k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
6.15k
#endif
846
847
6.15k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
6.15k
  * flags_ptr = sec_flags;
851
6.15k
  return true;
852
6.15k
}
coff-i386.c:styp_to_sec_flags
Line
Count
Source
687
7.30k
{
688
7.30k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
7.30k
  unsigned long styp_flags = internal_s->s_flags;
690
7.30k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
7.30k
#ifdef STYP_NOLOAD
703
7.30k
  if (styp_flags & STYP_NOLOAD)
704
2.56k
    sec_flags |= SEC_NEVER_LOAD;
705
7.30k
#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.30k
  if (styp_flags & STYP_TEXT)
710
2.56k
    {
711
2.56k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.32k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.24k
      else
714
1.24k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.56k
    }
716
4.74k
  else if (styp_flags & STYP_DATA)
717
1.17k
    {
718
1.17k
      if (sec_flags & SEC_NEVER_LOAD)
719
523
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
650
      else
721
650
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.17k
    }
723
3.56k
  else if (styp_flags & STYP_BSS)
724
613
    {
725
613
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
613
      if (sec_flags & SEC_NEVER_LOAD)
727
329
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
284
      else
729
284
#endif
730
284
  sec_flags |= SEC_ALLOC;
731
613
    }
732
2.95k
  else if (styp_flags & STYP_INFO)
733
451
    {
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
451
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
451
      sec_flags |= SEC_DEBUGGING;
742
451
#endif
743
451
    }
744
2.50k
  else if (styp_flags & STYP_PAD)
745
172
    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.33k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
2.33k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
2.33k
  else if (strcmp (name, _BSS) == 0)
787
1
    {
788
1
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
1
      if (sec_flags & SEC_NEVER_LOAD)
790
0
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
1
      else
792
1
#endif
793
1
  sec_flags |= SEC_ALLOC;
794
1
    }
795
2.33k
  else if (startswith (name, DOT_DEBUG)
796
2.33k
     || startswith (name, DOT_ZDEBUG)
797
2.33k
#ifdef _COMMENT
798
2.33k
     || strcmp (name, _COMMENT) == 0
799
2.33k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.33k
     || startswith (name, ".stab"))
805
2
    {
806
2
#ifdef COFF_PAGE_SIZE
807
2
      sec_flags |= SEC_DEBUGGING;
808
2
#endif
809
2
    }
810
2.32k
#ifdef _LIB
811
2.32k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
2.32k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.32k
  else
819
2.32k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
7.30k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
7.30k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.23k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
7.30k
#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.30k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
7.30k
      && (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.30k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
7.30k
  * flags_ptr = sec_flags;
851
7.30k
  return true;
852
7.30k
}
coff-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
2.14k
{
688
2.14k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
2.14k
  unsigned long styp_flags = internal_s->s_flags;
690
2.14k
  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.14k
#ifdef STYP_NOLOAD
703
2.14k
  if (styp_flags & STYP_NOLOAD)
704
591
    sec_flags |= SEC_NEVER_LOAD;
705
2.14k
#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.14k
  if (styp_flags & STYP_TEXT)
710
556
    {
711
556
      if (sec_flags & SEC_NEVER_LOAD)
712
292
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
264
      else
714
264
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
556
    }
716
1.58k
  else if (styp_flags & STYP_DATA)
717
234
    {
718
234
      if (sec_flags & SEC_NEVER_LOAD)
719
120
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
114
      else
721
114
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
234
    }
723
1.35k
  else if (styp_flags & STYP_BSS)
724
163
    {
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
163
  sec_flags |= SEC_ALLOC;
731
163
    }
732
1.19k
  else if (styp_flags & STYP_INFO)
733
143
    {
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
143
    }
744
1.04k
  else if (styp_flags & STYP_PAD)
745
87
    sec_flags = 0;
746
962
#ifdef RS6000COFF_C
747
962
  else if (styp_flags & STYP_TDATA)
748
105
    {
749
105
      if (sec_flags & SEC_NEVER_LOAD)
750
23
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
82
      else
752
82
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
105
    }
754
857
  else if (styp_flags & STYP_TBSS)
755
27
    {
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
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
27
    }
763
830
  else if (styp_flags & STYP_EXCEPT)
764
57
    sec_flags |= SEC_LOAD;
765
773
  else if (styp_flags & STYP_LOADER)
766
20
    sec_flags |= SEC_LOAD;
767
753
  else if (styp_flags & STYP_TYPCHK)
768
7
    sec_flags |= SEC_LOAD;
769
746
  else if (styp_flags & STYP_DWARF)
770
19
    sec_flags |= SEC_DEBUGGING;
771
727
#endif
772
727
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
727
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
727
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
727
  else if (startswith (name, DOT_DEBUG)
796
727
     || 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
727
     || startswith (name, ".stab"))
805
4
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
4
    }
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
723
  else
819
723
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
2.14k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
2.14k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
259
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
2.14k
#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.14k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
2.14k
      && (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.14k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
2.14k
  * flags_ptr = sec_flags;
851
2.14k
  return true;
852
2.14k
}
coff-sh.c:styp_to_sec_flags
Line
Count
Source
687
10.6k
{
688
10.6k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
10.6k
  unsigned long styp_flags = internal_s->s_flags;
690
10.6k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
10.6k
#ifdef STYP_NOLOAD
703
10.6k
  if (styp_flags & STYP_NOLOAD)
704
2.84k
    sec_flags |= SEC_NEVER_LOAD;
705
10.6k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
10.6k
  if (styp_flags & STYP_TEXT)
710
3.05k
    {
711
3.05k
      if (sec_flags & SEC_NEVER_LOAD)
712
1.59k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.46k
      else
714
1.46k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.05k
    }
716
7.63k
  else if (styp_flags & STYP_DATA)
717
1.25k
    {
718
1.25k
      if (sec_flags & SEC_NEVER_LOAD)
719
595
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
662
      else
721
662
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.25k
    }
723
6.37k
  else if (styp_flags & STYP_BSS)
724
594
    {
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
594
  sec_flags |= SEC_ALLOC;
731
594
    }
732
5.78k
  else if (styp_flags & STYP_INFO)
733
718
    {
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
718
    }
744
5.06k
  else if (styp_flags & STYP_PAD)
745
169
    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.89k
  else if (strcmp (name, _TEXT) == 0)
773
3
    {
774
3
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3
      else
777
3
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
3
    }
779
4.89k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
4.89k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
4.89k
  else if (startswith (name, DOT_DEBUG)
796
4.89k
     || startswith (name, DOT_ZDEBUG)
797
4.89k
#ifdef _COMMENT
798
4.89k
     || strcmp (name, _COMMENT) == 0
799
4.89k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
4.89k
     || startswith (name, ".stab"))
805
5
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
5
    }
810
4.89k
#ifdef _LIB
811
4.89k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
4.89k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
4.89k
  else
819
4.89k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
10.6k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
10.6k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.17k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
10.6k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
10.6k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
10.6k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
10.6k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
10.6k
  * flags_ptr = sec_flags;
851
10.6k
  return true;
852
10.6k
}
coff-stgo32.c:styp_to_sec_flags
Line
Count
Source
687
1.92k
{
688
1.92k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
1.92k
  unsigned long styp_flags = internal_s->s_flags;
690
1.92k
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
1.92k
#ifdef STYP_NOLOAD
703
1.92k
  if (styp_flags & STYP_NOLOAD)
704
596
    sec_flags |= SEC_NEVER_LOAD;
705
1.92k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
1.92k
  if (styp_flags & STYP_TEXT)
710
454
    {
711
454
      if (sec_flags & SEC_NEVER_LOAD)
712
259
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
195
      else
714
195
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
454
    }
716
1.46k
  else if (styp_flags & STYP_DATA)
717
282
    {
718
282
      if (sec_flags & SEC_NEVER_LOAD)
719
202
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
80
      else
721
80
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
282
    }
723
1.18k
  else if (styp_flags & STYP_BSS)
724
43
    {
725
43
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
43
      if (sec_flags & SEC_NEVER_LOAD)
727
16
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
27
      else
729
27
#endif
730
27
  sec_flags |= SEC_ALLOC;
731
43
    }
732
1.14k
  else if (styp_flags & STYP_INFO)
733
167
    {
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
167
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
167
      sec_flags |= SEC_DEBUGGING;
742
167
#endif
743
167
    }
744
976
  else if (styp_flags & STYP_PAD)
745
83
    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
893
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
893
  else if (strcmp (name, _DATA) == 0)
780
8
    {
781
8
      if (sec_flags & SEC_NEVER_LOAD)
782
6
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
2
      else
784
2
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
8
    }
786
885
  else if (strcmp (name, _BSS) == 0)
787
1
    {
788
1
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
1
      if (sec_flags & SEC_NEVER_LOAD)
790
1
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
0
      else
792
0
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
1
    }
795
884
  else if (startswith (name, DOT_DEBUG)
796
884
     || startswith (name, DOT_ZDEBUG)
797
884
#ifdef _COMMENT
798
884
     || strcmp (name, _COMMENT) == 0
799
884
#endif
800
884
#ifdef COFF_LONG_SECTION_NAMES
801
884
     || startswith (name, GNU_LINKONCE_WI)
802
884
     || startswith (name, GNU_LINKONCE_WT)
803
884
#endif
804
884
     || startswith (name, ".stab"))
805
18
    {
806
18
#ifdef COFF_PAGE_SIZE
807
18
      sec_flags |= SEC_DEBUGGING;
808
18
#endif
809
18
    }
810
866
#ifdef _LIB
811
866
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
866
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
866
  else
819
866
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
1.92k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
1.92k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
183
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
1.92k
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
1.92k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
1.92k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
1.92k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
1.92k
  if (startswith (name, ".gnu.linkonce"))
844
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
1.92k
#endif
846
847
1.92k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
1.92k
  * flags_ptr = sec_flags;
851
1.92k
  return true;
852
1.92k
}
coff-tic30.c:styp_to_sec_flags
Line
Count
Source
687
110k
{
688
110k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
110k
  unsigned long styp_flags = internal_s->s_flags;
690
110k
  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
110k
#ifdef STYP_NOLOAD
703
110k
  if (styp_flags & STYP_NOLOAD)
704
33.1k
    sec_flags |= SEC_NEVER_LOAD;
705
110k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
110k
  if (styp_flags & STYP_TEXT)
710
24.0k
    {
711
24.0k
      if (sec_flags & SEC_NEVER_LOAD)
712
14.2k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
9.80k
      else
714
9.80k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
24.0k
    }
716
86.1k
  else if (styp_flags & STYP_DATA)
717
14.3k
    {
718
14.3k
      if (sec_flags & SEC_NEVER_LOAD)
719
9.48k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
4.82k
      else
721
4.82k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
14.3k
    }
723
71.8k
  else if (styp_flags & STYP_BSS)
724
3.50k
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
      if (sec_flags & SEC_NEVER_LOAD)
727
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
      else
729
#endif
730
3.50k
  sec_flags |= SEC_ALLOC;
731
3.50k
    }
732
68.3k
  else if (styp_flags & STYP_INFO)
733
9.78k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
9.78k
    }
744
58.5k
  else if (styp_flags & STYP_PAD)
745
2.42k
    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
56.1k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
56.1k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
56.1k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
56.1k
  else if (startswith (name, DOT_DEBUG)
796
56.1k
     || startswith (name, DOT_ZDEBUG)
797
56.1k
#ifdef _COMMENT
798
56.1k
     || strcmp (name, _COMMENT) == 0
799
56.1k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
56.1k
     || startswith (name, ".stab"))
805
4
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
4
    }
810
56.1k
#ifdef _LIB
811
56.1k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
56.1k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
56.1k
  else
819
56.1k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
110k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
110k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
11.9k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
110k
#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
110k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
110k
      && (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
110k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
110k
  * flags_ptr = sec_flags;
851
110k
  return true;
852
110k
}
Unexecuted instantiation: coff-tic4x.c:styp_to_sec_flags
coff-tic54x.c:styp_to_sec_flags
Line
Count
Source
687
11.4k
{
688
11.4k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
11.4k
  unsigned long styp_flags = internal_s->s_flags;
690
11.4k
  flagword sec_flags = 0;
691
692
11.4k
#ifdef STYP_BLOCK
693
11.4k
  if (styp_flags & STYP_BLOCK)
694
3.90k
    sec_flags |= SEC_TIC54X_BLOCK;
695
11.4k
#endif
696
697
11.4k
#ifdef STYP_CLINK
698
11.4k
  if (styp_flags & STYP_CLINK)
699
4.29k
    sec_flags |= SEC_TIC54X_CLINK;
700
11.4k
#endif
701
702
11.4k
#ifdef STYP_NOLOAD
703
11.4k
  if (styp_flags & STYP_NOLOAD)
704
3.87k
    sec_flags |= SEC_NEVER_LOAD;
705
11.4k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
11.4k
  if (styp_flags & STYP_TEXT)
710
3.99k
    {
711
3.99k
      if (sec_flags & SEC_NEVER_LOAD)
712
2.22k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.76k
      else
714
1.76k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.99k
    }
716
7.47k
  else if (styp_flags & STYP_DATA)
717
1.82k
    {
718
1.82k
      if (sec_flags & SEC_NEVER_LOAD)
719
785
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
1.03k
      else
721
1.03k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
1.82k
    }
723
5.64k
  else if (styp_flags & STYP_BSS)
724
846
    {
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
846
  sec_flags |= SEC_ALLOC;
731
846
    }
732
4.80k
  else if (styp_flags & STYP_INFO)
733
779
    {
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
779
    }
744
4.02k
  else if (styp_flags & STYP_PAD)
745
311
    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.71k
  else if (strcmp (name, _TEXT) == 0)
773
1
    {
774
1
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
1
      else
777
1
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
1
    }
779
3.71k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
3.71k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
3.71k
  else if (startswith (name, DOT_DEBUG)
796
3.71k
     || 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.71k
     || startswith (name, ".stab"))
805
2
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
2
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.70k
  else
819
3.70k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
11.4k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
11.4k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.78k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
11.4k
#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
11.4k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
11.4k
      && (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
11.4k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
11.4k
  * flags_ptr = sec_flags;
851
11.4k
  return true;
852
11.4k
}
coff-z80.c:styp_to_sec_flags
Line
Count
Source
687
2.51k
{
688
2.51k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
2.51k
  unsigned long styp_flags = internal_s->s_flags;
690
2.51k
  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.51k
#ifdef STYP_NOLOAD
703
2.51k
  if (styp_flags & STYP_NOLOAD)
704
676
    sec_flags |= SEC_NEVER_LOAD;
705
2.51k
#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.51k
  if (styp_flags & STYP_TEXT)
710
531
    {
711
531
      if (sec_flags & SEC_NEVER_LOAD)
712
241
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
290
      else
714
290
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
531
    }
716
1.97k
  else if (styp_flags & STYP_DATA)
717
285
    {
718
285
      if (sec_flags & SEC_NEVER_LOAD)
719
179
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
106
      else
721
106
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
285
    }
723
1.69k
  else if (styp_flags & STYP_BSS)
724
116
    {
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
116
  sec_flags |= SEC_ALLOC;
731
116
    }
732
1.57k
  else if (styp_flags & STYP_INFO)
733
184
    {
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
184
    }
744
1.39k
  else if (styp_flags & STYP_PAD)
745
149
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
1.24k
  else if (strcmp (name, _TEXT) == 0)
773
0
    {
774
0
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
0
      else
777
0
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
0
    }
779
1.24k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
1.24k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
1.24k
  else if (startswith (name, DOT_DEBUG)
796
1.24k
     || startswith (name, DOT_ZDEBUG)
797
1.24k
#ifdef _COMMENT
798
1.24k
     || strcmp (name, _COMMENT) == 0
799
1.24k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
1.24k
     || startswith (name, ".stab"))
805
1
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
1
    }
810
1.24k
#ifdef _LIB
811
1.24k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
1.24k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.24k
  else
819
1.24k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
2.51k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
2.51k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
186
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
2.51k
#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.51k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
2.51k
      && (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.51k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
2.51k
  * flags_ptr = sec_flags;
851
2.51k
  return true;
852
2.51k
}
coff-z8k.c:styp_to_sec_flags
Line
Count
Source
687
4.89k
{
688
4.89k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
4.89k
  unsigned long styp_flags = internal_s->s_flags;
690
4.89k
  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.89k
#ifdef STYP_NOLOAD
703
4.89k
  if (styp_flags & STYP_NOLOAD)
704
1.00k
    sec_flags |= SEC_NEVER_LOAD;
705
4.89k
#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.89k
  if (styp_flags & STYP_TEXT)
710
1.19k
    {
711
1.19k
      if (sec_flags & SEC_NEVER_LOAD)
712
572
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
624
      else
714
624
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.19k
    }
716
3.70k
  else if (styp_flags & STYP_DATA)
717
358
    {
718
358
      if (sec_flags & SEC_NEVER_LOAD)
719
161
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
197
      else
721
197
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
358
    }
723
3.34k
  else if (styp_flags & STYP_BSS)
724
496
    {
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
496
  sec_flags |= SEC_ALLOC;
731
496
    }
732
2.84k
  else if (styp_flags & STYP_INFO)
733
230
    {
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
230
    }
744
2.61k
  else if (styp_flags & STYP_PAD)
745
101
    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.51k
  else if (strcmp (name, _TEXT) == 0)
773
5
    {
774
5
      if (sec_flags & SEC_NEVER_LOAD)
775
0
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
5
      else
777
5
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
5
    }
779
2.51k
  else if (strcmp (name, _DATA) == 0)
780
0
    {
781
0
      if (sec_flags & SEC_NEVER_LOAD)
782
0
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
0
      else
784
0
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
0
    }
786
2.51k
  else if (strcmp (name, _BSS) == 0)
787
0
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
0
  sec_flags |= SEC_ALLOC;
794
0
    }
795
2.51k
  else if (startswith (name, DOT_DEBUG)
796
2.51k
     || startswith (name, DOT_ZDEBUG)
797
2.51k
#ifdef _COMMENT
798
2.51k
     || strcmp (name, _COMMENT) == 0
799
2.51k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.51k
     || startswith (name, ".stab"))
805
4
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
4
    }
810
2.50k
#ifdef _LIB
811
2.50k
  else if (strcmp (name, _LIB) == 0)
812
0
    ;
813
2.50k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.50k
  else
819
2.50k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
4.89k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
4.89k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
486
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
4.89k
#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.89k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
4.89k
      && (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.89k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
4.89k
  * flags_ptr = sec_flags;
851
4.89k
  return true;
852
4.89k
}
853
854
#else /* COFF_WITH_PE */
855
856
static hashval_t
857
comdat_hashf (const void *entry)
858
6.46k
{
859
6.46k
  const struct comdat_hash_entry *fe = entry;
860
6.46k
  return fe->target_index;
861
6.46k
}
pei-i386.c:comdat_hashf
Line
Count
Source
858
161
{
859
161
  const struct comdat_hash_entry *fe = entry;
860
161
  return fe->target_index;
861
161
}
pe-x86_64.c:comdat_hashf
Line
Count
Source
858
623
{
859
623
  const struct comdat_hash_entry *fe = entry;
860
623
  return fe->target_index;
861
623
}
pei-x86_64.c:comdat_hashf
Line
Count
Source
858
247
{
859
247
  const struct comdat_hash_entry *fe = entry;
860
247
  return fe->target_index;
861
247
}
pe-aarch64.c:comdat_hashf
Line
Count
Source
858
176
{
859
176
  const struct comdat_hash_entry *fe = entry;
860
176
  return fe->target_index;
861
176
}
pei-aarch64.c:comdat_hashf
Line
Count
Source
858
3.32k
{
859
3.32k
  const struct comdat_hash_entry *fe = entry;
860
3.32k
  return fe->target_index;
861
3.32k
}
pei-ia64.c:comdat_hashf
Line
Count
Source
858
902
{
859
902
  const struct comdat_hash_entry *fe = entry;
860
902
  return fe->target_index;
861
902
}
pei-loongarch64.c:comdat_hashf
Line
Count
Source
858
182
{
859
182
  const struct comdat_hash_entry *fe = entry;
860
182
  return fe->target_index;
861
182
}
pe-arm-wince.c:comdat_hashf
Line
Count
Source
858
38
{
859
38
  const struct comdat_hash_entry *fe = entry;
860
38
  return fe->target_index;
861
38
}
pe-arm.c:comdat_hashf
Line
Count
Source
858
38
{
859
38
  const struct comdat_hash_entry *fe = entry;
860
38
  return fe->target_index;
861
38
}
pe-i386.c:comdat_hashf
Line
Count
Source
858
245
{
859
245
  const struct comdat_hash_entry *fe = entry;
860
245
  return fe->target_index;
861
245
}
pe-mcore.c:comdat_hashf
Line
Count
Source
858
51
{
859
51
  const struct comdat_hash_entry *fe = entry;
860
51
  return fe->target_index;
861
51
}
pe-sh.c:comdat_hashf
Line
Count
Source
858
68
{
859
68
  const struct comdat_hash_entry *fe = entry;
860
68
  return fe->target_index;
861
68
}
pei-arm-wince.c:comdat_hashf
Line
Count
Source
858
24
{
859
24
  const struct comdat_hash_entry *fe = entry;
860
24
  return fe->target_index;
861
24
}
pei-arm.c:comdat_hashf
Line
Count
Source
858
136
{
859
136
  const struct comdat_hash_entry *fe = entry;
860
136
  return fe->target_index;
861
136
}
pei-mcore.c:comdat_hashf
Line
Count
Source
858
114
{
859
114
  const struct comdat_hash_entry *fe = entry;
860
114
  return fe->target_index;
861
114
}
pei-sh.c:comdat_hashf
Line
Count
Source
858
141
{
859
141
  const struct comdat_hash_entry *fe = entry;
860
141
  return fe->target_index;
861
141
}
862
863
static int
864
comdat_eqf (const void *e1, const void *e2)
865
1.34k
{
866
1.34k
  const struct comdat_hash_entry *fe1 = e1;
867
1.34k
  const struct comdat_hash_entry *fe2 = e2;
868
1.34k
  return fe1->target_index == fe2->target_index;
869
1.34k
}
pei-i386.c:comdat_eqf
Line
Count
Source
865
25
{
866
25
  const struct comdat_hash_entry *fe1 = e1;
867
25
  const struct comdat_hash_entry *fe2 = e2;
868
25
  return fe1->target_index == fe2->target_index;
869
25
}
pe-x86_64.c:comdat_eqf
Line
Count
Source
865
223
{
866
223
  const struct comdat_hash_entry *fe1 = e1;
867
223
  const struct comdat_hash_entry *fe2 = e2;
868
223
  return fe1->target_index == fe2->target_index;
869
223
}
pei-x86_64.c:comdat_eqf
Line
Count
Source
865
31
{
866
31
  const struct comdat_hash_entry *fe1 = e1;
867
31
  const struct comdat_hash_entry *fe2 = e2;
868
31
  return fe1->target_index == fe2->target_index;
869
31
}
pe-aarch64.c:comdat_eqf
Line
Count
Source
865
35
{
866
35
  const struct comdat_hash_entry *fe1 = e1;
867
35
  const struct comdat_hash_entry *fe2 = e2;
868
35
  return fe1->target_index == fe2->target_index;
869
35
}
pei-aarch64.c:comdat_eqf
Line
Count
Source
865
402
{
866
402
  const struct comdat_hash_entry *fe1 = e1;
867
402
  const struct comdat_hash_entry *fe2 = e2;
868
402
  return fe1->target_index == fe2->target_index;
869
402
}
pei-ia64.c:comdat_eqf
Line
Count
Source
865
518
{
866
518
  const struct comdat_hash_entry *fe1 = e1;
867
518
  const struct comdat_hash_entry *fe2 = e2;
868
518
  return fe1->target_index == fe2->target_index;
869
518
}
pei-loongarch64.c:comdat_eqf
Line
Count
Source
865
23
{
866
23
  const struct comdat_hash_entry *fe1 = e1;
867
23
  const struct comdat_hash_entry *fe2 = e2;
868
23
  return fe1->target_index == fe2->target_index;
869
23
}
pe-arm-wince.c:comdat_eqf
Line
Count
Source
865
1
{
866
1
  const struct comdat_hash_entry *fe1 = e1;
867
1
  const struct comdat_hash_entry *fe2 = e2;
868
1
  return fe1->target_index == fe2->target_index;
869
1
}
pe-arm.c:comdat_eqf
Line
Count
Source
865
1
{
866
1
  const struct comdat_hash_entry *fe1 = e1;
867
1
  const struct comdat_hash_entry *fe2 = e2;
868
1
  return fe1->target_index == fe2->target_index;
869
1
}
pe-i386.c:comdat_eqf
Line
Count
Source
865
17
{
866
17
  const struct comdat_hash_entry *fe1 = e1;
867
17
  const struct comdat_hash_entry *fe2 = e2;
868
17
  return fe1->target_index == fe2->target_index;
869
17
}
pe-mcore.c:comdat_eqf
Line
Count
Source
865
7
{
866
7
  const struct comdat_hash_entry *fe1 = e1;
867
7
  const struct comdat_hash_entry *fe2 = e2;
868
7
  return fe1->target_index == fe2->target_index;
869
7
}
pe-sh.c:comdat_eqf
Line
Count
Source
865
10
{
866
10
  const struct comdat_hash_entry *fe1 = e1;
867
10
  const struct comdat_hash_entry *fe2 = e2;
868
10
  return fe1->target_index == fe2->target_index;
869
10
}
Unexecuted instantiation: pei-arm-wince.c:comdat_eqf
pei-arm.c:comdat_eqf
Line
Count
Source
865
6
{
866
6
  const struct comdat_hash_entry *fe1 = e1;
867
6
  const struct comdat_hash_entry *fe2 = e2;
868
6
  return fe1->target_index == fe2->target_index;
869
6
}
pei-mcore.c:comdat_eqf
Line
Count
Source
865
21
{
866
21
  const struct comdat_hash_entry *fe1 = e1;
867
21
  const struct comdat_hash_entry *fe2 = e2;
868
21
  return fe1->target_index == fe2->target_index;
869
21
}
pei-sh.c:comdat_eqf
Line
Count
Source
865
27
{
866
27
  const struct comdat_hash_entry *fe1 = e1;
867
27
  const struct comdat_hash_entry *fe2 = e2;
868
27
  return fe1->target_index == fe2->target_index;
869
27
}
870
871
static void
872
comdat_delf (void *ent)
873
646
{
874
646
  struct comdat_hash_entry *e = ent;
875
646
  free (e->symname);
876
646
  free (e);
877
646
}
pei-i386.c:comdat_delf
Line
Count
Source
873
28
{
874
28
  struct comdat_hash_entry *e = ent;
875
28
  free (e->symname);
876
28
  free (e);
877
28
}
pe-x86_64.c:comdat_delf
Line
Count
Source
873
117
{
874
117
  struct comdat_hash_entry *e = ent;
875
117
  free (e->symname);
876
117
  free (e);
877
117
}
pei-x86_64.c:comdat_delf
Line
Count
Source
873
44
{
874
44
  struct comdat_hash_entry *e = ent;
875
44
  free (e->symname);
876
44
  free (e);
877
44
}
pe-aarch64.c:comdat_delf
Line
Count
Source
873
28
{
874
28
  struct comdat_hash_entry *e = ent;
875
28
  free (e->symname);
876
28
  free (e);
877
28
}
pei-aarch64.c:comdat_delf
Line
Count
Source
873
94
{
874
94
  struct comdat_hash_entry *e = ent;
875
94
  free (e->symname);
876
94
  free (e);
877
94
}
pei-ia64.c:comdat_delf
Line
Count
Source
873
137
{
874
137
  struct comdat_hash_entry *e = ent;
875
137
  free (e->symname);
876
137
  free (e);
877
137
}
pei-loongarch64.c:comdat_delf
Line
Count
Source
873
24
{
874
24
  struct comdat_hash_entry *e = ent;
875
24
  free (e->symname);
876
24
  free (e);
877
24
}
pe-arm-wince.c:comdat_delf
Line
Count
Source
873
4
{
874
4
  struct comdat_hash_entry *e = ent;
875
4
  free (e->symname);
876
4
  free (e);
877
4
}
pe-arm.c:comdat_delf
Line
Count
Source
873
4
{
874
4
  struct comdat_hash_entry *e = ent;
875
4
  free (e->symname);
876
4
  free (e);
877
4
}
pe-i386.c:comdat_delf
Line
Count
Source
873
40
{
874
40
  struct comdat_hash_entry *e = ent;
875
40
  free (e->symname);
876
40
  free (e);
877
40
}
pe-mcore.c:comdat_delf
Line
Count
Source
873
17
{
874
17
  struct comdat_hash_entry *e = ent;
875
17
  free (e->symname);
876
17
  free (e);
877
17
}
pe-sh.c:comdat_delf
Line
Count
Source
873
11
{
874
11
  struct comdat_hash_entry *e = ent;
875
11
  free (e->symname);
876
11
  free (e);
877
11
}
Unexecuted instantiation: pei-arm-wince.c:comdat_delf
pei-arm.c:comdat_delf
Line
Count
Source
873
15
{
874
15
  struct comdat_hash_entry *e = ent;
875
15
  free (e->symname);
876
15
  free (e);
877
15
}
pei-mcore.c:comdat_delf
Line
Count
Source
873
32
{
874
32
  struct comdat_hash_entry *e = ent;
875
32
  free (e->symname);
876
32
  free (e);
877
32
}
pei-sh.c:comdat_delf
Line
Count
Source
873
51
{
874
51
  struct comdat_hash_entry *e = ent;
875
51
  free (e->symname);
876
51
  free (e);
877
51
}
878
879
static struct comdat_hash_entry *
880
find_flags (htab_t comdat_hash, int target_index)
881
4.66k
{
882
4.66k
  struct comdat_hash_entry needle;
883
4.66k
  needle.target_index = target_index;
884
885
4.66k
  return htab_find (comdat_hash, &needle);
886
4.66k
}
pei-i386.c:find_flags
Line
Count
Source
881
110
{
882
110
  struct comdat_hash_entry needle;
883
110
  needle.target_index = target_index;
884
885
110
  return htab_find (comdat_hash, &needle);
886
110
}
pe-x86_64.c:find_flags
Line
Count
Source
881
306
{
882
306
  struct comdat_hash_entry needle;
883
306
  needle.target_index = target_index;
884
885
306
  return htab_find (comdat_hash, &needle);
886
306
}
pei-x86_64.c:find_flags
Line
Count
Source
881
165
{
882
165
  struct comdat_hash_entry needle;
883
165
  needle.target_index = target_index;
884
885
165
  return htab_find (comdat_hash, &needle);
886
165
}
pe-aarch64.c:find_flags
Line
Count
Source
881
117
{
882
117
  struct comdat_hash_entry needle;
883
117
  needle.target_index = target_index;
884
885
117
  return htab_find (comdat_hash, &needle);
886
117
}
pei-aarch64.c:find_flags
Line
Count
Source
881
2.94k
{
882
2.94k
  struct comdat_hash_entry needle;
883
2.94k
  needle.target_index = target_index;
884
885
2.94k
  return htab_find (comdat_hash, &needle);
886
2.94k
}
pei-ia64.c:find_flags
Line
Count
Source
881
285
{
882
285
  struct comdat_hash_entry needle;
883
285
  needle.target_index = target_index;
884
885
285
  return htab_find (comdat_hash, &needle);
886
285
}
pei-loongarch64.c:find_flags
Line
Count
Source
881
135
{
882
135
  struct comdat_hash_entry needle;
883
135
  needle.target_index = target_index;
884
885
135
  return htab_find (comdat_hash, &needle);
886
135
}
pe-arm-wince.c:find_flags
Line
Count
Source
881
32
{
882
32
  struct comdat_hash_entry needle;
883
32
  needle.target_index = target_index;
884
885
32
  return htab_find (comdat_hash, &needle);
886
32
}
pe-arm.c:find_flags
Line
Count
Source
881
32
{
882
32
  struct comdat_hash_entry needle;
883
32
  needle.target_index = target_index;
884
885
32
  return htab_find (comdat_hash, &needle);
886
32
}
pe-i386.c:find_flags
Line
Count
Source
881
190
{
882
190
  struct comdat_hash_entry needle;
883
190
  needle.target_index = target_index;
884
885
190
  return htab_find (comdat_hash, &needle);
886
190
}
pe-mcore.c:find_flags
Line
Count
Source
881
28
{
882
28
  struct comdat_hash_entry needle;
883
28
  needle.target_index = target_index;
884
885
28
  return htab_find (comdat_hash, &needle);
886
28
}
pe-sh.c:find_flags
Line
Count
Source
881
46
{
882
46
  struct comdat_hash_entry needle;
883
46
  needle.target_index = target_index;
884
885
46
  return htab_find (comdat_hash, &needle);
886
46
}
pei-arm-wince.c:find_flags
Line
Count
Source
881
23
{
882
23
  struct comdat_hash_entry needle;
883
23
  needle.target_index = target_index;
884
885
23
  return htab_find (comdat_hash, &needle);
886
23
}
pei-arm.c:find_flags
Line
Count
Source
881
114
{
882
114
  struct comdat_hash_entry needle;
883
114
  needle.target_index = target_index;
884
885
114
  return htab_find (comdat_hash, &needle);
886
114
}
pei-mcore.c:find_flags
Line
Count
Source
881
62
{
882
62
  struct comdat_hash_entry needle;
883
62
  needle.target_index = target_index;
884
885
62
  return htab_find (comdat_hash, &needle);
886
62
}
pei-sh.c:find_flags
Line
Count
Source
881
78
{
882
78
  struct comdat_hash_entry needle;
883
78
  needle.target_index = target_index;
884
885
78
  return htab_find (comdat_hash, &needle);
886
78
}
887
888
static bool
889
fill_comdat_hash (bfd *abfd)
890
4.39k
{
891
4.39k
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
4.39k
  if (! _bfd_coff_get_external_symbols (abfd))
909
533
    return true;
910
911
3.86k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
3.86k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
3.86k
  for (struct internal_syment isym;
915
6.35k
       esym < esymend;
916
3.86k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
2.49k
    {
918
2.49k
      char buf[SYMNMLEN + 1];
919
2.49k
      const char *symname;
920
2.49k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
2.49k
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
2.49k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
2.49k
      if (symname == NULL)
949
726
  {
950
726
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
726
            abfd);
952
726
    continue;
953
726
  }
954
955
1.76k
      union internal_auxent aux;
956
957
1.76k
      struct comdat_hash_entry needle;
958
1.76k
      needle.target_index = isym.n_scnum;
959
960
1.76k
      void **slot
961
1.76k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
1.76k
      if (slot == NULL)
963
0
  return false;
964
965
1.76k
      if (*slot == NULL)
966
756
  {
967
756
    if (isym.n_numaux == 0)
968
536
      aux.x_scn.x_comdat = 0;
969
220
    else
970
220
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
220
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
110
    {
974
      /* xgettext:c-format */
975
110
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
110
          " section '%s' found"),
977
110
              abfd, symname);
978
110
      continue;
979
110
    }
980
110
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
110
            isym.n_type, isym.n_sclass, 0,
982
110
            isym.n_numaux, &aux);
983
110
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
646
    switch (aux.x_scn.x_comdat)
998
646
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
2
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
2
        sec_flags &= ~SEC_LINK_ONCE;
1031
2
#endif
1032
2
        break;
1033
1034
644
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
644
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
644
        break;
1038
646
      }
1039
1040
646
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
646
    if (*slot == NULL)
1042
0
      return false;
1043
646
    struct comdat_hash_entry *newentry = *slot;
1044
646
    newentry->sec_flags = sec_flags;
1045
646
    newentry->symname = bfd_strdup (symname);
1046
646
    newentry->target_index = isym.n_scnum;
1047
646
    newentry->isym = isym;
1048
646
    newentry->comdat_symbol = -1;
1049
646
  }
1050
1.01k
      else
1051
1.01k
  {
1052
1.01k
    struct comdat_hash_entry *entry = *slot;
1053
1054
1.01k
    if (entry->comdat_symbol != -1)
1055
856
      continue;
1056
1057
155
    char *target_name = strchr (entry->symname, '$');
1058
155
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
155
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
155
    entry->comdat_name = bfd_strdup (symname);
1082
155
  }
1083
1.76k
    }
1084
1085
3.86k
  return true;
1086
3.86k
}
pei-i386.c:fill_comdat_hash
Line
Count
Source
890
95
{
891
95
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
95
  if (! _bfd_coff_get_external_symbols (abfd))
909
17
    return true;
910
911
78
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
78
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
78
  for (struct internal_syment isym;
915
178
       esym < esymend;
916
100
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
100
    {
918
100
      char buf[SYMNMLEN + 1];
919
100
      const char *symname;
920
100
      flagword sec_flags = SEC_LINK_ONCE;
921
922
100
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
100
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
100
      if (symname == NULL)
949
49
  {
950
49
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
49
            abfd);
952
49
    continue;
953
49
  }
954
955
51
      union internal_auxent aux;
956
957
51
      struct comdat_hash_entry needle;
958
51
      needle.target_index = isym.n_scnum;
959
960
51
      void **slot
961
51
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
51
      if (slot == NULL)
963
0
  return false;
964
965
51
      if (*slot == NULL)
966
33
  {
967
33
    if (isym.n_numaux == 0)
968
21
      aux.x_scn.x_comdat = 0;
969
12
    else
970
12
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
12
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
5
    {
974
      /* xgettext:c-format */
975
5
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
5
          " section '%s' found"),
977
5
              abfd, symname);
978
5
      continue;
979
5
    }
980
7
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
7
            isym.n_type, isym.n_sclass, 0,
982
7
            isym.n_numaux, &aux);
983
7
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
28
    switch (aux.x_scn.x_comdat)
998
28
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
28
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
28
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
28
        break;
1038
28
      }
1039
1040
28
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
28
    if (*slot == NULL)
1042
0
      return false;
1043
28
    struct comdat_hash_entry *newentry = *slot;
1044
28
    newentry->sec_flags = sec_flags;
1045
28
    newentry->symname = bfd_strdup (symname);
1046
28
    newentry->target_index = isym.n_scnum;
1047
28
    newentry->isym = isym;
1048
28
    newentry->comdat_symbol = -1;
1049
28
  }
1050
18
      else
1051
18
  {
1052
18
    struct comdat_hash_entry *entry = *slot;
1053
1054
18
    if (entry->comdat_symbol != -1)
1055
8
      continue;
1056
1057
10
    char *target_name = strchr (entry->symname, '$');
1058
10
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
10
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
10
    entry->comdat_name = bfd_strdup (symname);
1082
10
  }
1083
51
    }
1084
1085
78
  return true;
1086
78
}
pe-x86_64.c:fill_comdat_hash
Line
Count
Source
890
304
{
891
304
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
304
  if (! _bfd_coff_get_external_symbols (abfd))
909
80
    return true;
910
911
224
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
224
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
224
  for (struct internal_syment isym;
915
607
       esym < esymend;
916
383
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
383
    {
918
383
      char buf[SYMNMLEN + 1];
919
383
      const char *symname;
920
383
      flagword sec_flags = SEC_LINK_ONCE;
921
922
383
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
383
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
383
      if (symname == NULL)
949
66
  {
950
66
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
66
            abfd);
952
66
    continue;
953
66
  }
954
955
317
      union internal_auxent aux;
956
957
317
      struct comdat_hash_entry needle;
958
317
      needle.target_index = isym.n_scnum;
959
960
317
      void **slot
961
317
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
317
      if (slot == NULL)
963
0
  return false;
964
965
317
      if (*slot == NULL)
966
134
  {
967
134
    if (isym.n_numaux == 0)
968
84
      aux.x_scn.x_comdat = 0;
969
50
    else
970
50
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
50
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
17
    {
974
      /* xgettext:c-format */
975
17
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
17
          " section '%s' found"),
977
17
              abfd, symname);
978
17
      continue;
979
17
    }
980
33
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
33
            isym.n_type, isym.n_sclass, 0,
982
33
            isym.n_numaux, &aux);
983
33
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
117
    switch (aux.x_scn.x_comdat)
998
117
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
117
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
117
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
117
        break;
1038
117
      }
1039
1040
117
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
117
    if (*slot == NULL)
1042
0
      return false;
1043
117
    struct comdat_hash_entry *newentry = *slot;
1044
117
    newentry->sec_flags = sec_flags;
1045
117
    newentry->symname = bfd_strdup (symname);
1046
117
    newentry->target_index = isym.n_scnum;
1047
117
    newentry->isym = isym;
1048
117
    newentry->comdat_symbol = -1;
1049
117
  }
1050
183
      else
1051
183
  {
1052
183
    struct comdat_hash_entry *entry = *slot;
1053
1054
183
    if (entry->comdat_symbol != -1)
1055
161
      continue;
1056
1057
22
    char *target_name = strchr (entry->symname, '$');
1058
22
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
22
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
22
    entry->comdat_name = bfd_strdup (symname);
1082
22
  }
1083
317
    }
1084
1085
224
  return true;
1086
224
}
pei-x86_64.c:fill_comdat_hash
Line
Count
Source
890
141
{
891
141
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
141
  if (! _bfd_coff_get_external_symbols (abfd))
909
13
    return true;
910
911
128
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
128
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
128
  for (struct internal_syment isym;
915
268
       esym < esymend;
916
140
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
140
    {
918
140
      char buf[SYMNMLEN + 1];
919
140
      const char *symname;
920
140
      flagword sec_flags = SEC_LINK_ONCE;
921
922
140
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
140
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
140
      if (symname == NULL)
949
58
  {
950
58
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
58
            abfd);
952
58
    continue;
953
58
  }
954
955
82
      union internal_auxent aux;
956
957
82
      struct comdat_hash_entry needle;
958
82
      needle.target_index = isym.n_scnum;
959
960
82
      void **slot
961
82
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
82
      if (slot == NULL)
963
0
  return false;
964
965
82
      if (*slot == NULL)
966
53
  {
967
53
    if (isym.n_numaux == 0)
968
42
      aux.x_scn.x_comdat = 0;
969
11
    else
970
11
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
11
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
9
    {
974
      /* xgettext:c-format */
975
9
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
9
          " section '%s' found"),
977
9
              abfd, symname);
978
9
      continue;
979
9
    }
980
2
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
2
            isym.n_type, isym.n_sclass, 0,
982
2
            isym.n_numaux, &aux);
983
2
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
44
    switch (aux.x_scn.x_comdat)
998
44
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
44
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
44
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
44
        break;
1038
44
      }
1039
1040
44
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
44
    if (*slot == NULL)
1042
0
      return false;
1043
44
    struct comdat_hash_entry *newentry = *slot;
1044
44
    newentry->sec_flags = sec_flags;
1045
44
    newentry->symname = bfd_strdup (symname);
1046
44
    newentry->target_index = isym.n_scnum;
1047
44
    newentry->isym = isym;
1048
44
    newentry->comdat_symbol = -1;
1049
44
  }
1050
29
      else
1051
29
  {
1052
29
    struct comdat_hash_entry *entry = *slot;
1053
1054
29
    if (entry->comdat_symbol != -1)
1055
14
      continue;
1056
1057
15
    char *target_name = strchr (entry->symname, '$');
1058
15
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
15
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
15
    entry->comdat_name = bfd_strdup (symname);
1082
15
  }
1083
82
    }
1084
1085
128
  return true;
1086
128
}
pe-aarch64.c:fill_comdat_hash
Line
Count
Source
890
95
{
891
95
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
95
  if (! _bfd_coff_get_external_symbols (abfd))
909
26
    return true;
910
911
69
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
69
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
69
  for (struct internal_syment isym;
915
148
       esym < esymend;
916
79
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
79
    {
918
79
      char buf[SYMNMLEN + 1];
919
79
      const char *symname;
920
79
      flagword sec_flags = SEC_LINK_ONCE;
921
922
79
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
79
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
79
      if (symname == NULL)
949
20
  {
950
20
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
20
            abfd);
952
20
    continue;
953
20
  }
954
955
59
      union internal_auxent aux;
956
957
59
      struct comdat_hash_entry needle;
958
59
      needle.target_index = isym.n_scnum;
959
960
59
      void **slot
961
59
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
59
      if (slot == NULL)
963
0
  return false;
964
965
59
      if (*slot == NULL)
966
32
  {
967
32
    if (isym.n_numaux == 0)
968
28
      aux.x_scn.x_comdat = 0;
969
4
    else
970
4
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
4
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
4
    {
974
      /* xgettext:c-format */
975
4
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
4
          " section '%s' found"),
977
4
              abfd, symname);
978
4
      continue;
979
4
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
28
    switch (aux.x_scn.x_comdat)
998
28
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
28
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
28
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
28
        break;
1038
28
      }
1039
1040
28
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
28
    if (*slot == NULL)
1042
0
      return false;
1043
28
    struct comdat_hash_entry *newentry = *slot;
1044
28
    newentry->sec_flags = sec_flags;
1045
28
    newentry->symname = bfd_strdup (symname);
1046
28
    newentry->target_index = isym.n_scnum;
1047
28
    newentry->isym = isym;
1048
28
    newentry->comdat_symbol = -1;
1049
28
  }
1050
27
      else
1051
27
  {
1052
27
    struct comdat_hash_entry *entry = *slot;
1053
1054
27
    if (entry->comdat_symbol != -1)
1055
14
      continue;
1056
1057
13
    char *target_name = strchr (entry->symname, '$');
1058
13
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
13
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
13
    entry->comdat_name = bfd_strdup (symname);
1082
13
  }
1083
59
    }
1084
1085
69
  return true;
1086
69
}
pei-aarch64.c:fill_comdat_hash
Line
Count
Source
890
2.87k
{
891
2.87k
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
2.87k
  if (! _bfd_coff_get_external_symbols (abfd))
909
108
    return true;
910
911
2.76k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
2.76k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
2.76k
  for (struct internal_syment isym;
915
3.29k
       esym < esymend;
916
2.76k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
531
    {
918
531
      char buf[SYMNMLEN + 1];
919
531
      const char *symname;
920
531
      flagword sec_flags = SEC_LINK_ONCE;
921
922
531
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
531
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
531
      if (symname == NULL)
949
187
  {
950
187
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
187
            abfd);
952
187
    continue;
953
187
  }
954
955
344
      union internal_auxent aux;
956
957
344
      struct comdat_hash_entry needle;
958
344
      needle.target_index = isym.n_scnum;
959
960
344
      void **slot
961
344
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
344
      if (slot == NULL)
963
0
  return false;
964
965
344
      if (*slot == NULL)
966
101
  {
967
101
    if (isym.n_numaux == 0)
968
62
      aux.x_scn.x_comdat = 0;
969
39
    else
970
39
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
39
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
7
    {
974
      /* xgettext:c-format */
975
7
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
7
          " section '%s' found"),
977
7
              abfd, symname);
978
7
      continue;
979
7
    }
980
32
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
32
            isym.n_type, isym.n_sclass, 0,
982
32
            isym.n_numaux, &aux);
983
32
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
94
    switch (aux.x_scn.x_comdat)
998
94
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
2
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
2
        sec_flags &= ~SEC_LINK_ONCE;
1031
2
#endif
1032
2
        break;
1033
1034
92
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
92
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
92
        break;
1038
94
      }
1039
1040
94
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
94
    if (*slot == NULL)
1042
0
      return false;
1043
94
    struct comdat_hash_entry *newentry = *slot;
1044
94
    newentry->sec_flags = sec_flags;
1045
94
    newentry->symname = bfd_strdup (symname);
1046
94
    newentry->target_index = isym.n_scnum;
1047
94
    newentry->isym = isym;
1048
94
    newentry->comdat_symbol = -1;
1049
94
  }
1050
243
      else
1051
243
  {
1052
243
    struct comdat_hash_entry *entry = *slot;
1053
1054
243
    if (entry->comdat_symbol != -1)
1055
223
      continue;
1056
1057
20
    char *target_name = strchr (entry->symname, '$');
1058
20
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
20
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
20
    entry->comdat_name = bfd_strdup (symname);
1082
20
  }
1083
344
    }
1084
1085
2.76k
  return true;
1086
2.76k
}
pei-ia64.c:fill_comdat_hash
Line
Count
Source
890
211
{
891
211
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
211
  if (! _bfd_coff_get_external_symbols (abfd))
909
22
    return true;
910
911
189
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
189
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
189
  for (struct internal_syment isym;
915
993
       esym < esymend;
916
804
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
804
    {
918
804
      char buf[SYMNMLEN + 1];
919
804
      const char *symname;
920
804
      flagword sec_flags = SEC_LINK_ONCE;
921
922
804
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
804
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
804
      if (symname == NULL)
949
187
  {
950
187
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
187
            abfd);
952
187
    continue;
953
187
  }
954
955
617
      union internal_auxent aux;
956
957
617
      struct comdat_hash_entry needle;
958
617
      needle.target_index = isym.n_scnum;
959
960
617
      void **slot
961
617
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
617
      if (slot == NULL)
963
0
  return false;
964
965
617
      if (*slot == NULL)
966
159
  {
967
159
    if (isym.n_numaux == 0)
968
118
      aux.x_scn.x_comdat = 0;
969
41
    else
970
41
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
41
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
22
    {
974
      /* xgettext:c-format */
975
22
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
22
          " section '%s' found"),
977
22
              abfd, symname);
978
22
      continue;
979
22
    }
980
19
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
19
            isym.n_type, isym.n_sclass, 0,
982
19
            isym.n_numaux, &aux);
983
19
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
137
    switch (aux.x_scn.x_comdat)
998
137
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
137
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
137
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
137
        break;
1038
137
      }
1039
1040
137
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
137
    if (*slot == NULL)
1042
0
      return false;
1043
137
    struct comdat_hash_entry *newentry = *slot;
1044
137
    newentry->sec_flags = sec_flags;
1045
137
    newentry->symname = bfd_strdup (symname);
1046
137
    newentry->target_index = isym.n_scnum;
1047
137
    newentry->isym = isym;
1048
137
    newentry->comdat_symbol = -1;
1049
137
  }
1050
458
      else
1051
458
  {
1052
458
    struct comdat_hash_entry *entry = *slot;
1053
1054
458
    if (entry->comdat_symbol != -1)
1055
415
      continue;
1056
1057
43
    char *target_name = strchr (entry->symname, '$');
1058
43
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
43
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
43
    entry->comdat_name = bfd_strdup (symname);
1082
43
  }
1083
617
    }
1084
1085
189
  return true;
1086
189
}
pei-loongarch64.c:fill_comdat_hash
Line
Count
Source
890
133
{
891
133
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
133
  if (! _bfd_coff_get_external_symbols (abfd))
909
19
    return true;
910
911
114
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
114
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
114
  for (struct internal_syment isym;
915
171
       esym < esymend;
916
114
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
57
    {
918
57
      char buf[SYMNMLEN + 1];
919
57
      const char *symname;
920
57
      flagword sec_flags = SEC_LINK_ONCE;
921
922
57
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
57
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
57
      if (symname == NULL)
949
10
  {
950
10
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
10
            abfd);
952
10
    continue;
953
10
  }
954
955
47
      union internal_auxent aux;
956
957
47
      struct comdat_hash_entry needle;
958
47
      needle.target_index = isym.n_scnum;
959
960
47
      void **slot
961
47
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
47
      if (slot == NULL)
963
0
  return false;
964
965
47
      if (*slot == NULL)
966
33
  {
967
33
    if (isym.n_numaux == 0)
968
24
      aux.x_scn.x_comdat = 0;
969
9
    else
970
9
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
9
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
9
    {
974
      /* xgettext:c-format */
975
9
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
9
          " section '%s' found"),
977
9
              abfd, symname);
978
9
      continue;
979
9
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
24
    switch (aux.x_scn.x_comdat)
998
24
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
24
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
24
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
24
        break;
1038
24
      }
1039
1040
24
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
24
    if (*slot == NULL)
1042
0
      return false;
1043
24
    struct comdat_hash_entry *newentry = *slot;
1044
24
    newentry->sec_flags = sec_flags;
1045
24
    newentry->symname = bfd_strdup (symname);
1046
24
    newentry->target_index = isym.n_scnum;
1047
24
    newentry->isym = isym;
1048
24
    newentry->comdat_symbol = -1;
1049
24
  }
1050
14
      else
1051
14
  {
1052
14
    struct comdat_hash_entry *entry = *slot;
1053
1054
14
    if (entry->comdat_symbol != -1)
1055
4
      continue;
1056
1057
10
    char *target_name = strchr (entry->symname, '$');
1058
10
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
10
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
10
    entry->comdat_name = bfd_strdup (symname);
1082
10
  }
1083
47
    }
1084
1085
114
  return true;
1086
114
}
pe-arm-wince.c:fill_comdat_hash
Line
Count
Source
890
31
{
891
31
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
31
  if (! _bfd_coff_get_external_symbols (abfd))
909
12
    return true;
910
911
19
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
19
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
19
  for (struct internal_syment isym;
915
39
       esym < esymend;
916
20
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
20
    {
918
20
      char buf[SYMNMLEN + 1];
919
20
      const char *symname;
920
20
      flagword sec_flags = SEC_LINK_ONCE;
921
922
20
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
20
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
20
      if (symname == NULL)
949
14
  {
950
14
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
14
            abfd);
952
14
    continue;
953
14
  }
954
955
6
      union internal_auxent aux;
956
957
6
      struct comdat_hash_entry needle;
958
6
      needle.target_index = isym.n_scnum;
959
960
6
      void **slot
961
6
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
6
      if (slot == NULL)
963
0
  return false;
964
965
6
      if (*slot == NULL)
966
6
  {
967
6
    if (isym.n_numaux == 0)
968
4
      aux.x_scn.x_comdat = 0;
969
2
    else
970
2
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
2
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
2
    {
974
      /* xgettext:c-format */
975
2
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
2
          " section '%s' found"),
977
2
              abfd, symname);
978
2
      continue;
979
2
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
4
    switch (aux.x_scn.x_comdat)
998
4
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
4
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
4
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
4
        break;
1038
4
      }
1039
1040
4
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
4
    if (*slot == NULL)
1042
0
      return false;
1043
4
    struct comdat_hash_entry *newentry = *slot;
1044
4
    newentry->sec_flags = sec_flags;
1045
4
    newentry->symname = bfd_strdup (symname);
1046
4
    newentry->target_index = isym.n_scnum;
1047
4
    newentry->isym = isym;
1048
4
    newentry->comdat_symbol = -1;
1049
4
  }
1050
0
      else
1051
0
  {
1052
0
    struct comdat_hash_entry *entry = *slot;
1053
1054
0
    if (entry->comdat_symbol != -1)
1055
0
      continue;
1056
1057
0
    char *target_name = strchr (entry->symname, '$');
1058
0
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
0
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
0
    entry->comdat_name = bfd_strdup (symname);
1082
0
  }
1083
6
    }
1084
1085
19
  return true;
1086
19
}
pe-arm.c:fill_comdat_hash
Line
Count
Source
890
31
{
891
31
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
31
  if (! _bfd_coff_get_external_symbols (abfd))
909
12
    return true;
910
911
19
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
19
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
19
  for (struct internal_syment isym;
915
39
       esym < esymend;
916
20
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
20
    {
918
20
      char buf[SYMNMLEN + 1];
919
20
      const char *symname;
920
20
      flagword sec_flags = SEC_LINK_ONCE;
921
922
20
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
20
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
20
      if (symname == NULL)
949
14
  {
950
14
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
14
            abfd);
952
14
    continue;
953
14
  }
954
955
6
      union internal_auxent aux;
956
957
6
      struct comdat_hash_entry needle;
958
6
      needle.target_index = isym.n_scnum;
959
960
6
      void **slot
961
6
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
6
      if (slot == NULL)
963
0
  return false;
964
965
6
      if (*slot == NULL)
966
6
  {
967
6
    if (isym.n_numaux == 0)
968
4
      aux.x_scn.x_comdat = 0;
969
2
    else
970
2
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
2
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
2
    {
974
      /* xgettext:c-format */
975
2
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
2
          " section '%s' found"),
977
2
              abfd, symname);
978
2
      continue;
979
2
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
4
    switch (aux.x_scn.x_comdat)
998
4
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
4
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
4
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
4
        break;
1038
4
      }
1039
1040
4
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
4
    if (*slot == NULL)
1042
0
      return false;
1043
4
    struct comdat_hash_entry *newentry = *slot;
1044
4
    newentry->sec_flags = sec_flags;
1045
4
    newentry->symname = bfd_strdup (symname);
1046
4
    newentry->target_index = isym.n_scnum;
1047
4
    newentry->isym = isym;
1048
4
    newentry->comdat_symbol = -1;
1049
4
  }
1050
0
      else
1051
0
  {
1052
0
    struct comdat_hash_entry *entry = *slot;
1053
1054
0
    if (entry->comdat_symbol != -1)
1055
0
      continue;
1056
1057
0
    char *target_name = strchr (entry->symname, '$');
1058
0
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
0
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
0
    entry->comdat_name = bfd_strdup (symname);
1082
0
  }
1083
6
    }
1084
1085
19
  return true;
1086
19
}
pe-i386.c:fill_comdat_hash
Line
Count
Source
890
175
{
891
175
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
175
  if (! _bfd_coff_get_external_symbols (abfd))
909
91
    return true;
910
911
84
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
84
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
84
  for (struct internal_syment isym;
915
172
       esym < esymend;
916
88
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
88
    {
918
88
      char buf[SYMNMLEN + 1];
919
88
      const char *symname;
920
88
      flagword sec_flags = SEC_LINK_ONCE;
921
922
88
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
88
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
88
      if (symname == NULL)
949
33
  {
950
33
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
33
            abfd);
952
33
    continue;
953
33
  }
954
955
55
      union internal_auxent aux;
956
957
55
      struct comdat_hash_entry needle;
958
55
      needle.target_index = isym.n_scnum;
959
960
55
      void **slot
961
55
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
55
      if (slot == NULL)
963
0
  return false;
964
965
55
      if (*slot == NULL)
966
47
  {
967
47
    if (isym.n_numaux == 0)
968
38
      aux.x_scn.x_comdat = 0;
969
9
    else
970
9
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
9
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
7
    {
974
      /* xgettext:c-format */
975
7
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
7
          " section '%s' found"),
977
7
              abfd, symname);
978
7
      continue;
979
7
    }
980
2
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
2
            isym.n_type, isym.n_sclass, 0,
982
2
            isym.n_numaux, &aux);
983
2
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
40
    switch (aux.x_scn.x_comdat)
998
40
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
40
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
40
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
40
        break;
1038
40
      }
1039
1040
40
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
40
    if (*slot == NULL)
1042
0
      return false;
1043
40
    struct comdat_hash_entry *newentry = *slot;
1044
40
    newentry->sec_flags = sec_flags;
1045
40
    newentry->symname = bfd_strdup (symname);
1046
40
    newentry->target_index = isym.n_scnum;
1047
40
    newentry->isym = isym;
1048
40
    newentry->comdat_symbol = -1;
1049
40
  }
1050
8
      else
1051
8
  {
1052
8
    struct comdat_hash_entry *entry = *slot;
1053
1054
8
    if (entry->comdat_symbol != -1)
1055
3
      continue;
1056
1057
5
    char *target_name = strchr (entry->symname, '$');
1058
5
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
5
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
5
    entry->comdat_name = bfd_strdup (symname);
1082
5
  }
1083
55
    }
1084
1085
84
  return true;
1086
84
}
pe-mcore.c:fill_comdat_hash
Line
Count
Source
890
26
{
891
26
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
26
  if (! _bfd_coff_get_external_symbols (abfd))
909
3
    return true;
910
911
23
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
23
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
23
  for (struct internal_syment isym;
915
55
       esym < esymend;
916
32
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
32
    {
918
32
      char buf[SYMNMLEN + 1];
919
32
      const char *symname;
920
32
      flagword sec_flags = SEC_LINK_ONCE;
921
922
32
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
32
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
32
      if (symname == NULL)
949
9
  {
950
9
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
9
            abfd);
952
9
    continue;
953
9
  }
954
955
23
      union internal_auxent aux;
956
957
23
      struct comdat_hash_entry needle;
958
23
      needle.target_index = isym.n_scnum;
959
960
23
      void **slot
961
23
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
23
      if (slot == NULL)
963
0
  return false;
964
965
23
      if (*slot == NULL)
966
22
  {
967
22
    if (isym.n_numaux == 0)
968
9
      aux.x_scn.x_comdat = 0;
969
13
    else
970
13
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
13
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
5
    {
974
      /* xgettext:c-format */
975
5
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
5
          " section '%s' found"),
977
5
              abfd, symname);
978
5
      continue;
979
5
    }
980
8
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
8
            isym.n_type, isym.n_sclass, 0,
982
8
            isym.n_numaux, &aux);
983
8
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
17
    switch (aux.x_scn.x_comdat)
998
17
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
17
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
17
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
17
        break;
1038
17
      }
1039
1040
17
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
17
    if (*slot == NULL)
1042
0
      return false;
1043
17
    struct comdat_hash_entry *newentry = *slot;
1044
17
    newentry->sec_flags = sec_flags;
1045
17
    newentry->symname = bfd_strdup (symname);
1046
17
    newentry->target_index = isym.n_scnum;
1047
17
    newentry->isym = isym;
1048
17
    newentry->comdat_symbol = -1;
1049
17
  }
1050
1
      else
1051
1
  {
1052
1
    struct comdat_hash_entry *entry = *slot;
1053
1054
1
    if (entry->comdat_symbol != -1)
1055
0
      continue;
1056
1057
1
    char *target_name = strchr (entry->symname, '$');
1058
1
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
1
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
1
    entry->comdat_name = bfd_strdup (symname);
1082
1
  }
1083
23
    }
1084
1085
23
  return true;
1086
23
}
pe-sh.c:fill_comdat_hash
Line
Count
Source
890
45
{
891
45
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
45
  if (! _bfd_coff_get_external_symbols (abfd))
909
15
    return true;
910
911
30
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
30
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
30
  for (struct internal_syment isym;
915
58
       esym < esymend;
916
30
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
28
    {
918
28
      char buf[SYMNMLEN + 1];
919
28
      const char *symname;
920
28
      flagword sec_flags = SEC_LINK_ONCE;
921
922
28
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
28
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
28
      if (symname == NULL)
949
6
  {
950
6
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
6
            abfd);
952
6
    continue;
953
6
  }
954
955
22
      union internal_auxent aux;
956
957
22
      struct comdat_hash_entry needle;
958
22
      needle.target_index = isym.n_scnum;
959
960
22
      void **slot
961
22
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
22
      if (slot == NULL)
963
0
  return false;
964
965
22
      if (*slot == NULL)
966
16
  {
967
16
    if (isym.n_numaux == 0)
968
10
      aux.x_scn.x_comdat = 0;
969
6
    else
970
6
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
6
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
5
    {
974
      /* xgettext:c-format */
975
5
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
5
          " section '%s' found"),
977
5
              abfd, symname);
978
5
      continue;
979
5
    }
980
1
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
1
            isym.n_type, isym.n_sclass, 0,
982
1
            isym.n_numaux, &aux);
983
1
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
11
    switch (aux.x_scn.x_comdat)
998
11
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
11
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
11
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
11
        break;
1038
11
      }
1039
1040
11
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
11
    if (*slot == NULL)
1042
0
      return false;
1043
11
    struct comdat_hash_entry *newentry = *slot;
1044
11
    newentry->sec_flags = sec_flags;
1045
11
    newentry->symname = bfd_strdup (symname);
1046
11
    newentry->target_index = isym.n_scnum;
1047
11
    newentry->isym = isym;
1048
11
    newentry->comdat_symbol = -1;
1049
11
  }
1050
6
      else
1051
6
  {
1052
6
    struct comdat_hash_entry *entry = *slot;
1053
1054
6
    if (entry->comdat_symbol != -1)
1055
4
      continue;
1056
1057
2
    char *target_name = strchr (entry->symname, '$');
1058
2
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
2
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
2
    entry->comdat_name = bfd_strdup (symname);
1082
2
  }
1083
22
    }
1084
1085
30
  return true;
1086
30
}
pei-arm-wince.c:fill_comdat_hash
Line
Count
Source
890
23
{
891
23
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
23
  if (! _bfd_coff_get_external_symbols (abfd))
909
16
    return true;
910
911
7
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
7
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
7
  for (struct internal_syment isym;
915
8
       esym < esymend;
916
7
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
1
    {
918
1
      char buf[SYMNMLEN + 1];
919
1
      const char *symname;
920
1
      flagword sec_flags = SEC_LINK_ONCE;
921
922
1
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
1
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
1
      if (symname == NULL)
949
0
  {
950
0
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
0
            abfd);
952
0
    continue;
953
0
  }
954
955
1
      union internal_auxent aux;
956
957
1
      struct comdat_hash_entry needle;
958
1
      needle.target_index = isym.n_scnum;
959
960
1
      void **slot
961
1
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
1
      if (slot == NULL)
963
0
  return false;
964
965
1
      if (*slot == NULL)
966
1
  {
967
1
    if (isym.n_numaux == 0)
968
0
      aux.x_scn.x_comdat = 0;
969
1
    else
970
1
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
1
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
1
    {
974
      /* xgettext:c-format */
975
1
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
1
          " section '%s' found"),
977
1
              abfd, symname);
978
1
      continue;
979
1
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
0
    switch (aux.x_scn.x_comdat)
998
0
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
0
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
0
        break;
1038
0
      }
1039
1040
0
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
0
    if (*slot == NULL)
1042
0
      return false;
1043
0
    struct comdat_hash_entry *newentry = *slot;
1044
0
    newentry->sec_flags = sec_flags;
1045
0
    newentry->symname = bfd_strdup (symname);
1046
0
    newentry->target_index = isym.n_scnum;
1047
0
    newentry->isym = isym;
1048
0
    newentry->comdat_symbol = -1;
1049
0
  }
1050
0
      else
1051
0
  {
1052
0
    struct comdat_hash_entry *entry = *slot;
1053
1054
0
    if (entry->comdat_symbol != -1)
1055
0
      continue;
1056
1057
0
    char *target_name = strchr (entry->symname, '$');
1058
0
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
0
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
0
    entry->comdat_name = bfd_strdup (symname);
1082
0
  }
1083
1
    }
1084
1085
7
  return true;
1086
7
}
pei-arm.c:fill_comdat_hash
Line
Count
Source
890
105
{
891
105
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
105
  if (! _bfd_coff_get_external_symbols (abfd))
909
59
    return true;
910
911
46
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
46
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
46
  for (struct internal_syment isym;
915
93
       esym < esymend;
916
47
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
47
    {
918
47
      char buf[SYMNMLEN + 1];
919
47
      const char *symname;
920
47
      flagword sec_flags = SEC_LINK_ONCE;
921
922
47
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
47
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
47
      if (symname == NULL)
949
25
  {
950
25
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
25
            abfd);
952
25
    continue;
953
25
  }
954
955
22
      union internal_auxent aux;
956
957
22
      struct comdat_hash_entry needle;
958
22
      needle.target_index = isym.n_scnum;
959
960
22
      void **slot
961
22
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
22
      if (slot == NULL)
963
0
  return false;
964
965
22
      if (*slot == NULL)
966
18
  {
967
18
    if (isym.n_numaux == 0)
968
15
      aux.x_scn.x_comdat = 0;
969
3
    else
970
3
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
3
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
3
    {
974
      /* xgettext:c-format */
975
3
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
3
          " section '%s' found"),
977
3
              abfd, symname);
978
3
      continue;
979
3
    }
980
0
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
0
            isym.n_type, isym.n_sclass, 0,
982
0
            isym.n_numaux, &aux);
983
0
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
15
    switch (aux.x_scn.x_comdat)
998
15
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
15
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
15
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
15
        break;
1038
15
      }
1039
1040
15
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
15
    if (*slot == NULL)
1042
0
      return false;
1043
15
    struct comdat_hash_entry *newentry = *slot;
1044
15
    newentry->sec_flags = sec_flags;
1045
15
    newentry->symname = bfd_strdup (symname);
1046
15
    newentry->target_index = isym.n_scnum;
1047
15
    newentry->isym = isym;
1048
15
    newentry->comdat_symbol = -1;
1049
15
  }
1050
4
      else
1051
4
  {
1052
4
    struct comdat_hash_entry *entry = *slot;
1053
1054
4
    if (entry->comdat_symbol != -1)
1055
2
      continue;
1056
1057
2
    char *target_name = strchr (entry->symname, '$');
1058
2
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
2
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
2
    entry->comdat_name = bfd_strdup (symname);
1082
2
  }
1083
22
    }
1084
1085
46
  return true;
1086
46
}
pei-mcore.c:fill_comdat_hash
Line
Count
Source
890
45
{
891
45
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
45
  if (! _bfd_coff_get_external_symbols (abfd))
909
23
    return true;
910
911
22
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
22
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
22
  for (struct internal_syment isym;
915
96
       esym < esymend;
916
74
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
74
    {
918
74
      char buf[SYMNMLEN + 1];
919
74
      const char *symname;
920
74
      flagword sec_flags = SEC_LINK_ONCE;
921
922
74
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
74
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
74
      if (symname == NULL)
949
22
  {
950
22
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
22
            abfd);
952
22
    continue;
953
22
  }
954
955
52
      union internal_auxent aux;
956
957
52
      struct comdat_hash_entry needle;
958
52
      needle.target_index = isym.n_scnum;
959
960
52
      void **slot
961
52
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
52
      if (slot == NULL)
963
0
  return false;
964
965
52
      if (*slot == NULL)
966
40
  {
967
40
    if (isym.n_numaux == 0)
968
27
      aux.x_scn.x_comdat = 0;
969
13
    else
970
13
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
13
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
8
    {
974
      /* xgettext:c-format */
975
8
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
8
          " section '%s' found"),
977
8
              abfd, symname);
978
8
      continue;
979
8
    }
980
5
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
5
            isym.n_type, isym.n_sclass, 0,
982
5
            isym.n_numaux, &aux);
983
5
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
32
    switch (aux.x_scn.x_comdat)
998
32
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
32
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
32
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
32
        break;
1038
32
      }
1039
1040
32
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
32
    if (*slot == NULL)
1042
0
      return false;
1043
32
    struct comdat_hash_entry *newentry = *slot;
1044
32
    newentry->sec_flags = sec_flags;
1045
32
    newentry->symname = bfd_strdup (symname);
1046
32
    newentry->target_index = isym.n_scnum;
1047
32
    newentry->isym = isym;
1048
32
    newentry->comdat_symbol = -1;
1049
32
  }
1050
12
      else
1051
12
  {
1052
12
    struct comdat_hash_entry *entry = *slot;
1053
1054
12
    if (entry->comdat_symbol != -1)
1055
8
      continue;
1056
1057
4
    char *target_name = strchr (entry->symname, '$');
1058
4
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
0
#ifndef TARGET_UNDERSCORE
1064
0
#define TARGET_UNDERSCORE 0
1065
0
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
4
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
4
    entry->comdat_name = bfd_strdup (symname);
1082
4
  }
1083
52
    }
1084
1085
22
  return true;
1086
22
}
pei-sh.c:fill_comdat_hash
Line
Count
Source
890
62
{
891
62
  bfd_byte *esymstart, *esym, *esymend;
892
893
  /* Unfortunately, the PE format stores essential information in the
894
     symbol table, of all places.  We need to extract that information
895
     now, so that objdump and the linker will know how to handle the
896
     section without worrying about the symbols.  We can't call
897
     slurp_symtab, because the linker doesn't want the swapped symbols.  */
898
899
  /* COMDAT sections are special.  The first symbol is the section
900
     symbol, which tells what kind of COMDAT section it is.  The
901
     second symbol is the "comdat symbol" - the one with the unique
902
     name.  GNU uses the section symbol for the unique name; MS uses
903
     ".text" for every comdat section.  Sigh.  - DJ.  */
904
905
  /* This is not mirrored in sec_to_styp_flags(), but there doesn't
906
     seem to be a need to, either, and it would at best be rather messy.  */
907
908
62
  if (! _bfd_coff_get_external_symbols (abfd))
909
17
    return true;
910
911
45
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
45
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
45
  for (struct internal_syment isym;
915
134
       esym < esymend;
916
89
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
89
    {
918
89
      char buf[SYMNMLEN + 1];
919
89
      const char *symname;
920
89
      flagword sec_flags = SEC_LINK_ONCE;
921
922
89
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
89
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
89
      if (symname == NULL)
949
26
  {
950
26
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
26
            abfd);
952
26
    continue;
953
26
  }
954
955
63
      union internal_auxent aux;
956
957
63
      struct comdat_hash_entry needle;
958
63
      needle.target_index = isym.n_scnum;
959
960
63
      void **slot
961
63
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
63
      if (slot == NULL)
963
0
  return false;
964
965
63
      if (*slot == NULL)
966
55
  {
967
55
    if (isym.n_numaux == 0)
968
50
      aux.x_scn.x_comdat = 0;
969
5
    else
970
5
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
5
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
4
    {
974
      /* xgettext:c-format */
975
4
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
4
          " section '%s' found"),
977
4
              abfd, symname);
978
4
      continue;
979
4
    }
980
1
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
1
            isym.n_type, isym.n_sclass, 0,
982
1
            isym.n_numaux, &aux);
983
1
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
51
    switch (aux.x_scn.x_comdat)
998
51
      {
999
0
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
0
        sec_flags &= ~SEC_LINK_ONCE;
1004
0
#endif
1005
0
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
0
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
0
        break;
1014
1015
0
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
0
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
0
        break;
1019
1020
        /* debug$S gets this case; other implications ???  */
1021
1022
        /* There may be no symbol.  We'll search the whole
1023
     table.  Is this the right place to play this game?
1024
     Or should we do it when reading it in?  */
1025
0
      case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
1026
#ifdef STRICT_PE_FORMAT
1027
        /* FIXME: This is not currently implemented.  */
1028
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1029
#else
1030
0
        sec_flags &= ~SEC_LINK_ONCE;
1031
0
#endif
1032
0
        break;
1033
1034
51
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
51
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
51
        break;
1038
51
      }
1039
1040
51
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
51
    if (*slot == NULL)
1042
0
      return false;
1043
51
    struct comdat_hash_entry *newentry = *slot;
1044
51
    newentry->sec_flags = sec_flags;
1045
51
    newentry->symname = bfd_strdup (symname);
1046
51
    newentry->target_index = isym.n_scnum;
1047
51
    newentry->isym = isym;
1048
51
    newentry->comdat_symbol = -1;
1049
51
  }
1050
8
      else
1051
8
  {
1052
8
    struct comdat_hash_entry *entry = *slot;
1053
1054
8
    if (entry->comdat_symbol != -1)
1055
0
      continue;
1056
1057
8
    char *target_name = strchr (entry->symname, '$');
1058
8
    if (target_name != NULL)
1059
0
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
0
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
0
        if (strcmp (target_name,
1068
0
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
0
    {
1070
      /* Not the name we're looking for */
1071
0
      continue;
1072
0
    }
1073
0
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
8
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
8
    entry->comdat_name = bfd_strdup (symname);
1082
8
  }
1083
63
    }
1084
1085
45
  return true;
1086
45
}
1087
1088
static bool
1089
insert_coff_comdat_info (bfd *abfd, asection *section, const char *symname,
1090
       long symbol)
1091
6
{
1092
6
  struct coff_comdat_info *comdat;
1093
6
  size_t len = strlen (symname) + 1;
1094
1095
6
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
6
  if (comdat == NULL)
1097
0
    return false;
1098
1099
6
  coff_section_data (abfd, section)->comdat = comdat;
1100
6
  comdat->symbol = symbol;
1101
6
  char *newname = (char *) (comdat + 1);
1102
6
  comdat->name = newname;
1103
6
  memcpy (newname, symname, len);
1104
6
  return true;
1105
6
}
pei-i386.c:insert_coff_comdat_info
Line
Count
Source
1091
2
{
1092
2
  struct coff_comdat_info *comdat;
1093
2
  size_t len = strlen (symname) + 1;
1094
1095
2
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
2
  if (comdat == NULL)
1097
0
    return false;
1098
1099
2
  coff_section_data (abfd, section)->comdat = comdat;
1100
2
  comdat->symbol = symbol;
1101
2
  char *newname = (char *) (comdat + 1);
1102
2
  comdat->name = newname;
1103
2
  memcpy (newname, symname, len);
1104
2
  return true;
1105
2
}
Unexecuted instantiation: pe-x86_64.c:insert_coff_comdat_info
Unexecuted instantiation: pei-x86_64.c:insert_coff_comdat_info
Unexecuted instantiation: pe-aarch64.c:insert_coff_comdat_info
Unexecuted instantiation: pei-aarch64.c:insert_coff_comdat_info
pei-ia64.c:insert_coff_comdat_info
Line
Count
Source
1091
3
{
1092
3
  struct coff_comdat_info *comdat;
1093
3
  size_t len = strlen (symname) + 1;
1094
1095
3
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
3
  if (comdat == NULL)
1097
0
    return false;
1098
1099
3
  coff_section_data (abfd, section)->comdat = comdat;
1100
3
  comdat->symbol = symbol;
1101
3
  char *newname = (char *) (comdat + 1);
1102
3
  comdat->name = newname;
1103
3
  memcpy (newname, symname, len);
1104
3
  return true;
1105
3
}
Unexecuted instantiation: pei-loongarch64.c:insert_coff_comdat_info
Unexecuted instantiation: pe-arm-wince.c:insert_coff_comdat_info
Unexecuted instantiation: pe-arm.c:insert_coff_comdat_info
Unexecuted instantiation: pe-i386.c:insert_coff_comdat_info
Unexecuted instantiation: pe-mcore.c:insert_coff_comdat_info
Unexecuted instantiation: pe-sh.c:insert_coff_comdat_info
Unexecuted instantiation: pei-arm-wince.c:insert_coff_comdat_info
Unexecuted instantiation: pei-arm.c:insert_coff_comdat_info
Unexecuted instantiation: pei-mcore.c:insert_coff_comdat_info
pei-sh.c:insert_coff_comdat_info
Line
Count
Source
1091
1
{
1092
1
  struct coff_comdat_info *comdat;
1093
1
  size_t len = strlen (symname) + 1;
1094
1095
1
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1
  coff_section_data (abfd, section)->comdat = comdat;
1100
1
  comdat->symbol = symbol;
1101
1
  char *newname = (char *) (comdat + 1);
1102
1
  comdat->name = newname;
1103
1
  memcpy (newname, symname, len);
1104
1
  return true;
1105
1
}
1106
1107
static bool
1108
handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
1109
         asection *section)
1110
4.66k
{
1111
4.66k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
3.95k
    {
1113
3.95k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
3.95k
             comdat_delf);
1115
3.95k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
3.95k
    }
1118
1119
4.66k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
4.39k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
4.66k
  struct comdat_hash_entry *found
1124
4.66k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
4.66k
  if (found != NULL)
1126
67
    {
1127
67
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
67
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
67
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
33
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
33
    _bfd_error_handler
1147
33
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
33
       abfd, found->symname);
1149
33
    return false;
1150
33
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
34
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
19
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
19
            " does not match section name '%s'"),
1160
19
          abfd, found->symname, name);
1161
1162
34
      if (found->comdat_symbol != -1)
1163
6
  {
1164
6
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
6
           found->comdat_symbol))
1166
0
      return false;
1167
6
  }
1168
34
      *sec_flags = *sec_flags | found->sec_flags;
1169
34
      return true;
1170
34
    }
1171
4.60k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
4.60k
  return true;
1173
4.66k
}
pei-i386.c:handle_COMDAT
Line
Count
Source
1110
110
{
1111
110
  if (pe_data (abfd)->comdat_hash == NULL)
1112
66
    {
1113
66
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
66
             comdat_delf);
1115
66
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
66
    }
1118
1119
110
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
95
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
110
  struct comdat_hash_entry *found
1124
110
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
110
  if (found != NULL)
1126
6
    {
1127
6
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
6
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
6
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
4
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
4
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
4
            " does not match section name '%s'"),
1160
4
          abfd, found->symname, name);
1161
1162
4
      if (found->comdat_symbol != -1)
1163
2
  {
1164
2
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
2
           found->comdat_symbol))
1166
0
      return false;
1167
2
  }
1168
4
      *sec_flags = *sec_flags | found->sec_flags;
1169
4
      return true;
1170
4
    }
1171
104
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
104
  return true;
1173
110
}
pe-x86_64.c:handle_COMDAT
Line
Count
Source
1110
306
{
1111
306
  if (pe_data (abfd)->comdat_hash == NULL)
1112
290
    {
1113
290
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
290
             comdat_delf);
1115
290
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
290
    }
1118
1119
306
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
304
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
306
  struct comdat_hash_entry *found
1124
306
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
306
  if (found != NULL)
1126
6
    {
1127
6
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
6
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
6
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3
    _bfd_error_handler
1147
3
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3
       abfd, found->symname);
1149
3
    return false;
1150
3
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
3
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
3
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
3
      *sec_flags = *sec_flags | found->sec_flags;
1169
3
      return true;
1170
3
    }
1171
300
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
300
  return true;
1173
306
}
pei-x86_64.c:handle_COMDAT
Line
Count
Source
1110
165
{
1111
165
  if (pe_data (abfd)->comdat_hash == NULL)
1112
111
    {
1113
111
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
111
             comdat_delf);
1115
111
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
111
    }
1118
1119
165
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
141
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
165
  struct comdat_hash_entry *found
1124
165
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
165
  if (found != NULL)
1126
2
    {
1127
2
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
2
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
2
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
2
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
2
      *sec_flags = *sec_flags | found->sec_flags;
1169
2
      return true;
1170
2
    }
1171
163
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
163
  return true;
1173
165
}
pe-aarch64.c:handle_COMDAT
Line
Count
Source
1110
117
{
1111
117
  if (pe_data (abfd)->comdat_hash == NULL)
1112
95
    {
1113
95
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
95
             comdat_delf);
1115
95
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
95
    }
1118
1119
117
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
95
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
117
  struct comdat_hash_entry *found
1124
117
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
117
  if (found != NULL)
1126
4
    {
1127
4
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
4
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
2
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
2
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
2
      *sec_flags = *sec_flags | found->sec_flags;
1169
2
      return true;
1170
2
    }
1171
113
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
113
  return true;
1173
117
}
pei-aarch64.c:handle_COMDAT
Line
Count
Source
1110
2.94k
{
1111
2.94k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
2.72k
    {
1113
2.72k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
2.72k
             comdat_delf);
1115
2.72k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
2.72k
    }
1118
1119
2.94k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
2.87k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
2.94k
  struct comdat_hash_entry *found
1124
2.94k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
2.94k
  if (found != NULL)
1126
8
    {
1127
8
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
8
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
8
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
6
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
6
    _bfd_error_handler
1147
6
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
6
       abfd, found->symname);
1149
6
    return false;
1150
6
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
2
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
2
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
2
      *sec_flags = *sec_flags | found->sec_flags;
1169
2
      return true;
1170
2
    }
1171
2.93k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
2.93k
  return true;
1173
2.94k
}
pei-ia64.c:handle_COMDAT
Line
Count
Source
1110
285
{
1111
285
  if (pe_data (abfd)->comdat_hash == NULL)
1112
150
    {
1113
150
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
150
             comdat_delf);
1115
150
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
150
    }
1118
1119
285
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
211
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
285
  struct comdat_hash_entry *found
1124
285
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
285
  if (found != NULL)
1126
16
    {
1127
16
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
16
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
16
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
7
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
7
    _bfd_error_handler
1147
7
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
7
       abfd, found->symname);
1149
7
    return false;
1150
7
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
9
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
6
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
6
            " does not match section name '%s'"),
1160
6
          abfd, found->symname, name);
1161
1162
9
      if (found->comdat_symbol != -1)
1163
3
  {
1164
3
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
3
           found->comdat_symbol))
1166
0
      return false;
1167
3
  }
1168
9
      *sec_flags = *sec_flags | found->sec_flags;
1169
9
      return true;
1170
9
    }
1171
269
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
269
  return true;
1173
285
}
pei-loongarch64.c:handle_COMDAT
Line
Count
Source
1110
135
{
1111
135
  if (pe_data (abfd)->comdat_hash == NULL)
1112
121
    {
1113
121
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
121
             comdat_delf);
1115
121
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
121
    }
1118
1119
135
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
133
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
135
  struct comdat_hash_entry *found
1124
135
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
135
  if (found != NULL)
1126
4
    {
1127
4
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
4
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
2
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
2
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
2
            " does not match section name '%s'"),
1160
2
          abfd, found->symname, name);
1161
1162
2
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
2
      *sec_flags = *sec_flags | found->sec_flags;
1169
2
      return true;
1170
2
    }
1171
131
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
131
  return true;
1173
135
}
pe-arm-wince.c:handle_COMDAT
Line
Count
Source
1110
32
{
1111
32
  if (pe_data (abfd)->comdat_hash == NULL)
1112
25
    {
1113
25
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
25
             comdat_delf);
1115
25
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
25
    }
1118
1119
32
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
31
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
32
  struct comdat_hash_entry *found
1124
32
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
32
  if (found != NULL)
1126
0
    {
1127
0
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
0
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
0
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
32
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
32
  return true;
1173
32
}
pe-arm.c:handle_COMDAT
Line
Count
Source
1110
32
{
1111
32
  if (pe_data (abfd)->comdat_hash == NULL)
1112
25
    {
1113
25
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
25
             comdat_delf);
1115
25
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
25
    }
1118
1119
32
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
31
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
32
  struct comdat_hash_entry *found
1124
32
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
32
  if (found != NULL)
1126
0
    {
1127
0
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
0
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
0
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
32
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
32
  return true;
1173
32
}
pe-i386.c:handle_COMDAT
Line
Count
Source
1110
190
{
1111
190
  if (pe_data (abfd)->comdat_hash == NULL)
1112
138
    {
1113
138
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
138
             comdat_delf);
1115
138
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
138
    }
1118
1119
190
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
175
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
190
  struct comdat_hash_entry *found
1124
190
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
190
  if (found != NULL)
1126
5
    {
1127
5
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
5
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
5
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3
    _bfd_error_handler
1147
3
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3
       abfd, found->symname);
1149
3
    return false;
1150
3
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
2
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
2
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
2
      *sec_flags = *sec_flags | found->sec_flags;
1169
2
      return true;
1170
2
    }
1171
185
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
185
  return true;
1173
190
}
pe-mcore.c:handle_COMDAT
Line
Count
Source
1110
28
{
1111
28
  if (pe_data (abfd)->comdat_hash == NULL)
1112
24
    {
1113
24
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
24
             comdat_delf);
1115
24
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
24
    }
1118
1119
28
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
26
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
28
  struct comdat_hash_entry *found
1124
28
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
28
  if (found != NULL)
1126
1
    {
1127
1
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
1
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
1
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1
    _bfd_error_handler
1147
1
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1
       abfd, found->symname);
1149
1
    return false;
1150
1
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
27
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
27
  return true;
1173
28
}
pe-sh.c:handle_COMDAT
Line
Count
Source
1110
46
{
1111
46
  if (pe_data (abfd)->comdat_hash == NULL)
1112
44
    {
1113
44
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
44
             comdat_delf);
1115
44
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
44
    }
1118
1119
46
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
45
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
46
  struct comdat_hash_entry *found
1124
46
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
46
  if (found != NULL)
1126
2
    {
1127
2
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
2
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
44
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
44
  return true;
1173
46
}
pei-arm-wince.c:handle_COMDAT
Line
Count
Source
1110
23
{
1111
23
  if (pe_data (abfd)->comdat_hash == NULL)
1112
19
    {
1113
19
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
19
             comdat_delf);
1115
19
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
19
    }
1118
1119
23
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
23
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
23
  struct comdat_hash_entry *found
1124
23
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
23
  if (found != NULL)
1126
0
    {
1127
0
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
0
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
0
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
23
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
23
  return true;
1173
23
}
pei-arm.c:handle_COMDAT
Line
Count
Source
1110
114
{
1111
114
  if (pe_data (abfd)->comdat_hash == NULL)
1112
45
    {
1113
45
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
45
             comdat_delf);
1115
45
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
45
    }
1118
1119
114
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
105
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
114
  struct comdat_hash_entry *found
1124
114
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
114
  if (found != NULL)
1126
0
    {
1127
0
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
0
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
0
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
0
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
0
    _bfd_error_handler
1147
0
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
0
       abfd, found->symname);
1149
0
    return false;
1150
0
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
0
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
0
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
0
            " does not match section name '%s'"),
1160
0
          abfd, found->symname, name);
1161
1162
0
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
0
      *sec_flags = *sec_flags | found->sec_flags;
1169
0
      return true;
1170
0
    }
1171
114
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
114
  return true;
1173
114
}
pei-mcore.c:handle_COMDAT
Line
Count
Source
1110
62
{
1111
62
  if (pe_data (abfd)->comdat_hash == NULL)
1112
36
    {
1113
36
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
36
             comdat_delf);
1115
36
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
36
    }
1118
1119
62
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
45
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
62
  struct comdat_hash_entry *found
1124
62
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
62
  if (found != NULL)
1126
6
    {
1127
6
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
6
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
6
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2
    _bfd_error_handler
1147
2
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2
       abfd, found->symname);
1149
2
    return false;
1150
2
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
4
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
3
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
3
            " does not match section name '%s'"),
1160
3
          abfd, found->symname, name);
1161
1162
4
      if (found->comdat_symbol != -1)
1163
0
  {
1164
0
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
0
           found->comdat_symbol))
1166
0
      return false;
1167
0
  }
1168
4
      *sec_flags = *sec_flags | found->sec_flags;
1169
4
      return true;
1170
4
    }
1171
56
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
56
  return true;
1173
62
}
pei-sh.c:handle_COMDAT
Line
Count
Source
1110
78
{
1111
78
  if (pe_data (abfd)->comdat_hash == NULL)
1112
38
    {
1113
38
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
38
             comdat_delf);
1115
38
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
38
    }
1118
1119
78
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
62
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
78
  struct comdat_hash_entry *found
1124
78
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
78
  if (found != NULL)
1126
7
    {
1127
7
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
7
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
7
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3
    _bfd_error_handler
1147
3
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3
       abfd, found->symname);
1149
3
    return false;
1150
3
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
4
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
4
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
4
            " does not match section name '%s'"),
1160
4
          abfd, found->symname, name);
1161
1162
4
      if (found->comdat_symbol != -1)
1163
1
  {
1164
1
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1
           found->comdat_symbol))
1166
0
      return false;
1167
1
  }
1168
4
      *sec_flags = *sec_flags | found->sec_flags;
1169
4
      return true;
1170
4
    }
1171
71
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
71
  return true;
1173
78
}
1174
1175
1176
/* The PE version; see above for the general comments.
1177
1178
   Since to set the SEC_LINK_ONCE and associated flags, we have to
1179
   look at the symbol table anyway, we return the symbol table index
1180
   of the symbol being used as the COMDAT symbol.  This is admittedly
1181
   ugly, but there's really nowhere else that we have access to the
1182
   required information.  FIXME: Is the COMDAT symbol index used for
1183
   any purpose other than objdump?  */
1184
1185
static bool
1186
styp_to_sec_flags (bfd *abfd,
1187
       void * hdr,
1188
       const char *name,
1189
       asection *section,
1190
       flagword *flags_ptr)
1191
30.5k
{
1192
30.5k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
30.5k
  unsigned long styp_flags = internal_s->s_flags;
1194
30.5k
  flagword sec_flags;
1195
30.5k
  bool result = true;
1196
30.5k
  bool is_dbg = false;
1197
1198
30.5k
  if (startswith (name, DOT_DEBUG)
1199
30.5k
      || startswith (name, DOT_ZDEBUG)
1200
30.5k
#ifdef COFF_LONG_SECTION_NAMES
1201
30.5k
      || startswith (name, GNU_LINKONCE_WI)
1202
30.5k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
30.5k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
30.5k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
30.5k
      || startswith (name, GNU_DEBUGLINK)
1207
30.5k
      || startswith (name, GNU_DEBUGALTLINK)
1208
30.5k
#endif
1209
30.5k
      || startswith (name, ".stab"))
1210
696
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
30.5k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
30.5k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
20.7k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
180k
  while (styp_flags)
1220
150k
    {
1221
150k
      unsigned long flag = styp_flags & - styp_flags;
1222
150k
      char * unhandled = NULL;
1223
1224
150k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
150k
      switch (flag)
1231
150k
  {
1232
798
  case STYP_DSECT:
1233
798
    unhandled = "STYP_DSECT";
1234
798
    break;
1235
781
  case STYP_GROUP:
1236
781
    unhandled = "STYP_GROUP";
1237
781
    break;
1238
800
  case STYP_COPY:
1239
800
    unhandled = "STYP_COPY";
1240
800
    break;
1241
747
  case STYP_OVER:
1242
747
    unhandled = "STYP_OVER";
1243
747
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
7.59k
  case STYP_NOLOAD:
1246
7.59k
    sec_flags |= SEC_NEVER_LOAD;
1247
7.59k
    break;
1248
0
#endif
1249
9.80k
  case IMAGE_SCN_MEM_READ:
1250
9.80k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
9.80k
    break;
1252
4.88k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
4.88k
    break;
1255
844
  case IMAGE_SCN_LNK_OTHER:
1256
844
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
844
    break;
1258
723
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
723
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
723
    break;
1261
5.71k
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
5.71k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
5.71k
        " %s in section %s"),
1268
5.71k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
5.71k
    break;
1270
6.45k
  case IMAGE_SCN_MEM_EXECUTE:
1271
6.45k
    sec_flags |= SEC_CODE;
1272
6.45k
    break;
1273
3.34k
  case IMAGE_SCN_MEM_WRITE:
1274
3.34k
    sec_flags &= ~ SEC_READONLY;
1275
3.34k
    break;
1276
6.05k
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
6.05k
       if (is_dbg
1283
6.05k
#ifdef _COMMENT
1284
6.05k
        || strcmp (name, _COMMENT) == 0
1285
6.05k
#endif
1286
6.05k
        )
1287
315
      {
1288
315
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
315
      }
1290
6.05k
    break;
1291
8.02k
  case IMAGE_SCN_MEM_SHARED:
1292
8.02k
    sec_flags |= SEC_COFF_SHARED;
1293
8.02k
    break;
1294
7.82k
  case IMAGE_SCN_LNK_REMOVE:
1295
7.82k
    if (!is_dbg)
1296
7.63k
      sec_flags |= SEC_EXCLUDE;
1297
7.82k
    break;
1298
7.68k
  case IMAGE_SCN_CNT_CODE:
1299
7.68k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
7.68k
    break;
1301
5.90k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
5.90k
    if (is_dbg)
1303
230
      sec_flags |= SEC_DEBUGGING;
1304
5.67k
    else
1305
5.67k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
5.90k
    break;
1307
4.54k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
4.54k
    sec_flags |= SEC_ALLOC;
1309
4.54k
    break;
1310
2.40k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
#ifdef COFF_PAGE_SIZE
1318
2.33k
    sec_flags |= SEC_DEBUGGING;
1319
#endif
1320
2.40k
    break;
1321
4.66k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
4.66k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
33
      result = false;
1325
4.66k
    break;
1326
60.7k
  default:
1327
    /* Silently ignore for now.  */
1328
60.7k
    break;
1329
150k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
150k
      if (unhandled != NULL)
1333
4.69k
  {
1334
4.69k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
4.69k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
4.69k
       abfd, name, unhandled, flag);
1338
4.69k
    result = false;
1339
4.69k
  }
1340
150k
    }
1341
1342
30.5k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
30.5k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
5.98k
  if (startswith (name, ".gnu.linkonce"))
1355
7
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
30.5k
  if (flags_ptr)
1359
30.5k
    * flags_ptr = sec_flags;
1360
1361
30.5k
  return result;
1362
30.5k
}
pei-i386.c:styp_to_sec_flags
Line
Count
Source
1191
1.13k
{
1192
1.13k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
1.13k
  unsigned long styp_flags = internal_s->s_flags;
1194
1.13k
  flagword sec_flags;
1195
1.13k
  bool result = true;
1196
1.13k
  bool is_dbg = false;
1197
1198
1.13k
  if (startswith (name, DOT_DEBUG)
1199
1.13k
      || startswith (name, DOT_ZDEBUG)
1200
1.13k
#ifdef COFF_LONG_SECTION_NAMES
1201
1.13k
      || startswith (name, GNU_LINKONCE_WI)
1202
1.13k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
1.13k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
1.13k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
1.13k
      || startswith (name, GNU_DEBUGLINK)
1207
1.13k
      || startswith (name, GNU_DEBUGALTLINK)
1208
1.13k
#endif
1209
1.13k
      || startswith (name, ".stab"))
1210
38
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
1.13k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
1.13k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
683
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
4.92k
  while (styp_flags)
1220
3.78k
    {
1221
3.78k
      unsigned long flag = styp_flags & - styp_flags;
1222
3.78k
      char * unhandled = NULL;
1223
1224
3.78k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
3.78k
      switch (flag)
1231
3.78k
  {
1232
35
  case STYP_DSECT:
1233
35
    unhandled = "STYP_DSECT";
1234
35
    break;
1235
37
  case STYP_GROUP:
1236
37
    unhandled = "STYP_GROUP";
1237
37
    break;
1238
39
  case STYP_COPY:
1239
39
    unhandled = "STYP_COPY";
1240
39
    break;
1241
20
  case STYP_OVER:
1242
20
    unhandled = "STYP_OVER";
1243
20
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
81
  case STYP_NOLOAD:
1246
81
    sec_flags |= SEC_NEVER_LOAD;
1247
81
    break;
1248
0
#endif
1249
455
  case IMAGE_SCN_MEM_READ:
1250
455
    sec_flags &= ~SEC_COFF_NOREAD;
1251
455
    break;
1252
134
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
134
    break;
1255
28
  case IMAGE_SCN_LNK_OTHER:
1256
28
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
28
    break;
1258
33
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
33
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
33
    break;
1261
122
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
122
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
122
        " %s in section %s"),
1268
122
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
122
    break;
1270
141
  case IMAGE_SCN_MEM_EXECUTE:
1271
141
    sec_flags |= SEC_CODE;
1272
141
    break;
1273
137
  case IMAGE_SCN_MEM_WRITE:
1274
137
    sec_flags &= ~ SEC_READONLY;
1275
137
    break;
1276
161
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
161
       if (is_dbg
1283
161
#ifdef _COMMENT
1284
161
        || strcmp (name, _COMMENT) == 0
1285
161
#endif
1286
161
        )
1287
20
      {
1288
20
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
20
      }
1290
161
    break;
1291
70
  case IMAGE_SCN_MEM_SHARED:
1292
70
    sec_flags |= SEC_COFF_SHARED;
1293
70
    break;
1294
135
  case IMAGE_SCN_LNK_REMOVE:
1295
135
    if (!is_dbg)
1296
116
      sec_flags |= SEC_EXCLUDE;
1297
135
    break;
1298
148
  case IMAGE_SCN_CNT_CODE:
1299
148
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
148
    break;
1301
345
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
345
    if (is_dbg)
1303
20
      sec_flags |= SEC_DEBUGGING;
1304
325
    else
1305
325
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
345
    break;
1307
68
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
68
    sec_flags |= SEC_ALLOC;
1309
68
    break;
1310
64
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
64
#ifdef COFF_PAGE_SIZE
1318
64
    sec_flags |= SEC_DEBUGGING;
1319
64
#endif
1320
64
    break;
1321
110
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
110
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
110
    break;
1326
1.42k
  default:
1327
    /* Silently ignore for now.  */
1328
1.42k
    break;
1329
3.78k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
3.78k
      if (unhandled != NULL)
1333
192
  {
1334
192
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
192
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
192
       abfd, name, unhandled, flag);
1338
192
    result = false;
1339
192
  }
1340
3.78k
    }
1341
1342
1.13k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
1.13k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
1.13k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
1.13k
  if (startswith (name, ".gnu.linkonce"))
1355
7
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
1.13k
#endif
1357
1358
1.13k
  if (flags_ptr)
1359
1.13k
    * flags_ptr = sec_flags;
1360
1361
1.13k
  return result;
1362
1.13k
}
pe-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
1.91k
{
1192
1.91k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
1.91k
  unsigned long styp_flags = internal_s->s_flags;
1194
1.91k
  flagword sec_flags;
1195
1.91k
  bool result = true;
1196
1.91k
  bool is_dbg = false;
1197
1198
1.91k
  if (startswith (name, DOT_DEBUG)
1199
1.91k
      || startswith (name, DOT_ZDEBUG)
1200
1.91k
#ifdef COFF_LONG_SECTION_NAMES
1201
1.91k
      || startswith (name, GNU_LINKONCE_WI)
1202
1.91k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
1.91k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
1.91k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
1.91k
      || startswith (name, GNU_DEBUGLINK)
1207
1.91k
      || startswith (name, GNU_DEBUGALTLINK)
1208
1.91k
#endif
1209
1.91k
      || startswith (name, ".stab"))
1210
25
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
1.91k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
1.91k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
1.63k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
12.2k
  while (styp_flags)
1220
10.3k
    {
1221
10.3k
      unsigned long flag = styp_flags & - styp_flags;
1222
10.3k
      char * unhandled = NULL;
1223
1224
10.3k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
10.3k
      switch (flag)
1231
10.3k
  {
1232
292
  case STYP_DSECT:
1233
292
    unhandled = "STYP_DSECT";
1234
292
    break;
1235
249
  case STYP_GROUP:
1236
249
    unhandled = "STYP_GROUP";
1237
249
    break;
1238
257
  case STYP_COPY:
1239
257
    unhandled = "STYP_COPY";
1240
257
    break;
1241
258
  case STYP_OVER:
1242
258
    unhandled = "STYP_OVER";
1243
258
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
378
  case STYP_NOLOAD:
1246
378
    sec_flags |= SEC_NEVER_LOAD;
1247
378
    break;
1248
0
#endif
1249
284
  case IMAGE_SCN_MEM_READ:
1250
284
    sec_flags &= ~SEC_COFF_NOREAD;
1251
284
    break;
1252
320
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
320
    break;
1255
297
  case IMAGE_SCN_LNK_OTHER:
1256
297
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
297
    break;
1258
214
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
214
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
214
    break;
1261
284
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
284
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
284
        " %s in section %s"),
1268
284
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
284
    break;
1270
333
  case IMAGE_SCN_MEM_EXECUTE:
1271
333
    sec_flags |= SEC_CODE;
1272
333
    break;
1273
245
  case IMAGE_SCN_MEM_WRITE:
1274
245
    sec_flags &= ~ SEC_READONLY;
1275
245
    break;
1276
319
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
319
       if (is_dbg
1283
319
#ifdef _COMMENT
1284
319
        || strcmp (name, _COMMENT) == 0
1285
319
#endif
1286
319
        )
1287
7
      {
1288
7
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
7
      }
1290
319
    break;
1291
290
  case IMAGE_SCN_MEM_SHARED:
1292
290
    sec_flags |= SEC_COFF_SHARED;
1293
290
    break;
1294
261
  case IMAGE_SCN_LNK_REMOVE:
1295
261
    if (!is_dbg)
1296
256
      sec_flags |= SEC_EXCLUDE;
1297
261
    break;
1298
294
  case IMAGE_SCN_CNT_CODE:
1299
294
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
294
    break;
1301
263
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
263
    if (is_dbg)
1303
9
      sec_flags |= SEC_DEBUGGING;
1304
254
    else
1305
254
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
263
    break;
1307
281
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
281
    sec_flags |= SEC_ALLOC;
1309
281
    break;
1310
335
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
335
#ifdef COFF_PAGE_SIZE
1318
335
    sec_flags |= SEC_DEBUGGING;
1319
335
#endif
1320
335
    break;
1321
306
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
306
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3
      result = false;
1325
306
    break;
1326
4.56k
  default:
1327
    /* Silently ignore for now.  */
1328
4.56k
    break;
1329
10.3k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
10.3k
      if (unhandled != NULL)
1333
1.56k
  {
1334
1.56k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
1.56k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
1.56k
       abfd, name, unhandled, flag);
1338
1.56k
    result = false;
1339
1.56k
  }
1340
10.3k
    }
1341
1342
1.91k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
1.91k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
1.91k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
1.91k
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
1.91k
#endif
1357
1358
1.91k
  if (flags_ptr)
1359
1.91k
    * flags_ptr = sec_flags;
1360
1361
1.91k
  return result;
1362
1.91k
}
pei-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
919
{
1192
919
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
919
  unsigned long styp_flags = internal_s->s_flags;
1194
919
  flagword sec_flags;
1195
919
  bool result = true;
1196
919
  bool is_dbg = false;
1197
1198
919
  if (startswith (name, DOT_DEBUG)
1199
919
      || startswith (name, DOT_ZDEBUG)
1200
919
#ifdef COFF_LONG_SECTION_NAMES
1201
919
      || startswith (name, GNU_LINKONCE_WI)
1202
919
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
919
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
919
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
919
      || startswith (name, GNU_DEBUGLINK)
1207
919
      || startswith (name, GNU_DEBUGALTLINK)
1208
919
#endif
1209
919
      || startswith (name, ".stab"))
1210
35
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
919
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
919
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
691
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
3.97k
  while (styp_flags)
1220
3.05k
    {
1221
3.05k
      unsigned long flag = styp_flags & - styp_flags;
1222
3.05k
      char * unhandled = NULL;
1223
1224
3.05k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
3.05k
      switch (flag)
1231
3.05k
  {
1232
26
  case STYP_DSECT:
1233
26
    unhandled = "STYP_DSECT";
1234
26
    break;
1235
24
  case STYP_GROUP:
1236
24
    unhandled = "STYP_GROUP";
1237
24
    break;
1238
21
  case STYP_COPY:
1239
21
    unhandled = "STYP_COPY";
1240
21
    break;
1241
28
  case STYP_OVER:
1242
28
    unhandled = "STYP_OVER";
1243
28
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
157
  case STYP_NOLOAD:
1246
157
    sec_flags |= SEC_NEVER_LOAD;
1247
157
    break;
1248
0
#endif
1249
228
  case IMAGE_SCN_MEM_READ:
1250
228
    sec_flags &= ~SEC_COFF_NOREAD;
1251
228
    break;
1252
87
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
87
    break;
1255
26
  case IMAGE_SCN_LNK_OTHER:
1256
26
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
26
    break;
1258
21
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
21
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
21
    break;
1261
92
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
92
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
92
        " %s in section %s"),
1268
92
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
92
    break;
1270
124
  case IMAGE_SCN_MEM_EXECUTE:
1271
124
    sec_flags |= SEC_CODE;
1272
124
    break;
1273
65
  case IMAGE_SCN_MEM_WRITE:
1274
65
    sec_flags &= ~ SEC_READONLY;
1275
65
    break;
1276
154
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
154
       if (is_dbg
1283
154
#ifdef _COMMENT
1284
154
        || strcmp (name, _COMMENT) == 0
1285
154
#endif
1286
154
        )
1287
31
      {
1288
31
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
31
      }
1290
154
    break;
1291
139
  case IMAGE_SCN_MEM_SHARED:
1292
139
    sec_flags |= SEC_COFF_SHARED;
1293
139
    break;
1294
145
  case IMAGE_SCN_LNK_REMOVE:
1295
145
    if (!is_dbg)
1296
134
      sec_flags |= SEC_EXCLUDE;
1297
145
    break;
1298
160
  case IMAGE_SCN_CNT_CODE:
1299
160
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
160
    break;
1301
179
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
179
    if (is_dbg)
1303
31
      sec_flags |= SEC_DEBUGGING;
1304
148
    else
1305
148
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
179
    break;
1307
82
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
82
    sec_flags |= SEC_ALLOC;
1309
82
    break;
1310
68
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
68
#ifdef COFF_PAGE_SIZE
1318
68
    sec_flags |= SEC_DEBUGGING;
1319
68
#endif
1320
68
    break;
1321
165
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
165
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
165
    break;
1326
1.06k
  default:
1327
    /* Silently ignore for now.  */
1328
1.06k
    break;
1329
3.05k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
3.05k
      if (unhandled != NULL)
1333
146
  {
1334
146
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
146
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
146
       abfd, name, unhandled, flag);
1338
146
    result = false;
1339
146
  }
1340
3.05k
    }
1341
1342
919
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
919
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
919
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
919
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
919
#endif
1357
1358
919
  if (flags_ptr)
1359
919
    * flags_ptr = sec_flags;
1360
1361
919
  return result;
1362
919
}
pe-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
2.30k
{
1192
2.30k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
2.30k
  unsigned long styp_flags = internal_s->s_flags;
1194
2.30k
  flagword sec_flags;
1195
2.30k
  bool result = true;
1196
2.30k
  bool is_dbg = false;
1197
1198
2.30k
  if (startswith (name, DOT_DEBUG)
1199
2.30k
      || startswith (name, DOT_ZDEBUG)
1200
2.30k
#ifdef COFF_LONG_SECTION_NAMES
1201
2.30k
      || startswith (name, GNU_LINKONCE_WI)
1202
2.30k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
2.30k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
2.30k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
2.30k
      || startswith (name, GNU_DEBUGLINK)
1207
2.30k
      || startswith (name, GNU_DEBUGALTLINK)
1208
2.30k
#endif
1209
2.30k
      || startswith (name, ".stab"))
1210
113
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
2.30k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
2.30k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
1.37k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
16.5k
  while (styp_flags)
1220
14.2k
    {
1221
14.2k
      unsigned long flag = styp_flags & - styp_flags;
1222
14.2k
      char * unhandled = NULL;
1223
1224
14.2k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
14.2k
      switch (flag)
1231
14.2k
  {
1232
40
  case STYP_DSECT:
1233
40
    unhandled = "STYP_DSECT";
1234
40
    break;
1235
52
  case STYP_GROUP:
1236
52
    unhandled = "STYP_GROUP";
1237
52
    break;
1238
52
  case STYP_COPY:
1239
52
    unhandled = "STYP_COPY";
1240
52
    break;
1241
44
  case STYP_OVER:
1242
44
    unhandled = "STYP_OVER";
1243
44
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
86
  case STYP_NOLOAD:
1246
86
    sec_flags |= SEC_NEVER_LOAD;
1247
86
    break;
1248
0
#endif
1249
932
  case IMAGE_SCN_MEM_READ:
1250
932
    sec_flags &= ~SEC_COFF_NOREAD;
1251
932
    break;
1252
64
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
64
    break;
1255
62
  case IMAGE_SCN_LNK_OTHER:
1256
62
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
62
    break;
1258
48
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
48
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
48
    break;
1261
369
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
369
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
369
        " %s in section %s"),
1268
369
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
369
    break;
1270
1.14k
  case IMAGE_SCN_MEM_EXECUTE:
1271
1.14k
    sec_flags |= SEC_CODE;
1272
1.14k
    break;
1273
874
  case IMAGE_SCN_MEM_WRITE:
1274
874
    sec_flags &= ~ SEC_READONLY;
1275
874
    break;
1276
472
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
472
       if (is_dbg
1283
472
#ifdef _COMMENT
1284
472
        || strcmp (name, _COMMENT) == 0
1285
472
#endif
1286
472
        )
1287
9
      {
1288
9
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
9
      }
1290
472
    break;
1291
1.11k
  case IMAGE_SCN_MEM_SHARED:
1292
1.11k
    sec_flags |= SEC_COFF_SHARED;
1293
1.11k
    break;
1294
87
  case IMAGE_SCN_LNK_REMOVE:
1295
87
    if (!is_dbg)
1296
82
      sec_flags |= SEC_EXCLUDE;
1297
87
    break;
1298
115
  case IMAGE_SCN_CNT_CODE:
1299
115
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
115
    break;
1301
109
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
109
    if (is_dbg)
1303
6
      sec_flags |= SEC_DEBUGGING;
1304
103
    else
1305
103
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
109
    break;
1307
84
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
84
    sec_flags |= SEC_ALLOC;
1309
84
    break;
1310
132
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
132
#ifdef COFF_PAGE_SIZE
1318
132
    sec_flags |= SEC_DEBUGGING;
1319
132
#endif
1320
132
    break;
1321
117
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
117
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
117
    break;
1326
8.29k
  default:
1327
    /* Silently ignore for now.  */
1328
8.29k
    break;
1329
14.2k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
14.2k
      if (unhandled != NULL)
1333
298
  {
1334
298
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
298
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
298
       abfd, name, unhandled, flag);
1338
298
    result = false;
1339
298
  }
1340
14.2k
    }
1341
1342
2.30k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
2.30k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
2.30k
  if (flags_ptr)
1359
2.30k
    * flags_ptr = sec_flags;
1360
1361
2.30k
  return result;
1362
2.30k
}
pei-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
15.0k
{
1192
15.0k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
15.0k
  unsigned long styp_flags = internal_s->s_flags;
1194
15.0k
  flagword sec_flags;
1195
15.0k
  bool result = true;
1196
15.0k
  bool is_dbg = false;
1197
1198
15.0k
  if (startswith (name, DOT_DEBUG)
1199
15.0k
      || startswith (name, DOT_ZDEBUG)
1200
15.0k
#ifdef COFF_LONG_SECTION_NAMES
1201
15.0k
      || startswith (name, GNU_LINKONCE_WI)
1202
15.0k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
15.0k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
15.0k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
15.0k
      || startswith (name, GNU_DEBUGLINK)
1207
15.0k
      || startswith (name, GNU_DEBUGALTLINK)
1208
15.0k
#endif
1209
15.0k
      || startswith (name, ".stab"))
1210
158
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
15.0k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
15.0k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
9.79k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
88.6k
  while (styp_flags)
1220
73.5k
    {
1221
73.5k
      unsigned long flag = styp_flags & - styp_flags;
1222
73.5k
      char * unhandled = NULL;
1223
1224
73.5k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
73.5k
      switch (flag)
1231
73.5k
  {
1232
57
  case STYP_DSECT:
1233
57
    unhandled = "STYP_DSECT";
1234
57
    break;
1235
65
  case STYP_GROUP:
1236
65
    unhandled = "STYP_GROUP";
1237
65
    break;
1238
58
  case STYP_COPY:
1239
58
    unhandled = "STYP_COPY";
1240
58
    break;
1241
48
  case STYP_OVER:
1242
48
    unhandled = "STYP_OVER";
1243
48
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
5.32k
  case STYP_NOLOAD:
1246
5.32k
    sec_flags |= SEC_NEVER_LOAD;
1247
5.32k
    break;
1248
0
#endif
1249
5.29k
  case IMAGE_SCN_MEM_READ:
1250
5.29k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
5.29k
    break;
1252
2.90k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
2.90k
    break;
1255
46
  case IMAGE_SCN_LNK_OTHER:
1256
46
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
46
    break;
1258
48
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
48
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
48
    break;
1261
3.03k
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
3.03k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
3.03k
        " %s in section %s"),
1268
3.03k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
3.03k
    break;
1270
2.92k
  case IMAGE_SCN_MEM_EXECUTE:
1271
2.92k
    sec_flags |= SEC_CODE;
1272
2.92k
    break;
1273
135
  case IMAGE_SCN_MEM_WRITE:
1274
135
    sec_flags &= ~ SEC_READONLY;
1275
135
    break;
1276
2.66k
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
2.66k
       if (is_dbg
1283
2.66k
#ifdef _COMMENT
1284
2.66k
        || strcmp (name, _COMMENT) == 0
1285
2.66k
#endif
1286
2.66k
        )
1287
15
      {
1288
15
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
15
      }
1290
2.66k
    break;
1291
5.17k
  case IMAGE_SCN_MEM_SHARED:
1292
5.17k
    sec_flags |= SEC_COFF_SHARED;
1293
5.17k
    break;
1294
5.51k
  case IMAGE_SCN_LNK_REMOVE:
1295
5.51k
    if (!is_dbg)
1296
5.50k
      sec_flags |= SEC_EXCLUDE;
1297
5.51k
    break;
1298
5.34k
  case IMAGE_SCN_CNT_CODE:
1299
5.34k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
5.34k
    break;
1301
2.88k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
2.88k
    if (is_dbg)
1303
5
      sec_flags |= SEC_DEBUGGING;
1304
2.88k
    else
1305
2.88k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
2.88k
    break;
1307
2.57k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
2.57k
    sec_flags |= SEC_ALLOC;
1309
2.57k
    break;
1310
220
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
220
#ifdef COFF_PAGE_SIZE
1318
220
    sec_flags |= SEC_DEBUGGING;
1319
220
#endif
1320
220
    break;
1321
2.94k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
2.94k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
6
      result = false;
1325
2.94k
    break;
1326
26.3k
  default:
1327
    /* Silently ignore for now.  */
1328
26.3k
    break;
1329
73.5k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
73.5k
      if (unhandled != NULL)
1333
322
  {
1334
322
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
322
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
322
       abfd, name, unhandled, flag);
1338
322
    result = false;
1339
322
  }
1340
73.5k
    }
1341
1342
15.0k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
15.0k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
15.0k
  if (flags_ptr)
1359
15.0k
    * flags_ptr = sec_flags;
1360
1361
15.0k
  return result;
1362
15.0k
}
pei-ia64.c:styp_to_sec_flags
Line
Count
Source
1191
2.43k
{
1192
2.43k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
2.43k
  unsigned long styp_flags = internal_s->s_flags;
1194
2.43k
  flagword sec_flags;
1195
2.43k
  bool result = true;
1196
2.43k
  bool is_dbg = false;
1197
1198
2.43k
  if (startswith (name, DOT_DEBUG)
1199
2.43k
      || startswith (name, DOT_ZDEBUG)
1200
2.43k
#ifdef COFF_LONG_SECTION_NAMES
1201
2.43k
      || startswith (name, GNU_LINKONCE_WI)
1202
2.43k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
2.43k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
2.43k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
2.43k
      || startswith (name, GNU_DEBUGLINK)
1207
2.43k
      || startswith (name, GNU_DEBUGALTLINK)
1208
2.43k
#endif
1209
2.43k
      || startswith (name, ".stab"))
1210
23
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
2.43k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
2.43k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
1.81k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
8.28k
  while (styp_flags)
1220
5.84k
    {
1221
5.84k
      unsigned long flag = styp_flags & - styp_flags;
1222
5.84k
      char * unhandled = NULL;
1223
1224
5.84k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
5.84k
      switch (flag)
1231
5.84k
  {
1232
50
  case STYP_DSECT:
1233
50
    unhandled = "STYP_DSECT";
1234
50
    break;
1235
54
  case STYP_GROUP:
1236
54
    unhandled = "STYP_GROUP";
1237
54
    break;
1238
51
  case STYP_COPY:
1239
51
    unhandled = "STYP_COPY";
1240
51
    break;
1241
52
  case STYP_OVER:
1242
52
    unhandled = "STYP_OVER";
1243
52
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
143
  case STYP_NOLOAD:
1246
143
    sec_flags |= SEC_NEVER_LOAD;
1247
143
    break;
1248
0
#endif
1249
627
  case IMAGE_SCN_MEM_READ:
1250
627
    sec_flags &= ~SEC_COFF_NOREAD;
1251
627
    break;
1252
85
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
85
    break;
1255
46
  case IMAGE_SCN_LNK_OTHER:
1256
46
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
46
    break;
1258
57
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
57
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
57
    break;
1261
137
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
137
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
137
        " %s in section %s"),
1268
137
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
137
    break;
1270
280
  case IMAGE_SCN_MEM_EXECUTE:
1271
280
    sec_flags |= SEC_CODE;
1272
280
    break;
1273
240
  case IMAGE_SCN_MEM_WRITE:
1274
240
    sec_flags &= ~ SEC_READONLY;
1275
240
    break;
1276
190
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
190
       if (is_dbg
1283
190
#ifdef _COMMENT
1284
190
        || strcmp (name, _COMMENT) == 0
1285
190
#endif
1286
190
        )
1287
15
      {
1288
15
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
15
      }
1290
190
    break;
1291
127
  case IMAGE_SCN_MEM_SHARED:
1292
127
    sec_flags |= SEC_COFF_SHARED;
1293
127
    break;
1294
154
  case IMAGE_SCN_LNK_REMOVE:
1295
154
    if (!is_dbg)
1296
144
      sec_flags |= SEC_EXCLUDE;
1297
154
    break;
1298
196
  case IMAGE_SCN_CNT_CODE:
1299
196
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
196
    break;
1301
550
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
550
    if (is_dbg)
1303
12
      sec_flags |= SEC_DEBUGGING;
1304
538
    else
1305
538
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
550
    break;
1307
85
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
85
    sec_flags |= SEC_ALLOC;
1309
85
    break;
1310
146
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
146
#ifdef COFF_PAGE_SIZE
1318
146
    sec_flags |= SEC_DEBUGGING;
1319
146
#endif
1320
146
    break;
1321
285
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
285
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
7
      result = false;
1325
285
    break;
1326
2.29k
  default:
1327
    /* Silently ignore for now.  */
1328
2.29k
    break;
1329
5.84k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
5.84k
      if (unhandled != NULL)
1333
310
  {
1334
310
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
310
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
310
       abfd, name, unhandled, flag);
1338
310
    result = false;
1339
310
  }
1340
5.84k
    }
1341
1342
2.43k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
2.43k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
2.43k
  if (flags_ptr)
1359
2.43k
    * flags_ptr = sec_flags;
1360
1361
2.43k
  return result;
1362
2.43k
}
pei-loongarch64.c:styp_to_sec_flags
Line
Count
Source
1191
673
{
1192
673
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
673
  unsigned long styp_flags = internal_s->s_flags;
1194
673
  flagword sec_flags;
1195
673
  bool result = true;
1196
673
  bool is_dbg = false;
1197
1198
673
  if (startswith (name, DOT_DEBUG)
1199
673
      || startswith (name, DOT_ZDEBUG)
1200
673
#ifdef COFF_LONG_SECTION_NAMES
1201
673
      || startswith (name, GNU_LINKONCE_WI)
1202
673
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
673
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
673
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
673
      || startswith (name, GNU_DEBUGLINK)
1207
673
      || startswith (name, GNU_DEBUGALTLINK)
1208
673
#endif
1209
673
      || startswith (name, ".stab"))
1210
4
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
673
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
673
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
427
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
5.08k
  while (styp_flags)
1220
4.40k
    {
1221
4.40k
      unsigned long flag = styp_flags & - styp_flags;
1222
4.40k
      char * unhandled = NULL;
1223
1224
4.40k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
4.40k
      switch (flag)
1231
4.40k
  {
1232
27
  case STYP_DSECT:
1233
27
    unhandled = "STYP_DSECT";
1234
27
    break;
1235
19
  case STYP_GROUP:
1236
19
    unhandled = "STYP_GROUP";
1237
19
    break;
1238
36
  case STYP_COPY:
1239
36
    unhandled = "STYP_COPY";
1240
36
    break;
1241
39
  case STYP_OVER:
1242
39
    unhandled = "STYP_OVER";
1243
39
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
247
  case STYP_NOLOAD:
1246
247
    sec_flags |= SEC_NEVER_LOAD;
1247
247
    break;
1248
0
#endif
1249
246
  case IMAGE_SCN_MEM_READ:
1250
246
    sec_flags &= ~SEC_COFF_NOREAD;
1251
246
    break;
1252
190
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
190
    break;
1255
45
  case IMAGE_SCN_LNK_OTHER:
1256
45
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
45
    break;
1258
29
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
29
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
29
    break;
1261
234
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
234
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
234
        " %s in section %s"),
1268
234
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
234
    break;
1270
136
  case IMAGE_SCN_MEM_EXECUTE:
1271
136
    sec_flags |= SEC_CODE;
1272
136
    break;
1273
68
  case IMAGE_SCN_MEM_WRITE:
1274
68
    sec_flags &= ~ SEC_READONLY;
1275
68
    break;
1276
218
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
218
       if (is_dbg
1283
218
#ifdef _COMMENT
1284
218
        || strcmp (name, _COMMENT) == 0
1285
218
#endif
1286
218
        )
1287
2
      {
1288
2
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2
      }
1290
218
    break;
1291
194
  case IMAGE_SCN_MEM_SHARED:
1292
194
    sec_flags |= SEC_COFF_SHARED;
1293
194
    break;
1294
271
  case IMAGE_SCN_LNK_REMOVE:
1295
271
    if (!is_dbg)
1296
269
      sec_flags |= SEC_EXCLUDE;
1297
271
    break;
1298
178
  case IMAGE_SCN_CNT_CODE:
1299
178
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
178
    break;
1301
187
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
187
    if (is_dbg)
1303
2
      sec_flags |= SEC_DEBUGGING;
1304
185
    else
1305
185
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
187
    break;
1307
105
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
105
    sec_flags |= SEC_ALLOC;
1309
105
    break;
1310
163
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
163
#ifdef COFF_PAGE_SIZE
1318
163
    sec_flags |= SEC_DEBUGGING;
1319
163
#endif
1320
163
    break;
1321
135
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
135
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
135
    break;
1326
1.64k
  default:
1327
    /* Silently ignore for now.  */
1328
1.64k
    break;
1329
4.40k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
4.40k
      if (unhandled != NULL)
1333
195
  {
1334
195
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
195
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
195
       abfd, name, unhandled, flag);
1338
195
    result = false;
1339
195
  }
1340
4.40k
    }
1341
1342
673
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
673
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
673
  if (flags_ptr)
1359
673
    * flags_ptr = sec_flags;
1360
1361
673
  return result;
1362
673
}
pe-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
119
{
1192
119
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
119
  unsigned long styp_flags = internal_s->s_flags;
1194
119
  flagword sec_flags;
1195
119
  bool result = true;
1196
119
  bool is_dbg = false;
1197
1198
119
  if (startswith (name, DOT_DEBUG)
1199
119
      || startswith (name, DOT_ZDEBUG)
1200
119
#ifdef COFF_LONG_SECTION_NAMES
1201
119
      || startswith (name, GNU_LINKONCE_WI)
1202
119
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
119
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
119
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
119
      || startswith (name, GNU_DEBUGLINK)
1207
119
      || startswith (name, GNU_DEBUGALTLINK)
1208
119
#endif
1209
119
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
119
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
119
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
81
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.23k
  while (styp_flags)
1220
1.11k
    {
1221
1.11k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.11k
      char * unhandled = NULL;
1223
1224
1.11k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.11k
      switch (flag)
1231
1.11k
  {
1232
18
  case STYP_DSECT:
1233
18
    unhandled = "STYP_DSECT";
1234
18
    break;
1235
19
  case STYP_GROUP:
1236
19
    unhandled = "STYP_GROUP";
1237
19
    break;
1238
21
  case STYP_COPY:
1239
21
    unhandled = "STYP_COPY";
1240
21
    break;
1241
25
  case STYP_OVER:
1242
25
    unhandled = "STYP_OVER";
1243
25
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
34
  case STYP_NOLOAD:
1246
34
    sec_flags |= SEC_NEVER_LOAD;
1247
34
    break;
1248
0
#endif
1249
38
  case IMAGE_SCN_MEM_READ:
1250
38
    sec_flags &= ~SEC_COFF_NOREAD;
1251
38
    break;
1252
37
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
37
    break;
1255
23
  case IMAGE_SCN_LNK_OTHER:
1256
23
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
23
    break;
1258
19
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
19
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
19
    break;
1261
53
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
53
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
53
        " %s in section %s"),
1268
53
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
53
    break;
1270
44
  case IMAGE_SCN_MEM_EXECUTE:
1271
44
    sec_flags |= SEC_CODE;
1272
44
    break;
1273
46
  case IMAGE_SCN_MEM_WRITE:
1274
46
    sec_flags &= ~ SEC_READONLY;
1275
46
    break;
1276
60
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
60
       if (is_dbg
1283
60
#ifdef _COMMENT
1284
60
        || strcmp (name, _COMMENT) == 0
1285
60
#endif
1286
60
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
60
    break;
1291
49
  case IMAGE_SCN_MEM_SHARED:
1292
49
    sec_flags |= SEC_COFF_SHARED;
1293
49
    break;
1294
39
  case IMAGE_SCN_LNK_REMOVE:
1295
39
    if (!is_dbg)
1296
39
      sec_flags |= SEC_EXCLUDE;
1297
39
    break;
1298
29
  case IMAGE_SCN_CNT_CODE:
1299
29
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
29
    break;
1301
28
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
28
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
28
    else
1305
28
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
28
    break;
1307
36
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
36
    sec_flags |= SEC_ALLOC;
1309
36
    break;
1310
37
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
37
#ifdef COFF_PAGE_SIZE
1318
37
    sec_flags |= SEC_DEBUGGING;
1319
37
#endif
1320
37
    break;
1321
32
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
32
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
32
    break;
1326
424
  default:
1327
    /* Silently ignore for now.  */
1328
424
    break;
1329
1.11k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.11k
      if (unhandled != NULL)
1333
125
  {
1334
125
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
125
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
125
       abfd, name, unhandled, flag);
1338
125
    result = false;
1339
125
  }
1340
1.11k
    }
1341
1342
119
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
119
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
119
  if (flags_ptr)
1359
119
    * flags_ptr = sec_flags;
1360
1361
119
  return result;
1362
119
}
pe-arm.c:styp_to_sec_flags
Line
Count
Source
1191
119
{
1192
119
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
119
  unsigned long styp_flags = internal_s->s_flags;
1194
119
  flagword sec_flags;
1195
119
  bool result = true;
1196
119
  bool is_dbg = false;
1197
1198
119
  if (startswith (name, DOT_DEBUG)
1199
119
      || startswith (name, DOT_ZDEBUG)
1200
119
#ifdef COFF_LONG_SECTION_NAMES
1201
119
      || startswith (name, GNU_LINKONCE_WI)
1202
119
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
119
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
119
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
119
      || startswith (name, GNU_DEBUGLINK)
1207
119
      || startswith (name, GNU_DEBUGALTLINK)
1208
119
#endif
1209
119
      || startswith (name, ".stab"))
1210
0
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
119
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
119
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
81
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.23k
  while (styp_flags)
1220
1.11k
    {
1221
1.11k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.11k
      char * unhandled = NULL;
1223
1224
1.11k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.11k
      switch (flag)
1231
1.11k
  {
1232
18
  case STYP_DSECT:
1233
18
    unhandled = "STYP_DSECT";
1234
18
    break;
1235
19
  case STYP_GROUP:
1236
19
    unhandled = "STYP_GROUP";
1237
19
    break;
1238
21
  case STYP_COPY:
1239
21
    unhandled = "STYP_COPY";
1240
21
    break;
1241
25
  case STYP_OVER:
1242
25
    unhandled = "STYP_OVER";
1243
25
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
34
  case STYP_NOLOAD:
1246
34
    sec_flags |= SEC_NEVER_LOAD;
1247
34
    break;
1248
0
#endif
1249
38
  case IMAGE_SCN_MEM_READ:
1250
38
    sec_flags &= ~SEC_COFF_NOREAD;
1251
38
    break;
1252
37
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
37
    break;
1255
23
  case IMAGE_SCN_LNK_OTHER:
1256
23
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
23
    break;
1258
19
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
19
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
19
    break;
1261
53
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
53
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
53
        " %s in section %s"),
1268
53
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
53
    break;
1270
44
  case IMAGE_SCN_MEM_EXECUTE:
1271
44
    sec_flags |= SEC_CODE;
1272
44
    break;
1273
46
  case IMAGE_SCN_MEM_WRITE:
1274
46
    sec_flags &= ~ SEC_READONLY;
1275
46
    break;
1276
60
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
60
       if (is_dbg
1283
60
#ifdef _COMMENT
1284
60
        || strcmp (name, _COMMENT) == 0
1285
60
#endif
1286
60
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
60
    break;
1291
49
  case IMAGE_SCN_MEM_SHARED:
1292
49
    sec_flags |= SEC_COFF_SHARED;
1293
49
    break;
1294
39
  case IMAGE_SCN_LNK_REMOVE:
1295
39
    if (!is_dbg)
1296
39
      sec_flags |= SEC_EXCLUDE;
1297
39
    break;
1298
29
  case IMAGE_SCN_CNT_CODE:
1299
29
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
29
    break;
1301
28
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
28
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
28
    else
1305
28
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
28
    break;
1307
36
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
36
    sec_flags |= SEC_ALLOC;
1309
36
    break;
1310
37
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
37
#ifdef COFF_PAGE_SIZE
1318
37
    sec_flags |= SEC_DEBUGGING;
1319
37
#endif
1320
37
    break;
1321
32
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
32
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
32
    break;
1326
424
  default:
1327
    /* Silently ignore for now.  */
1328
424
    break;
1329
1.11k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.11k
      if (unhandled != NULL)
1333
125
  {
1334
125
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
125
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
125
       abfd, name, unhandled, flag);
1338
125
    result = false;
1339
125
  }
1340
1.11k
    }
1341
1342
119
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
119
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
119
  if (flags_ptr)
1359
119
    * flags_ptr = sec_flags;
1360
1361
119
  return result;
1362
119
}
pe-i386.c:styp_to_sec_flags
Line
Count
Source
1191
2.01k
{
1192
2.01k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
2.01k
  unsigned long styp_flags = internal_s->s_flags;
1194
2.01k
  flagword sec_flags;
1195
2.01k
  bool result = true;
1196
2.01k
  bool is_dbg = false;
1197
1198
2.01k
  if (startswith (name, DOT_DEBUG)
1199
2.01k
      || startswith (name, DOT_ZDEBUG)
1200
2.01k
#ifdef COFF_LONG_SECTION_NAMES
1201
2.01k
      || startswith (name, GNU_LINKONCE_WI)
1202
2.01k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
2.01k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
2.01k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
2.01k
      || startswith (name, GNU_DEBUGLINK)
1207
2.01k
      || startswith (name, GNU_DEBUGALTLINK)
1208
2.01k
#endif
1209
2.01k
      || startswith (name, ".stab"))
1210
22
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
2.01k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
2.01k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
1.50k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
10.8k
  while (styp_flags)
1220
8.78k
    {
1221
8.78k
      unsigned long flag = styp_flags & - styp_flags;
1222
8.78k
      char * unhandled = NULL;
1223
1224
8.78k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
8.78k
      switch (flag)
1231
8.78k
  {
1232
82
  case STYP_DSECT:
1233
82
    unhandled = "STYP_DSECT";
1234
82
    break;
1235
96
  case STYP_GROUP:
1236
96
    unhandled = "STYP_GROUP";
1237
96
    break;
1238
90
  case STYP_COPY:
1239
90
    unhandled = "STYP_COPY";
1240
90
    break;
1241
90
  case STYP_OVER:
1242
90
    unhandled = "STYP_OVER";
1243
90
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
266
  case STYP_NOLOAD:
1246
266
    sec_flags |= SEC_NEVER_LOAD;
1247
266
    break;
1248
0
#endif
1249
506
  case IMAGE_SCN_MEM_READ:
1250
506
    sec_flags &= ~SEC_COFF_NOREAD;
1251
506
    break;
1252
226
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
226
    break;
1255
89
  case IMAGE_SCN_LNK_OTHER:
1256
89
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
89
    break;
1258
98
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
98
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
98
    break;
1261
557
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
557
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
557
        " %s in section %s"),
1268
557
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
557
    break;
1270
162
  case IMAGE_SCN_MEM_EXECUTE:
1271
162
    sec_flags |= SEC_CODE;
1272
162
    break;
1273
276
  case IMAGE_SCN_MEM_WRITE:
1274
276
    sec_flags &= ~ SEC_READONLY;
1275
276
    break;
1276
547
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
547
       if (is_dbg
1283
547
#ifdef _COMMENT
1284
547
        || strcmp (name, _COMMENT) == 0
1285
547
#endif
1286
547
        )
1287
17
      {
1288
17
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
17
      }
1290
547
    break;
1291
414
  case IMAGE_SCN_MEM_SHARED:
1292
414
    sec_flags |= SEC_COFF_SHARED;
1293
414
    break;
1294
276
  case IMAGE_SCN_LNK_REMOVE:
1295
276
    if (!is_dbg)
1296
266
      sec_flags |= SEC_EXCLUDE;
1297
276
    break;
1298
342
  case IMAGE_SCN_CNT_CODE:
1299
342
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
342
    break;
1301
215
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
215
    if (is_dbg)
1303
13
      sec_flags |= SEC_DEBUGGING;
1304
202
    else
1305
202
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
215
    break;
1307
185
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
185
    sec_flags |= SEC_ALLOC;
1309
185
    break;
1310
255
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
255
#ifdef COFF_PAGE_SIZE
1318
255
    sec_flags |= SEC_DEBUGGING;
1319
255
#endif
1320
255
    break;
1321
190
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
190
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3
      result = false;
1325
190
    break;
1326
3.82k
  default:
1327
    /* Silently ignore for now.  */
1328
3.82k
    break;
1329
8.78k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
8.78k
      if (unhandled != NULL)
1333
545
  {
1334
545
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
545
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
545
       abfd, name, unhandled, flag);
1338
545
    result = false;
1339
545
  }
1340
8.78k
    }
1341
1342
2.01k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
2.01k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
2.01k
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
2.01k
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
2.01k
#endif
1357
1358
2.01k
  if (flags_ptr)
1359
2.01k
    * flags_ptr = sec_flags;
1360
1361
2.01k
  return result;
1362
2.01k
}
pe-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
526
{
1192
526
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
526
  unsigned long styp_flags = internal_s->s_flags;
1194
526
  flagword sec_flags;
1195
526
  bool result = true;
1196
526
  bool is_dbg = false;
1197
1198
526
  if (startswith (name, DOT_DEBUG)
1199
526
      || startswith (name, DOT_ZDEBUG)
1200
526
#ifdef COFF_LONG_SECTION_NAMES
1201
526
      || startswith (name, GNU_LINKONCE_WI)
1202
526
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
526
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
526
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
526
      || startswith (name, GNU_DEBUGLINK)
1207
526
      || startswith (name, GNU_DEBUGALTLINK)
1208
526
#endif
1209
526
      || startswith (name, ".stab"))
1210
4
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
526
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
526
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
486
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.54k
  while (styp_flags)
1220
1.02k
    {
1221
1.02k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.02k
      char * unhandled = NULL;
1223
1224
1.02k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.02k
      switch (flag)
1231
1.02k
  {
1232
20
  case STYP_DSECT:
1233
20
    unhandled = "STYP_DSECT";
1234
20
    break;
1235
10
  case STYP_GROUP:
1236
10
    unhandled = "STYP_GROUP";
1237
10
    break;
1238
19
  case STYP_COPY:
1239
19
    unhandled = "STYP_COPY";
1240
19
    break;
1241
13
  case STYP_OVER:
1242
13
    unhandled = "STYP_OVER";
1243
13
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
47
  case STYP_NOLOAD:
1246
47
    sec_flags |= SEC_NEVER_LOAD;
1247
47
    break;
1248
0
#endif
1249
40
  case IMAGE_SCN_MEM_READ:
1250
40
    sec_flags &= ~SEC_COFF_NOREAD;
1251
40
    break;
1252
40
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
40
    break;
1255
23
  case IMAGE_SCN_LNK_OTHER:
1256
23
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
23
    break;
1258
15
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
15
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
15
    break;
1261
33
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
33
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
33
        " %s in section %s"),
1268
33
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
33
    break;
1270
45
  case IMAGE_SCN_MEM_EXECUTE:
1271
45
    sec_flags |= SEC_CODE;
1272
45
    break;
1273
31
  case IMAGE_SCN_MEM_WRITE:
1274
31
    sec_flags &= ~ SEC_READONLY;
1275
31
    break;
1276
54
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
54
       if (is_dbg
1283
54
#ifdef _COMMENT
1284
54
        || strcmp (name, _COMMENT) == 0
1285
54
#endif
1286
54
        )
1287
0
      {
1288
0
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
0
      }
1290
54
    break;
1291
27
  case IMAGE_SCN_MEM_SHARED:
1292
27
    sec_flags |= SEC_COFF_SHARED;
1293
27
    break;
1294
32
  case IMAGE_SCN_LNK_REMOVE:
1295
32
    if (!is_dbg)
1296
32
      sec_flags |= SEC_EXCLUDE;
1297
32
    break;
1298
33
  case IMAGE_SCN_CNT_CODE:
1299
33
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
33
    break;
1301
36
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
36
    if (is_dbg)
1303
0
      sec_flags |= SEC_DEBUGGING;
1304
36
    else
1305
36
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
36
    break;
1307
32
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
32
    sec_flags |= SEC_ALLOC;
1309
32
    break;
1310
40
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
40
#ifdef COFF_PAGE_SIZE
1318
40
    sec_flags |= SEC_DEBUGGING;
1319
40
#endif
1320
40
    break;
1321
28
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
28
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1
      result = false;
1325
28
    break;
1326
404
  default:
1327
    /* Silently ignore for now.  */
1328
404
    break;
1329
1.02k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.02k
      if (unhandled != NULL)
1333
100
  {
1334
100
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
100
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
100
       abfd, name, unhandled, flag);
1338
100
    result = false;
1339
100
  }
1340
1.02k
    }
1341
1342
526
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
526
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
526
  if (flags_ptr)
1359
526
    * flags_ptr = sec_flags;
1360
1361
526
  return result;
1362
526
}
pe-sh.c:styp_to_sec_flags
Line
Count
Source
1191
287
{
1192
287
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
287
  unsigned long styp_flags = internal_s->s_flags;
1194
287
  flagword sec_flags;
1195
287
  bool result = true;
1196
287
  bool is_dbg = false;
1197
1198
287
  if (startswith (name, DOT_DEBUG)
1199
287
      || startswith (name, DOT_ZDEBUG)
1200
287
#ifdef COFF_LONG_SECTION_NAMES
1201
287
      || startswith (name, GNU_LINKONCE_WI)
1202
287
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
287
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
287
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
287
      || startswith (name, GNU_DEBUGLINK)
1207
287
      || startswith (name, GNU_DEBUGALTLINK)
1208
287
#endif
1209
287
      || startswith (name, ".stab"))
1210
5
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
287
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
287
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
225
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.99k
  while (styp_flags)
1220
1.71k
    {
1221
1.71k
      unsigned long flag = styp_flags & - styp_flags;
1222
1.71k
      char * unhandled = NULL;
1223
1224
1.71k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
1.71k
      switch (flag)
1231
1.71k
  {
1232
37
  case STYP_DSECT:
1233
37
    unhandled = "STYP_DSECT";
1234
37
    break;
1235
38
  case STYP_GROUP:
1236
38
    unhandled = "STYP_GROUP";
1237
38
    break;
1238
33
  case STYP_COPY:
1239
33
    unhandled = "STYP_COPY";
1240
33
    break;
1241
31
  case STYP_OVER:
1242
31
    unhandled = "STYP_OVER";
1243
31
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
67
  case STYP_NOLOAD:
1246
67
    sec_flags |= SEC_NEVER_LOAD;
1247
67
    break;
1248
0
#endif
1249
62
  case IMAGE_SCN_MEM_READ:
1250
62
    sec_flags &= ~SEC_COFF_NOREAD;
1251
62
    break;
1252
51
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
51
    break;
1255
40
  case IMAGE_SCN_LNK_OTHER:
1256
40
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
40
    break;
1258
31
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
31
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
31
    break;
1261
57
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
57
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
57
        " %s in section %s"),
1268
57
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
57
    break;
1270
68
  case IMAGE_SCN_MEM_EXECUTE:
1271
68
    sec_flags |= SEC_CODE;
1272
68
    break;
1273
59
  case IMAGE_SCN_MEM_WRITE:
1274
59
    sec_flags &= ~ SEC_READONLY;
1275
59
    break;
1276
65
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
65
       if (is_dbg
1283
65
#ifdef _COMMENT
1284
65
        || strcmp (name, _COMMENT) == 0
1285
65
#endif
1286
65
        )
1287
2
      {
1288
2
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2
      }
1290
65
    break;
1291
43
  case IMAGE_SCN_MEM_SHARED:
1292
43
    sec_flags |= SEC_COFF_SHARED;
1293
43
    break;
1294
51
  case IMAGE_SCN_LNK_REMOVE:
1295
51
    if (!is_dbg)
1296
48
      sec_flags |= SEC_EXCLUDE;
1297
51
    break;
1298
64
  case IMAGE_SCN_CNT_CODE:
1299
64
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
64
    break;
1301
54
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
54
    if (is_dbg)
1303
2
      sec_flags |= SEC_DEBUGGING;
1304
52
    else
1305
52
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
54
    break;
1307
67
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
67
    sec_flags |= SEC_ALLOC;
1309
67
    break;
1310
71
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
#ifdef COFF_PAGE_SIZE
1318
    sec_flags |= SEC_DEBUGGING;
1319
#endif
1320
71
    break;
1321
46
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
46
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
46
    break;
1326
676
  default:
1327
    /* Silently ignore for now.  */
1328
676
    break;
1329
1.71k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.71k
      if (unhandled != NULL)
1333
210
  {
1334
210
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
210
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
210
       abfd, name, unhandled, flag);
1338
210
    result = false;
1339
210
  }
1340
1.71k
    }
1341
1342
287
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
287
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
287
  if (flags_ptr)
1359
287
    * flags_ptr = sec_flags;
1360
1361
287
  return result;
1362
287
}
pei-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
333
{
1192
333
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
333
  unsigned long styp_flags = internal_s->s_flags;
1194
333
  flagword sec_flags;
1195
333
  bool result = true;
1196
333
  bool is_dbg = false;
1197
1198
333
  if (startswith (name, DOT_DEBUG)
1199
333
      || startswith (name, DOT_ZDEBUG)
1200
333
#ifdef COFF_LONG_SECTION_NAMES
1201
333
      || startswith (name, GNU_LINKONCE_WI)
1202
333
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
333
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
333
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
333
      || startswith (name, GNU_DEBUGLINK)
1207
333
      || startswith (name, GNU_DEBUGALTLINK)
1208
333
#endif
1209
333
      || startswith (name, ".stab"))
1210
22
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
333
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
333
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
174
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
3.86k
  while (styp_flags)
1220
3.52k
    {
1221
3.52k
      unsigned long flag = styp_flags & - styp_flags;
1222
3.52k
      char * unhandled = NULL;
1223
1224
3.52k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
3.52k
      switch (flag)
1231
3.52k
  {
1232
25
  case STYP_DSECT:
1233
25
    unhandled = "STYP_DSECT";
1234
25
    break;
1235
22
  case STYP_GROUP:
1236
22
    unhandled = "STYP_GROUP";
1237
22
    break;
1238
24
  case STYP_COPY:
1239
24
    unhandled = "STYP_COPY";
1240
24
    break;
1241
16
  case STYP_OVER:
1242
16
    unhandled = "STYP_OVER";
1243
16
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
168
  case STYP_NOLOAD:
1246
168
    sec_flags |= SEC_NEVER_LOAD;
1247
168
    break;
1248
0
#endif
1249
159
  case IMAGE_SCN_MEM_READ:
1250
159
    sec_flags &= ~SEC_COFF_NOREAD;
1251
159
    break;
1252
164
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
164
    break;
1255
25
  case IMAGE_SCN_LNK_OTHER:
1256
25
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
25
    break;
1258
19
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
19
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
19
    break;
1261
150
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
150
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
150
        " %s in section %s"),
1268
150
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
150
    break;
1270
81
  case IMAGE_SCN_MEM_EXECUTE:
1271
81
    sec_flags |= SEC_CODE;
1272
81
    break;
1273
171
  case IMAGE_SCN_MEM_WRITE:
1274
171
    sec_flags &= ~ SEC_READONLY;
1275
171
    break;
1276
207
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
207
       if (is_dbg
1283
207
#ifdef _COMMENT
1284
207
        || strcmp (name, _COMMENT) == 0
1285
207
#endif
1286
207
        )
1287
19
      {
1288
19
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
19
      }
1290
207
    break;
1291
38
  case IMAGE_SCN_MEM_SHARED:
1292
38
    sec_flags |= SEC_COFF_SHARED;
1293
38
    break;
1294
178
  case IMAGE_SCN_LNK_REMOVE:
1295
178
    if (!is_dbg)
1296
167
      sec_flags |= SEC_EXCLUDE;
1297
178
    break;
1298
76
  case IMAGE_SCN_CNT_CODE:
1299
76
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
76
    break;
1301
174
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
174
    if (is_dbg)
1303
11
      sec_flags |= SEC_DEBUGGING;
1304
163
    else
1305
163
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
174
    break;
1307
176
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
176
    sec_flags |= SEC_ALLOC;
1309
176
    break;
1310
191
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
191
#ifdef COFF_PAGE_SIZE
1318
191
    sec_flags |= SEC_DEBUGGING;
1319
191
#endif
1320
191
    break;
1321
23
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
23
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
23
    break;
1326
1.44k
  default:
1327
    /* Silently ignore for now.  */
1328
1.44k
    break;
1329
3.52k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
3.52k
      if (unhandled != NULL)
1333
131
  {
1334
131
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
131
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
131
       abfd, name, unhandled, flag);
1338
131
    result = false;
1339
131
  }
1340
3.52k
    }
1341
1342
333
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
333
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
333
  if (flags_ptr)
1359
333
    * flags_ptr = sec_flags;
1360
1361
333
  return result;
1362
333
}
pei-arm.c:styp_to_sec_flags
Line
Count
Source
1191
1.03k
{
1192
1.03k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
1.03k
  unsigned long styp_flags = internal_s->s_flags;
1194
1.03k
  flagword sec_flags;
1195
1.03k
  bool result = true;
1196
1.03k
  bool is_dbg = false;
1197
1198
1.03k
  if (startswith (name, DOT_DEBUG)
1199
1.03k
      || startswith (name, DOT_ZDEBUG)
1200
1.03k
#ifdef COFF_LONG_SECTION_NAMES
1201
1.03k
      || startswith (name, GNU_LINKONCE_WI)
1202
1.03k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
1.03k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
1.03k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
1.03k
      || startswith (name, GNU_DEBUGLINK)
1207
1.03k
      || startswith (name, GNU_DEBUGALTLINK)
1208
1.03k
#endif
1209
1.03k
      || startswith (name, ".stab"))
1210
23
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
1.03k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
1.03k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
580
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
8.07k
  while (styp_flags)
1220
7.03k
    {
1221
7.03k
      unsigned long flag = styp_flags & - styp_flags;
1222
7.03k
      char * unhandled = NULL;
1223
1224
7.03k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
7.03k
      switch (flag)
1231
7.03k
  {
1232
33
  case STYP_DSECT:
1233
33
    unhandled = "STYP_DSECT";
1234
33
    break;
1235
35
  case STYP_GROUP:
1236
35
    unhandled = "STYP_GROUP";
1237
35
    break;
1238
35
  case STYP_COPY:
1239
35
    unhandled = "STYP_COPY";
1240
35
    break;
1241
28
  case STYP_OVER:
1242
28
    unhandled = "STYP_OVER";
1243
28
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
234
  case STYP_NOLOAD:
1246
234
    sec_flags |= SEC_NEVER_LOAD;
1247
234
    break;
1248
0
#endif
1249
455
  case IMAGE_SCN_MEM_READ:
1250
455
    sec_flags &= ~SEC_COFF_NOREAD;
1251
455
    break;
1252
189
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
189
    break;
1255
33
  case IMAGE_SCN_LNK_OTHER:
1256
33
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
33
    break;
1258
33
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
33
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
33
    break;
1261
308
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
308
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
308
        " %s in section %s"),
1268
308
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
308
    break;
1270
291
  case IMAGE_SCN_MEM_EXECUTE:
1271
291
    sec_flags |= SEC_CODE;
1272
291
    break;
1273
361
  case IMAGE_SCN_MEM_WRITE:
1274
361
    sec_flags &= ~ SEC_READONLY;
1275
361
    break;
1276
447
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
447
       if (is_dbg
1283
447
#ifdef _COMMENT
1284
447
        || strcmp (name, _COMMENT) == 0
1285
447
#endif
1286
447
        )
1287
20
      {
1288
20
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
20
      }
1290
447
    break;
1291
196
  case IMAGE_SCN_MEM_SHARED:
1292
196
    sec_flags |= SEC_COFF_SHARED;
1293
196
    break;
1294
257
  case IMAGE_SCN_LNK_REMOVE:
1295
257
    if (!is_dbg)
1296
245
      sec_flags |= SEC_EXCLUDE;
1297
257
    break;
1298
150
  case IMAGE_SCN_CNT_CODE:
1299
150
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
150
    break;
1301
285
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
285
    if (is_dbg)
1303
12
      sec_flags |= SEC_DEBUGGING;
1304
273
    else
1305
273
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
285
    break;
1307
237
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
237
    sec_flags |= SEC_ALLOC;
1309
237
    break;
1310
243
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
243
#ifdef COFF_PAGE_SIZE
1318
243
    sec_flags |= SEC_DEBUGGING;
1319
243
#endif
1320
243
    break;
1321
114
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
114
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
0
      result = false;
1325
114
    break;
1326
3.07k
  default:
1327
    /* Silently ignore for now.  */
1328
3.07k
    break;
1329
7.03k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
7.03k
      if (unhandled != NULL)
1333
197
  {
1334
197
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
197
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
197
       abfd, name, unhandled, flag);
1338
197
    result = false;
1339
197
  }
1340
7.03k
    }
1341
1342
1.03k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
1.03k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
1.03k
  if (flags_ptr)
1359
1.03k
    * flags_ptr = sec_flags;
1360
1361
1.03k
  return result;
1362
1.03k
}
pei-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
851
{
1192
851
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
851
  unsigned long styp_flags = internal_s->s_flags;
1194
851
  flagword sec_flags;
1195
851
  bool result = true;
1196
851
  bool is_dbg = false;
1197
1198
851
  if (startswith (name, DOT_DEBUG)
1199
851
      || startswith (name, DOT_ZDEBUG)
1200
851
#ifdef COFF_LONG_SECTION_NAMES
1201
851
      || startswith (name, GNU_LINKONCE_WI)
1202
851
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
851
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
851
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
851
      || startswith (name, GNU_DEBUGLINK)
1207
851
      || startswith (name, GNU_DEBUGALTLINK)
1208
851
#endif
1209
851
      || startswith (name, ".stab"))
1210
51
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
851
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
851
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
660
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
4.81k
  while (styp_flags)
1220
3.96k
    {
1221
3.96k
      unsigned long flag = styp_flags & - styp_flags;
1222
3.96k
      char * unhandled = NULL;
1223
1224
3.96k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
3.96k
      switch (flag)
1231
3.96k
  {
1232
19
  case STYP_DSECT:
1233
19
    unhandled = "STYP_DSECT";
1234
19
    break;
1235
19
  case STYP_GROUP:
1236
19
    unhandled = "STYP_GROUP";
1237
19
    break;
1238
20
  case STYP_COPY:
1239
20
    unhandled = "STYP_COPY";
1240
20
    break;
1241
18
  case STYP_OVER:
1242
18
    unhandled = "STYP_OVER";
1243
18
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
142
  case STYP_NOLOAD:
1246
142
    sec_flags |= SEC_NEVER_LOAD;
1247
142
    break;
1248
0
#endif
1249
191
  case IMAGE_SCN_MEM_READ:
1250
191
    sec_flags &= ~SEC_COFF_NOREAD;
1251
191
    break;
1252
159
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
159
    break;
1255
21
  case IMAGE_SCN_LNK_OTHER:
1256
21
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
21
    break;
1258
21
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
21
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
21
    break;
1261
136
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
136
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
136
        " %s in section %s"),
1268
136
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
136
    break;
1270
200
  case IMAGE_SCN_MEM_EXECUTE:
1271
200
    sec_flags |= SEC_CODE;
1272
200
    break;
1273
177
  case IMAGE_SCN_MEM_WRITE:
1274
177
    sec_flags &= ~ SEC_READONLY;
1275
177
    break;
1276
170
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
170
       if (is_dbg
1283
170
#ifdef _COMMENT
1284
170
        || strcmp (name, _COMMENT) == 0
1285
170
#endif
1286
170
        )
1287
31
      {
1288
31
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
31
      }
1290
170
    break;
1291
55
  case IMAGE_SCN_MEM_SHARED:
1292
55
    sec_flags |= SEC_COFF_SHARED;
1293
55
    break;
1294
163
  case IMAGE_SCN_LNK_REMOVE:
1295
163
    if (!is_dbg)
1296
145
      sec_flags |= SEC_EXCLUDE;
1297
163
    break;
1298
166
  case IMAGE_SCN_CNT_CODE:
1299
166
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
166
    break;
1301
209
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
209
    if (is_dbg)
1303
22
      sec_flags |= SEC_DEBUGGING;
1304
187
    else
1305
187
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
209
    break;
1307
155
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
155
    sec_flags |= SEC_ALLOC;
1309
155
    break;
1310
161
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
161
#ifdef COFF_PAGE_SIZE
1318
161
    sec_flags |= SEC_DEBUGGING;
1319
161
#endif
1320
161
    break;
1321
62
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
62
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2
      result = false;
1325
62
    break;
1326
1.70k
  default:
1327
    /* Silently ignore for now.  */
1328
1.70k
    break;
1329
3.96k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
3.96k
      if (unhandled != NULL)
1333
118
  {
1334
118
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
118
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
118
       abfd, name, unhandled, flag);
1338
118
    result = false;
1339
118
  }
1340
3.96k
    }
1341
1342
851
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
851
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
851
  if (flags_ptr)
1359
851
    * flags_ptr = sec_flags;
1360
1361
851
  return result;
1362
851
}
pei-sh.c:styp_to_sec_flags
Line
Count
Source
1191
790
{
1192
790
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
790
  unsigned long styp_flags = internal_s->s_flags;
1194
790
  flagword sec_flags;
1195
790
  bool result = true;
1196
790
  bool is_dbg = false;
1197
1198
790
  if (startswith (name, DOT_DEBUG)
1199
790
      || startswith (name, DOT_ZDEBUG)
1200
790
#ifdef COFF_LONG_SECTION_NAMES
1201
790
      || startswith (name, GNU_LINKONCE_WI)
1202
790
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
790
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
790
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
790
      || startswith (name, GNU_DEBUGLINK)
1207
790
      || startswith (name, GNU_DEBUGALTLINK)
1208
790
#endif
1209
790
      || startswith (name, ".stab"))
1210
173
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
790
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
790
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
538
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
7.52k
  while (styp_flags)
1220
6.73k
    {
1221
6.73k
      unsigned long flag = styp_flags & - styp_flags;
1222
6.73k
      char * unhandled = NULL;
1223
1224
6.73k
      styp_flags &= ~ flag;
1225
1226
      /* We infer from the distinct read/write/execute bits the settings
1227
   of some of the bfd flags; the actual values, should we need them,
1228
   are also in pei_section_data (abfd, section)->pe_flags.  */
1229
1230
6.73k
      switch (flag)
1231
6.73k
  {
1232
19
  case STYP_DSECT:
1233
19
    unhandled = "STYP_DSECT";
1234
19
    break;
1235
23
  case STYP_GROUP:
1236
23
    unhandled = "STYP_GROUP";
1237
23
    break;
1238
23
  case STYP_COPY:
1239
23
    unhandled = "STYP_COPY";
1240
23
    break;
1241
12
  case STYP_OVER:
1242
12
    unhandled = "STYP_OVER";
1243
12
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
188
  case STYP_NOLOAD:
1246
188
    sec_flags |= SEC_NEVER_LOAD;
1247
188
    break;
1248
0
#endif
1249
252
  case IMAGE_SCN_MEM_READ:
1250
252
    sec_flags &= ~SEC_COFF_NOREAD;
1251
252
    break;
1252
197
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
197
    break;
1255
17
  case IMAGE_SCN_LNK_OTHER:
1256
17
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
17
    break;
1258
18
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
18
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
18
    break;
1261
104
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
104
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
104
        " %s in section %s"),
1268
104
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
104
    break;
1270
434
  case IMAGE_SCN_MEM_EXECUTE:
1271
434
    sec_flags |= SEC_CODE;
1272
434
    break;
1273
413
  case IMAGE_SCN_MEM_WRITE:
1274
413
    sec_flags &= ~ SEC_READONLY;
1275
413
    break;
1276
273
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
273
       if (is_dbg
1283
273
#ifdef _COMMENT
1284
273
        || strcmp (name, _COMMENT) == 0
1285
273
#endif
1286
273
        )
1287
127
      {
1288
127
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
127
      }
1290
273
    break;
1291
42
  case IMAGE_SCN_MEM_SHARED:
1292
42
    sec_flags |= SEC_COFF_SHARED;
1293
42
    break;
1294
225
  case IMAGE_SCN_LNK_REMOVE:
1295
225
    if (!is_dbg)
1296
143
      sec_flags |= SEC_EXCLUDE;
1297
225
    break;
1298
355
  case IMAGE_SCN_CNT_CODE:
1299
355
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
355
    break;
1301
357
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
357
    if (is_dbg)
1303
85
      sec_flags |= SEC_DEBUGGING;
1304
272
    else
1305
272
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
357
    break;
1307
341
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
341
    sec_flags |= SEC_ALLOC;
1309
341
    break;
1310
245
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
245
#ifdef COFF_PAGE_SIZE
1318
245
    sec_flags |= SEC_DEBUGGING;
1319
245
#endif
1320
245
    break;
1321
78
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
78
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3
      result = false;
1325
78
    break;
1326
3.11k
  default:
1327
    /* Silently ignore for now.  */
1328
3.11k
    break;
1329
6.73k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
6.73k
      if (unhandled != NULL)
1333
112
  {
1334
112
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
112
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
112
       abfd, name, unhandled, flag);
1338
112
    result = false;
1339
112
  }
1340
6.73k
    }
1341
1342
790
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
790
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
1348
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
1349
     only link a single copy of the section.  This is used to support
1350
     g++.  g++ will emit each template expansion in its own section.
1351
     The symbols will be defined as weak, so that multiple definitions
1352
     are permitted.  The GNU linker extension is to actually discard
1353
     all but one of the sections.  */
1354
  if (startswith (name, ".gnu.linkonce"))
1355
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
790
  if (flags_ptr)
1359
790
    * flags_ptr = sec_flags;
1360
1361
790
  return result;
1362
790
}
1363
1364
#endif /* COFF_WITH_PE */
1365
1366
0
#define get_index(symbol) ((symbol)->udata.i)
1367
1368
/*
1369
INTERNAL_DEFINITION
1370
  bfd_coff_backend_data
1371
1372
INTERNAL
1373
.{* COFF symbol classifications.  *}
1374
.
1375
.enum coff_symbol_classification
1376
.{
1377
.  {* Global symbol.  *}
1378
.  COFF_SYMBOL_GLOBAL,
1379
.  {* Common symbol.  *}
1380
.  COFF_SYMBOL_COMMON,
1381
.  {* Undefined symbol.  *}
1382
.  COFF_SYMBOL_UNDEFINED,
1383
.  {* Local symbol.  *}
1384
.  COFF_SYMBOL_LOCAL,
1385
.  {* PE section symbol.  *}
1386
.  COFF_SYMBOL_PE_SECTION
1387
.};
1388
.
1389
.typedef asection * (*coff_gc_mark_hook_fn)
1390
.  (asection *, struct bfd_link_info *, struct internal_reloc *,
1391
.   struct coff_link_hash_entry *, struct internal_syment *);
1392
.
1393
1394
Special entry points for gdb to swap in coff symbol table parts:
1395
1396
CODE_FRAGMENT
1397
.typedef struct
1398
.{
1399
.  void (*_bfd_coff_swap_aux_in)
1400
.    (bfd *, void *, int, int, int, int, void *);
1401
.
1402
.  void (*_bfd_coff_swap_sym_in)
1403
.    (bfd *, void *, void *);
1404
.
1405
.  void (*_bfd_coff_swap_lineno_in)
1406
.    (bfd *, void *, void *);
1407
.
1408
.  unsigned int (*_bfd_coff_swap_aux_out)
1409
.    (bfd *, void *, int, int, int, int, void *);
1410
.
1411
.  unsigned int (*_bfd_coff_swap_sym_out)
1412
.    (bfd *, void *, void *);
1413
.
1414
.  unsigned int (*_bfd_coff_swap_lineno_out)
1415
.    (bfd *, void *, void *);
1416
.
1417
.  unsigned int (*_bfd_coff_swap_reloc_out)
1418
.    (bfd *, void *, void *);
1419
.
1420
.  unsigned int (*_bfd_coff_swap_filehdr_out)
1421
.    (bfd *, void *, void *);
1422
.
1423
.  unsigned int (*_bfd_coff_swap_aouthdr_out)
1424
.    (bfd *, void *, void *);
1425
.
1426
.  unsigned int (*_bfd_coff_swap_scnhdr_out)
1427
.    (bfd *, void *, void *);
1428
.
1429
.  unsigned int _bfd_filhsz;
1430
.  unsigned int _bfd_aoutsz;
1431
.  unsigned int _bfd_scnhsz;
1432
.  unsigned int _bfd_symesz;
1433
.  unsigned int _bfd_auxesz;
1434
.  unsigned int _bfd_relsz;
1435
.  unsigned int _bfd_linesz;
1436
.  unsigned int _bfd_filnmlen;
1437
.  bool _bfd_coff_long_filenames;
1438
.
1439
.  bool _bfd_coff_long_section_names;
1440
.  bool (*_bfd_coff_set_long_section_names)
1441
.    (bfd *, int);
1442
.
1443
.  unsigned int _bfd_coff_default_section_alignment_power;
1444
.  bool _bfd_coff_force_symnames_in_strings;
1445
.  unsigned int _bfd_coff_debug_string_prefix_length;
1446
.  unsigned int _bfd_coff_max_nscns;
1447
.
1448
.  void (*_bfd_coff_swap_filehdr_in)
1449
.    (bfd *, void *, void *);
1450
.
1451
.  void (*_bfd_coff_swap_aouthdr_in)
1452
.    (bfd *, void *, void *);
1453
.
1454
.  void (*_bfd_coff_swap_scnhdr_in)
1455
.    (bfd *, void *, void *);
1456
.
1457
.  void (*_bfd_coff_swap_reloc_in)
1458
.    (bfd *abfd, void *, void *);
1459
.
1460
.  bool (*_bfd_coff_bad_format_hook)
1461
.    (bfd *, void *);
1462
.
1463
.  bool (*_bfd_coff_set_arch_mach_hook)
1464
.    (bfd *, void *);
1465
.
1466
.  void * (*_bfd_coff_mkobject_hook)
1467
.    (bfd *, void *, void *);
1468
.
1469
.  bool (*_bfd_styp_to_sec_flags_hook)
1470
.    (bfd *, void *, const char *, asection *, flagword *);
1471
.
1472
.  void (*_bfd_set_alignment_hook)
1473
.    (bfd *, asection *, void *);
1474
.
1475
.  bool (*_bfd_coff_slurp_symbol_table)
1476
.    (bfd *);
1477
.
1478
.  bool (*_bfd_coff_symname_in_debug)
1479
.    (bfd *, struct internal_syment *);
1480
.
1481
.  bool (*_bfd_coff_pointerize_aux_hook)
1482
.    (bfd *, combined_entry_type *, combined_entry_type *,
1483
.     unsigned int, combined_entry_type *);
1484
.
1485
.  bool (*_bfd_coff_print_aux)
1486
.    (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
1487
.     combined_entry_type *, unsigned int);
1488
.
1489
.  bool (*_bfd_coff_reloc16_extra_cases)
1490
.    (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
1491
.     bfd_byte *, size_t *, size_t *);
1492
.
1493
.  int (*_bfd_coff_reloc16_estimate)
1494
.    (bfd *, asection *, arelent *, unsigned int,
1495
.     struct bfd_link_info *);
1496
.
1497
.  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
1498
.    (bfd *, struct internal_syment *);
1499
.
1500
.  bool (*_bfd_coff_compute_section_file_positions)
1501
.    (bfd *);
1502
.
1503
.  bool (*_bfd_coff_start_final_link)
1504
.    (bfd *, struct bfd_link_info *);
1505
.
1506
.  bool (*_bfd_coff_relocate_section)
1507
.    (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
1508
.     struct internal_reloc *, struct internal_syment *, asection **);
1509
.
1510
.  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
1511
.    (bfd *, asection *, struct internal_reloc *,
1512
.     struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
1513
.
1514
.  bool (*_bfd_coff_adjust_symndx)
1515
.    (bfd *, struct bfd_link_info *, bfd *, asection *,
1516
.     struct internal_reloc *, bool *);
1517
.
1518
.  bool (*_bfd_coff_link_add_one_symbol)
1519
.    (struct bfd_link_info *, bfd *, const char *, flagword,
1520
.     asection *, bfd_vma, const char *, bool, bool,
1521
.     struct bfd_link_hash_entry **);
1522
.
1523
.  bool (*_bfd_coff_link_output_has_begun)
1524
.    (bfd *, struct coff_final_link_info *);
1525
.
1526
.  bool (*_bfd_coff_final_link_postscript)
1527
.    (bfd *, struct coff_final_link_info *);
1528
.
1529
.  bool (*_bfd_coff_print_pdata)
1530
.    (bfd *, void *);
1531
.
1532
.} bfd_coff_backend_data;
1533
.
1534
1535
INTERNAL
1536
.#define coff_backend_info(abfd) \
1537
.  ((const bfd_coff_backend_data *) (abfd)->xvec->backend_data)
1538
.
1539
.#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
1540
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
1541
.
1542
.#define bfd_coff_swap_sym_in(a,e,i) \
1543
.  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
1544
.
1545
.#define bfd_coff_swap_lineno_in(a,e,i) \
1546
.  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
1547
.
1548
.#define bfd_coff_swap_reloc_out(abfd, i, o) \
1549
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
1550
.
1551
.#define bfd_coff_swap_lineno_out(abfd, i, o) \
1552
.  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
1553
.
1554
.#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
1555
.  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
1556
.
1557
.#define bfd_coff_swap_sym_out(abfd, i,o) \
1558
.  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
1559
.
1560
.#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
1561
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
1562
.
1563
.#define bfd_coff_swap_filehdr_out(abfd, i,o) \
1564
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
1565
.
1566
.#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
1567
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
1568
.
1569
.#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
1570
.#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
1571
.#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
1572
.#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
1573
.#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
1574
.#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
1575
.#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
1576
.#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
1577
.#define bfd_coff_long_filenames(abfd) \
1578
.  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
1579
.#define bfd_coff_long_section_names(abfd) \
1580
.  (coff_data (abfd)->long_section_names)
1581
.#define bfd_coff_set_long_section_names(abfd, enable) \
1582
.  ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
1583
.#define bfd_coff_default_section_alignment_power(abfd) \
1584
.  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
1585
.#define bfd_coff_max_nscns(abfd) \
1586
.  (coff_backend_info (abfd)->_bfd_coff_max_nscns)
1587
.
1588
.#define bfd_coff_swap_filehdr_in(abfd, i,o) \
1589
.  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
1590
.
1591
.#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
1592
.  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
1593
.
1594
.#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
1595
.  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
1596
.
1597
.#define bfd_coff_swap_reloc_in(abfd, i, o) \
1598
.  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
1599
.
1600
.#define bfd_coff_bad_format_hook(abfd, filehdr) \
1601
.  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
1602
.
1603
.#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
1604
.  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
1605
.#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
1606
.  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
1607
.   (abfd, filehdr, aouthdr))
1608
.
1609
.#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
1610
.  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
1611
.   (abfd, scnhdr, name, section, flags_ptr))
1612
.
1613
.#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
1614
.  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
1615
.
1616
.#define bfd_coff_slurp_symbol_table(abfd)\
1617
.  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
1618
.
1619
.#define bfd_coff_symname_in_debug(abfd, sym)\
1620
.  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
1621
.
1622
.#define bfd_coff_force_symnames_in_strings(abfd)\
1623
.  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
1624
.
1625
.#define bfd_coff_debug_string_prefix_length(abfd)\
1626
.  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
1627
.
1628
.#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
1629
.  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
1630
.   (abfd, file, base, symbol, aux, indaux))
1631
.
1632
.#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
1633
.             reloc, data, src_ptr, dst_ptr)\
1634
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
1635
.   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
1636
.
1637
.#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
1638
.  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
1639
.   (abfd, section, reloc, shrink, link_info))
1640
.
1641
.#define bfd_coff_classify_symbol(abfd, sym)\
1642
.  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
1643
.   (abfd, sym))
1644
.
1645
.#define bfd_coff_compute_section_file_positions(abfd)\
1646
.  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
1647
.   (abfd))
1648
.
1649
.#define bfd_coff_start_final_link(obfd, info)\
1650
.  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
1651
.   (obfd, info))
1652
.#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
1653
.  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
1654
.   (obfd, info, ibfd, o, con, rel, isyms, secs))
1655
.#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
1656
.  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
1657
.   (abfd, sec, rel, h, sym, addendp))
1658
.#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
1659
.  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
1660
.   (obfd, info, ibfd, sec, rel, adjustedp))
1661
.#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
1662
.             value, string, cp, coll, hashp)\
1663
.  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
1664
.   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
1665
.
1666
.#define bfd_coff_link_output_has_begun(a,p) \
1667
.  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
1668
.#define bfd_coff_final_link_postscript(a,p) \
1669
.  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
1670
.
1671
.#define bfd_coff_have_print_pdata(a) \
1672
.  (coff_backend_info (a)->_bfd_coff_print_pdata)
1673
.#define bfd_coff_print_pdata(a,p) \
1674
.  ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
1675
.
1676
.{* Macro: Returns true if the bfd is a PE executable as opposed to a
1677
.   PE object file.  *}
1678
.#define bfd_pei_p(abfd) \
1679
.  (startswith ((abfd)->xvec->name, "pei-"))
1680
*/
1681
1682
/* See whether the magic number matches.  */
1683
1684
static bool
1685
coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
1686
832k
{
1687
832k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
832k
  if (BADMAG (*internal_f))
1690
816k
    return false;
1691
1692
16.2k
  return true;
1693
832k
}
pei-i386.c:coff_bad_format_hook
Line
Count
Source
1686
4.35k
{
1687
4.35k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.35k
  if (BADMAG (*internal_f))
1690
4.11k
    return false;
1691
1692
244
  return true;
1693
4.35k
}
pe-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
79.0k
{
1687
79.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
79.0k
  if (BADMAG (*internal_f))
1690
78.2k
    return false;
1691
1692
746
  return true;
1693
79.0k
}
pei-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
4.39k
{
1687
4.39k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.39k
  if (BADMAG (*internal_f))
1690
4.12k
    return false;
1691
1692
266
  return true;
1693
4.39k
}
coff-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
40.2k
{
1687
40.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
40.2k
  if (BADMAG (*internal_f))
1690
39.5k
    return false;
1691
1692
661
  return true;
1693
40.2k
}
Unexecuted instantiation: coff64-rs6000.c:coff_bad_format_hook
pe-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
40.2k
{
1687
40.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
40.2k
  if (BADMAG (*internal_f))
1690
38.4k
    return false;
1691
1692
1.83k
  return true;
1693
40.2k
}
pei-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
4.35k
{
1687
4.35k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.35k
  if (BADMAG (*internal_f))
1690
1.35k
    return false;
1691
1692
2.99k
  return true;
1693
4.35k
}
pei-ia64.c:coff_bad_format_hook
Line
Count
Source
1686
698
{
1687
698
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
698
  if (BADMAG (*internal_f))
1690
365
    return false;
1691
1692
333
  return true;
1693
698
}
pei-loongarch64.c:coff_bad_format_hook
Line
Count
Source
1686
4.33k
{
1687
4.33k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.33k
  if (BADMAG (*internal_f))
1690
4.10k
    return false;
1691
1692
231
  return true;
1693
4.33k
}
cf-i386lynx.c:coff_bad_format_hook
Line
Count
Source
1686
40.2k
{
1687
40.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
40.2k
  if (BADMAG (*internal_f))
1690
38.4k
    return false;
1691
1692
1.77k
  return true;
1693
40.2k
}
coff-go32.c:coff_bad_format_hook
Line
Count
Source
1686
40.2k
{
1687
40.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
40.2k
  if (BADMAG (*internal_f))
1690
38.5k
    return false;
1691
1692
1.66k
  return true;
1693
40.2k
}
coff-i386.c:coff_bad_format_hook
Line
Count
Source
1686
40.2k
{
1687
40.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
40.2k
  if (BADMAG (*internal_f))
1690
38.5k
    return false;
1691
1692
1.66k
  return true;
1693
40.2k
}
coff-rs6000.c:coff_bad_format_hook
Line
Count
Source
1686
28.5k
{
1687
28.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
28.5k
  if (BADMAG (*internal_f))
1690
28.3k
    return false;
1691
1692
298
  return true;
1693
28.5k
}
coff-sh.c:coff_bad_format_hook
Line
Count
Source
1686
67.7k
{
1687
67.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
67.7k
  if (BADMAG (*internal_f))
1690
67.4k
    return false;
1691
1692
212
  return true;
1693
67.7k
}
coff-stgo32.c:coff_bad_format_hook
Line
Count
Source
1686
125
{
1687
125
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
125
  if (BADMAG (*internal_f))
1690
5
    return false;
1691
1692
120
  return true;
1693
125
}
coff-tic30.c:coff_bad_format_hook
Line
Count
Source
1686
28.5k
{
1687
28.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
28.5k
  if (BADMAG (*internal_f))
1690
28.3k
    return false;
1691
1692
253
  return true;
1693
28.5k
}
Unexecuted instantiation: coff-tic4x.c:coff_bad_format_hook
coff-tic54x.c:coff_bad_format_hook
Line
Count
Source
1686
57.0k
{
1687
57.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
57.0k
  if (BADMAG (*internal_f))
1690
57.0k
    return false;
1691
1692
0
  return true;
1693
57.0k
}
coff-z80.c:coff_bad_format_hook
Line
Count
Source
1686
28.5k
{
1687
28.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
28.5k
  if (BADMAG (*internal_f))
1690
28.4k
    return false;
1691
1692
142
  return true;
1693
28.5k
}
coff-z8k.c:coff_bad_format_hook
Line
Count
Source
1686
28.5k
{
1687
28.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
28.5k
  if (BADMAG (*internal_f))
1690
28.3k
    return false;
1691
1692
218
  return true;
1693
28.5k
}
pe-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
57.1k
{
1687
57.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
57.1k
  if (BADMAG (*internal_f))
1690
57.1k
    return false;
1691
1692
48
  return true;
1693
57.1k
}
pe-arm.c:coff_bad_format_hook
Line
Count
Source
1686
57.1k
{
1687
57.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
57.1k
  if (BADMAG (*internal_f))
1690
57.1k
    return false;
1691
1692
48
  return true;
1693
57.1k
}
pe-i386.c:coff_bad_format_hook
Line
Count
Source
1686
78.9k
{
1687
78.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
78.9k
  if (BADMAG (*internal_f))
1690
77.1k
    return false;
1691
1692
1.80k
  return true;
1693
78.9k
}
pe-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
57.1k
{
1687
57.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
57.1k
  if (BADMAG (*internal_f))
1690
57.0k
    return false;
1691
1692
147
  return true;
1693
57.1k
}
pe-sh.c:coff_bad_format_hook
Line
Count
Source
1686
28.5k
{
1687
28.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
28.5k
  if (BADMAG (*internal_f))
1690
28.4k
    return false;
1691
1692
134
  return true;
1693
28.5k
}
pei-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
4.06k
{
1687
4.06k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.06k
  if (BADMAG (*internal_f))
1690
3.95k
    return false;
1691
1692
114
  return true;
1693
4.06k
}
pei-arm.c:coff_bad_format_hook
Line
Count
Source
1686
4.06k
{
1687
4.06k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.06k
  if (BADMAG (*internal_f))
1690
3.95k
    return false;
1691
1692
114
  return true;
1693
4.06k
}
pei-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
4.05k
{
1687
4.05k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.05k
  if (BADMAG (*internal_f))
1690
3.95k
    return false;
1691
1692
101
  return true;
1693
4.05k
}
pei-sh.c:coff_bad_format_hook
Line
Count
Source
1686
4.05k
{
1687
4.05k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
4.05k
  if (BADMAG (*internal_f))
1690
3.98k
    return false;
1691
1692
71
  return true;
1693
4.05k
}
1694
1695
#ifdef TICOFF
1696
static bool
1697
ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1698
57.1k
{
1699
57.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
57.1k
  if (COFF0_BADMAG (*internal_f))
1702
56.8k
    return false;
1703
1704
300
  return true;
1705
57.1k
}
Unexecuted instantiation: coff-tic4x.c:ticoff0_bad_format_hook
coff-tic54x.c:ticoff0_bad_format_hook
Line
Count
Source
1698
57.1k
{
1699
57.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
57.1k
  if (COFF0_BADMAG (*internal_f))
1702
56.8k
    return false;
1703
1704
300
  return true;
1705
57.1k
}
1706
#endif
1707
1708
#ifdef TICOFF
1709
static bool
1710
ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1711
57.0k
{
1712
57.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
57.0k
  if (COFF1_BADMAG (*internal_f))
1715
57.0k
    return false;
1716
1717
0
  return true;
1718
57.0k
}
Unexecuted instantiation: coff-tic4x.c:ticoff1_bad_format_hook
coff-tic54x.c:ticoff1_bad_format_hook
Line
Count
Source
1711
57.0k
{
1712
57.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
57.0k
  if (COFF1_BADMAG (*internal_f))
1715
57.0k
    return false;
1716
1717
0
  return true;
1718
57.0k
}
1719
#endif
1720
1721
/* Check whether this section uses an alignment other than the
1722
   default.  */
1723
1724
static void
1725
coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
1726
           asection *section,
1727
           const struct coff_section_alignment_entry *alignment_table,
1728
           const unsigned int table_size)
1729
206k
{
1730
206k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
206k
  unsigned int i;
1732
1733
1.29M
  for (i = 0; i < table_size; ++i)
1734
1.09M
    {
1735
1.09M
      const char *secname = bfd_section_name (section);
1736
1737
1.09M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.09M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.09M
    : strncmp (alignment_table[i].name, secname,
1740
572k
         alignment_table[i].comparison_length) == 0)
1741
1.13k
  break;
1742
1.09M
    }
1743
206k
  if (i >= table_size)
1744
205k
    return;
1745
1746
1.13k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1.13k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
363
    return;
1749
1750
770
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
770
      )
1755
0
    return;
1756
1757
770
  section->alignment_power = alignment_table[i].alignment_power;
1758
770
}
pei-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.15k
{
1730
1.15k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.15k
  unsigned int i;
1732
1733
9.84k
  for (i = 0; i < table_size; ++i)
1734
8.78k
    {
1735
8.78k
      const char *secname = bfd_section_name (section);
1736
1737
8.78k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
8.78k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
8.78k
    : strncmp (alignment_table[i].name, secname,
1740
5.50k
         alignment_table[i].comparison_length) == 0)
1741
94
  break;
1742
8.78k
    }
1743
1.15k
  if (i >= table_size)
1744
1.06k
    return;
1745
1746
94
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
94
      && default_alignment < alignment_table[i].default_alignment_min)
1748
20
    return;
1749
1750
74
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
74
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
74
      && default_alignment > alignment_table[i].default_alignment_max
1753
74
#endif
1754
74
      )
1755
0
    return;
1756
1757
74
  section->alignment_power = alignment_table[i].alignment_power;
1758
74
}
pe-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.91k
{
1730
1.91k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.91k
  unsigned int i;
1732
1733
26.5k
  for (i = 0; i < table_size; ++i)
1734
24.7k
    {
1735
24.7k
      const char *secname = bfd_section_name (section);
1736
1737
24.7k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
24.7k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
24.7k
    : strncmp (alignment_table[i].name, secname,
1740
17.1k
         alignment_table[i].comparison_length) == 0)
1741
45
  break;
1742
24.7k
    }
1743
1.91k
  if (i >= table_size)
1744
1.87k
    return;
1745
1746
45
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
45
      && default_alignment < alignment_table[i].default_alignment_min)
1748
9
    return;
1749
1750
36
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
36
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
36
      && default_alignment > alignment_table[i].default_alignment_max
1753
36
#endif
1754
36
      )
1755
0
    return;
1756
1757
36
  section->alignment_power = alignment_table[i].alignment_power;
1758
36
}
pei-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
929
{
1730
929
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
929
  unsigned int i;
1732
1733
11.3k
  for (i = 0; i < table_size; ++i)
1734
10.5k
    {
1735
10.5k
      const char *secname = bfd_section_name (section);
1736
1737
10.5k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
10.5k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
10.5k
    : strncmp (alignment_table[i].name, secname,
1740
7.04k
         alignment_table[i].comparison_length) == 0)
1741
92
  break;
1742
10.5k
    }
1743
929
  if (i >= table_size)
1744
837
    return;
1745
1746
92
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
92
      && default_alignment < alignment_table[i].default_alignment_min)
1748
9
    return;
1749
1750
83
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
83
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
83
      && default_alignment > alignment_table[i].default_alignment_max
1753
83
#endif
1754
83
      )
1755
0
    return;
1756
1757
83
  section->alignment_power = alignment_table[i].alignment_power;
1758
83
}
coff-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
6.18k
{
1730
6.18k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
6.18k
  unsigned int i;
1732
1733
30.8k
  for (i = 0; i < table_size; ++i)
1734
24.6k
    {
1735
24.6k
      const char *secname = bfd_section_name (section);
1736
1737
24.6k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
24.6k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
24.6k
    : strncmp (alignment_table[i].name, secname,
1740
12.3k
         alignment_table[i].comparison_length) == 0)
1741
11
  break;
1742
24.6k
    }
1743
6.18k
  if (i >= table_size)
1744
6.16k
    return;
1745
1746
11
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
11
      && default_alignment < alignment_table[i].default_alignment_min)
1748
10
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
coff64-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.70k
{
1730
2.70k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.70k
  unsigned int i;
1732
1733
13.5k
  for (i = 0; i < table_size; ++i)
1734
10.8k
    {
1735
10.8k
      const char *secname = bfd_section_name (section);
1736
1737
10.8k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
10.8k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
10.8k
    : strncmp (alignment_table[i].name, secname,
1740
5.40k
         alignment_table[i].comparison_length) == 0)
1741
1
  break;
1742
10.8k
    }
1743
2.70k
  if (i >= table_size)
1744
2.70k
    return;
1745
1746
1
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
pe-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.30k
{
1730
2.30k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.30k
  unsigned int i;
1732
1733
29.4k
  for (i = 0; i < table_size; ++i)
1734
27.2k
    {
1735
27.2k
      const char *secname = bfd_section_name (section);
1736
1737
27.2k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
27.2k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
27.2k
    : strncmp (alignment_table[i].name, secname,
1740
11.4k
         alignment_table[i].comparison_length) == 0)
1741
117
  break;
1742
27.2k
    }
1743
2.30k
  if (i >= table_size)
1744
2.18k
    return;
1745
1746
117
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
117
      && default_alignment < alignment_table[i].default_alignment_min)
1748
89
    return;
1749
1750
28
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
28
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
28
      && default_alignment > alignment_table[i].default_alignment_max
1753
28
#endif
1754
28
      )
1755
0
    return;
1756
1757
28
  section->alignment_power = alignment_table[i].alignment_power;
1758
28
}
pei-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
15.1k
{
1730
15.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
15.1k
  unsigned int i;
1732
1733
195k
  for (i = 0; i < table_size; ++i)
1734
180k
    {
1735
180k
      const char *secname = bfd_section_name (section);
1736
1737
180k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
180k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
180k
    : strncmp (alignment_table[i].name, secname,
1740
75.3k
         alignment_table[i].comparison_length) == 0)
1741
159
  break;
1742
180k
    }
1743
15.1k
  if (i >= table_size)
1744
14.9k
    return;
1745
1746
159
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
159
      && default_alignment < alignment_table[i].default_alignment_min)
1748
27
    return;
1749
1750
132
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
132
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
132
      && default_alignment > alignment_table[i].default_alignment_max
1753
132
#endif
1754
132
      )
1755
0
    return;
1756
1757
132
  section->alignment_power = alignment_table[i].alignment_power;
1758
132
}
pei-ia64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.44k
{
1730
2.44k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.44k
  unsigned int i;
1732
1733
12.1k
  for (i = 0; i < table_size; ++i)
1734
9.74k
    {
1735
9.74k
      const char *secname = bfd_section_name (section);
1736
1737
9.74k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
9.74k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
9.74k
    : strncmp (alignment_table[i].name, secname,
1740
4.88k
         alignment_table[i].comparison_length) == 0)
1741
23
  break;
1742
9.74k
    }
1743
2.44k
  if (i >= table_size)
1744
2.42k
    return;
1745
1746
23
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
23
      && default_alignment < alignment_table[i].default_alignment_min)
1748
13
    return;
1749
1750
10
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
10
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
10
      && default_alignment > alignment_table[i].default_alignment_max
1753
10
#endif
1754
10
      )
1755
0
    return;
1756
1757
10
  section->alignment_power = alignment_table[i].alignment_power;
1758
10
}
pei-loongarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
699
{
1730
699
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
699
  unsigned int i;
1732
1733
8.85k
  for (i = 0; i < table_size; ++i)
1734
8.18k
    {
1735
8.18k
      const char *secname = bfd_section_name (section);
1736
1737
8.18k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
8.18k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
8.18k
    : strncmp (alignment_table[i].name, secname,
1740
3.38k
         alignment_table[i].comparison_length) == 0)
1741
30
  break;
1742
8.18k
    }
1743
699
  if (i >= table_size)
1744
669
    return;
1745
1746
30
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
30
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
30
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
30
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
30
      && default_alignment > alignment_table[i].default_alignment_max
1753
30
#endif
1754
30
      )
1755
0
    return;
1756
1757
30
  section->alignment_power = alignment_table[i].alignment_power;
1758
30
}
cf-i386lynx.c:coff_set_custom_section_alignment
Line
Count
Source
1729
9.20k
{
1730
9.20k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
9.20k
  unsigned int i;
1732
1733
45.9k
  for (i = 0; i < table_size; ++i)
1734
36.7k
    {
1735
36.7k
      const char *secname = bfd_section_name (section);
1736
1737
36.7k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
36.7k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
36.7k
    : strncmp (alignment_table[i].name, secname,
1740
18.3k
         alignment_table[i].comparison_length) == 0)
1741
37
  break;
1742
36.7k
    }
1743
9.20k
  if (i >= table_size)
1744
9.16k
    return;
1745
1746
37
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
37
      && default_alignment < alignment_table[i].default_alignment_min)
1748
22
    return;
1749
1750
15
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
15
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
15
      && default_alignment > alignment_table[i].default_alignment_max
1753
15
#endif
1754
15
      )
1755
0
    return;
1756
1757
15
  section->alignment_power = alignment_table[i].alignment_power;
1758
15
}
coff-go32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
6.15k
{
1730
6.15k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
6.15k
  unsigned int i;
1732
1733
98.2k
  for (i = 0; i < table_size; ++i)
1734
92.1k
    {
1735
92.1k
      const char *secname = bfd_section_name (section);
1736
1737
92.1k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
92.1k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
92.1k
    : strncmp (alignment_table[i].name, secname,
1740
79.8k
         alignment_table[i].comparison_length) == 0)
1741
31
  break;
1742
92.1k
    }
1743
6.15k
  if (i >= table_size)
1744
6.12k
    return;
1745
1746
31
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
31
      && default_alignment < alignment_table[i].default_alignment_min)
1748
11
    return;
1749
1750
20
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
20
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
20
      && default_alignment > alignment_table[i].default_alignment_max
1753
20
#endif
1754
20
      )
1755
0
    return;
1756
1757
20
  section->alignment_power = alignment_table[i].alignment_power;
1758
20
}
coff-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
7.30k
{
1730
7.30k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
7.30k
  unsigned int i;
1732
1733
36.4k
  for (i = 0; i < table_size; ++i)
1734
29.1k
    {
1735
29.1k
      const char *secname = bfd_section_name (section);
1736
1737
29.1k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
29.1k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
29.1k
    : strncmp (alignment_table[i].name, secname,
1740
14.5k
         alignment_table[i].comparison_length) == 0)
1741
22
  break;
1742
29.1k
    }
1743
7.30k
  if (i >= table_size)
1744
7.28k
    return;
1745
1746
22
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
22
      && default_alignment < alignment_table[i].default_alignment_min)
1748
11
    return;
1749
1750
11
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
11
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
11
      && default_alignment > alignment_table[i].default_alignment_max
1753
11
#endif
1754
11
      )
1755
0
    return;
1756
1757
11
  section->alignment_power = alignment_table[i].alignment_power;
1758
11
}
coff-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.14k
{
1730
2.14k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.14k
  unsigned int i;
1732
1733
10.7k
  for (i = 0; i < table_size; ++i)
1734
8.57k
    {
1735
8.57k
      const char *secname = bfd_section_name (section);
1736
1737
8.57k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
8.57k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
8.57k
    : strncmp (alignment_table[i].name, secname,
1740
4.29k
         alignment_table[i].comparison_length) == 0)
1741
3
  break;
1742
8.57k
    }
1743
2.14k
  if (i >= table_size)
1744
2.14k
    return;
1745
1746
3
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
3
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
3
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
3
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
3
      && default_alignment > alignment_table[i].default_alignment_max
1753
3
#endif
1754
3
      )
1755
0
    return;
1756
1757
3
  section->alignment_power = alignment_table[i].alignment_power;
1758
3
}
coff-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
10.6k
{
1730
10.6k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
10.6k
  unsigned int i;
1732
1733
53.4k
  for (i = 0; i < table_size; ++i)
1734
42.7k
    {
1735
42.7k
      const char *secname = bfd_section_name (section);
1736
1737
42.7k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
42.7k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
42.7k
    : strncmp (alignment_table[i].name, secname,
1740
21.3k
         alignment_table[i].comparison_length) == 0)
1741
4
  break;
1742
42.7k
    }
1743
10.6k
  if (i >= table_size)
1744
10.6k
    return;
1745
1746
4
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
4
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
4
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
4
      && default_alignment > alignment_table[i].default_alignment_max
1753
4
#endif
1754
4
      )
1755
0
    return;
1756
1757
4
  section->alignment_power = alignment_table[i].alignment_power;
1758
4
}
coff-stgo32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.92k
{
1730
1.92k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.92k
  unsigned int i;
1732
1733
17.1k
  for (i = 0; i < table_size; ++i)
1734
15.2k
    {
1735
15.2k
      const char *secname = bfd_section_name (section);
1736
1737
15.2k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
15.2k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
15.2k
    : strncmp (alignment_table[i].name, secname,
1740
7.61k
         alignment_table[i].comparison_length) == 0)
1741
33
  break;
1742
15.2k
    }
1743
1.92k
  if (i >= table_size)
1744
1.88k
    return;
1745
1746
33
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
33
      && default_alignment < alignment_table[i].default_alignment_min)
1748
11
    return;
1749
1750
22
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
22
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
22
      && default_alignment > alignment_table[i].default_alignment_max
1753
22
#endif
1754
22
      )
1755
0
    return;
1756
1757
22
  section->alignment_power = alignment_table[i].alignment_power;
1758
22
}
coff-tic30.c:coff_set_custom_section_alignment
Line
Count
Source
1729
110k
{
1730
110k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
110k
  unsigned int i;
1732
1733
550k
  for (i = 0; i < table_size; ++i)
1734
440k
    {
1735
440k
      const char *secname = bfd_section_name (section);
1736
1737
440k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
440k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
440k
    : strncmp (alignment_table[i].name, secname,
1740
220k
         alignment_table[i].comparison_length) == 0)
1741
7
  break;
1742
440k
    }
1743
110k
  if (i >= table_size)
1744
110k
    return;
1745
1746
7
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
7
      && default_alignment < alignment_table[i].default_alignment_min)
1748
7
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
Unexecuted instantiation: coff-tic4x.c:coff_set_custom_section_alignment
coff-tic54x.c:coff_set_custom_section_alignment
Line
Count
Source
1729
11.4k
{
1730
11.4k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
11.4k
  unsigned int i;
1732
1733
57.2k
  for (i = 0; i < table_size; ++i)
1734
45.8k
    {
1735
45.8k
      const char *secname = bfd_section_name (section);
1736
1737
45.8k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
45.8k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
45.8k
    : strncmp (alignment_table[i].name, secname,
1740
22.9k
         alignment_table[i].comparison_length) == 0)
1741
3
  break;
1742
45.8k
    }
1743
11.4k
  if (i >= table_size)
1744
11.4k
    return;
1745
1746
3
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
3
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff-z80.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.51k
{
1730
2.51k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.51k
  unsigned int i;
1732
1733
12.5k
  for (i = 0; i < table_size; ++i)
1734
10.0k
    {
1735
10.0k
      const char *secname = bfd_section_name (section);
1736
1737
10.0k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
10.0k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
10.0k
    : strncmp (alignment_table[i].name, secname,
1740
5.02k
         alignment_table[i].comparison_length) == 0)
1741
2
  break;
1742
10.0k
    }
1743
2.51k
  if (i >= table_size)
1744
2.50k
    return;
1745
1746
2
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
2
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
      && default_alignment > alignment_table[i].default_alignment_max
1753
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
coff-z8k.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4.89k
{
1730
4.89k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4.89k
  unsigned int i;
1732
1733
24.4k
  for (i = 0; i < table_size; ++i)
1734
19.5k
    {
1735
19.5k
      const char *secname = bfd_section_name (section);
1736
1737
19.5k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
19.5k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
19.5k
    : strncmp (alignment_table[i].name, secname,
1740
9.79k
         alignment_table[i].comparison_length) == 0)
1741
4
  break;
1742
19.5k
    }
1743
4.89k
  if (i >= table_size)
1744
4.89k
    return;
1745
1746
4
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
pe-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
119
{
1730
119
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
119
  unsigned int i;
1732
1733
1.65k
  for (i = 0; i < table_size; ++i)
1734
1.53k
    {
1735
1.53k
      const char *secname = bfd_section_name (section);
1736
1737
1.53k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.53k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.53k
    : strncmp (alignment_table[i].name, secname,
1740
708
         alignment_table[i].comparison_length) == 0)
1741
1
  break;
1742
1.53k
    }
1743
119
  if (i >= table_size)
1744
118
    return;
1745
1746
1
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
pe-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
119
{
1730
119
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
119
  unsigned int i;
1732
1733
1.65k
  for (i = 0; i < table_size; ++i)
1734
1.53k
    {
1735
1.53k
      const char *secname = bfd_section_name (section);
1736
1737
1.53k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.53k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.53k
    : strncmp (alignment_table[i].name, secname,
1740
708
         alignment_table[i].comparison_length) == 0)
1741
1
  break;
1742
1.53k
    }
1743
119
  if (i >= table_size)
1744
118
    return;
1745
1746
1
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
1
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
1
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1
      && default_alignment > alignment_table[i].default_alignment_max
1753
1
#endif
1754
1
      )
1755
0
    return;
1756
1757
1
  section->alignment_power = alignment_table[i].alignment_power;
1758
1
}
pe-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
2.01k
{
1730
2.01k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
2.01k
  unsigned int i;
1732
1733
20.0k
  for (i = 0; i < table_size; ++i)
1734
18.0k
    {
1735
18.0k
      const char *secname = bfd_section_name (section);
1736
1737
18.0k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
18.0k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
18.0k
    : strncmp (alignment_table[i].name, secname,
1740
12.0k
         alignment_table[i].comparison_length) == 0)
1741
28
  break;
1742
18.0k
    }
1743
2.01k
  if (i >= table_size)
1744
1.98k
    return;
1745
1746
28
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
28
      && default_alignment < alignment_table[i].default_alignment_min)
1748
15
    return;
1749
1750
13
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
13
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
13
      && default_alignment > alignment_table[i].default_alignment_max
1753
13
#endif
1754
13
      )
1755
0
    return;
1756
1757
13
  section->alignment_power = alignment_table[i].alignment_power;
1758
13
}
pe-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
526
{
1730
526
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
526
  unsigned int i;
1732
1733
2.61k
  for (i = 0; i < table_size; ++i)
1734
2.09k
    {
1735
2.09k
      const char *secname = bfd_section_name (section);
1736
1737
2.09k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.09k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.09k
    : strncmp (alignment_table[i].name, secname,
1740
1.05k
         alignment_table[i].comparison_length) == 0)
1741
4
  break;
1742
2.09k
    }
1743
526
  if (i >= table_size)
1744
522
    return;
1745
1746
4
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4
      && default_alignment < alignment_table[i].default_alignment_min)
1748
4
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pe-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
287
{
1730
287
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
287
  unsigned int i;
1732
1733
1.43k
  for (i = 0; i < table_size; ++i)
1734
1.14k
    {
1735
1.14k
      const char *secname = bfd_section_name (section);
1736
1737
1.14k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.14k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.14k
    : strncmp (alignment_table[i].name, secname,
1740
574
         alignment_table[i].comparison_length) == 0)
1741
0
  break;
1742
1.14k
    }
1743
287
  if (i >= table_size)
1744
287
    return;
1745
1746
0
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
0
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
0
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
0
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
0
      && default_alignment > alignment_table[i].default_alignment_max
1753
0
#endif
1754
0
      )
1755
0
    return;
1756
1757
0
  section->alignment_power = alignment_table[i].alignment_power;
1758
0
}
pei-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
373
{
1730
373
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
373
  unsigned int i;
1732
1733
4.44k
  for (i = 0; i < table_size; ++i)
1734
4.13k
    {
1735
4.13k
      const char *secname = bfd_section_name (section);
1736
1737
4.13k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
4.13k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
4.13k
    : strncmp (alignment_table[i].name, secname,
1740
1.68k
         alignment_table[i].comparison_length) == 0)
1741
61
  break;
1742
4.13k
    }
1743
373
  if (i >= table_size)
1744
312
    return;
1745
1746
61
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
61
      && default_alignment < alignment_table[i].default_alignment_min)
1748
6
    return;
1749
1750
55
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
55
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
55
      && default_alignment > alignment_table[i].default_alignment_max
1753
55
#endif
1754
55
      )
1755
0
    return;
1756
1757
55
  section->alignment_power = alignment_table[i].alignment_power;
1758
55
}
pei-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
1.07k
{
1730
1.07k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
1.07k
  unsigned int i;
1732
1733
13.2k
  for (i = 0; i < table_size; ++i)
1734
12.2k
    {
1735
12.2k
      const char *secname = bfd_section_name (section);
1736
1737
12.2k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
12.2k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
12.2k
    : strncmp (alignment_table[i].name, secname,
1740
5.02k
         alignment_table[i].comparison_length) == 0)
1741
98
  break;
1742
12.2k
    }
1743
1.07k
  if (i >= table_size)
1744
977
    return;
1745
1746
98
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
98
      && default_alignment < alignment_table[i].default_alignment_min)
1748
7
    return;
1749
1750
91
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
91
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
91
      && default_alignment > alignment_table[i].default_alignment_max
1753
91
#endif
1754
91
      )
1755
0
    return;
1756
1757
91
  section->alignment_power = alignment_table[i].alignment_power;
1758
91
}
pei-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
856
{
1730
856
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
856
  unsigned int i;
1732
1733
4.09k
  for (i = 0; i < table_size; ++i)
1734
3.29k
    {
1735
3.29k
      const char *secname = bfd_section_name (section);
1736
1737
3.29k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
3.29k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
3.29k
    : strncmp (alignment_table[i].name, secname,
1740
1.67k
         alignment_table[i].comparison_length) == 0)
1741
57
  break;
1742
3.29k
    }
1743
856
  if (i >= table_size)
1744
799
    return;
1745
1746
57
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
57
      && default_alignment < alignment_table[i].default_alignment_min)
1748
24
    return;
1749
1750
33
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
33
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
33
      && default_alignment > alignment_table[i].default_alignment_max
1753
33
#endif
1754
33
      )
1755
0
    return;
1756
1757
33
  section->alignment_power = alignment_table[i].alignment_power;
1758
33
}
pei-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
982
{
1730
982
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
982
  unsigned int i;
1732
1733
4.31k
  for (i = 0; i < table_size; ++i)
1734
3.49k
    {
1735
3.49k
      const char *secname = bfd_section_name (section);
1736
1737
3.49k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
3.49k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
3.49k
    : strncmp (alignment_table[i].name, secname,
1740
1.85k
         alignment_table[i].comparison_length) == 0)
1741
165
  break;
1742
3.49k
    }
1743
982
  if (i >= table_size)
1744
817
    return;
1745
1746
165
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
165
      && default_alignment < alignment_table[i].default_alignment_min)
1748
60
    return;
1749
1750
105
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
105
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
105
      && default_alignment > alignment_table[i].default_alignment_max
1753
105
#endif
1754
105
      )
1755
0
    return;
1756
1757
105
  section->alignment_power = alignment_table[i].alignment_power;
1758
105
}
1759
1760
/* Custom section alignment records.  */
1761
1762
static const struct coff_section_alignment_entry
1763
coff_section_alignment_table[] =
1764
{
1765
#ifdef COFF_SECTION_ALIGNMENT_ENTRIES
1766
  COFF_SECTION_ALIGNMENT_ENTRIES,
1767
#endif
1768
  /* There must not be any gaps between .stabstr sections.  */
1769
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
1770
    1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
1771
  /* The .stab section must be aligned to 2**2 at most, to avoid gaps.  */
1772
  { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
1773
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1774
  /* Similarly for the .ctors and .dtors sections.  */
1775
  { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
1776
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
1777
  { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
1778
    3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
1779
};
1780
1781
static const unsigned int coff_section_alignment_table_size =
1782
  sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
1783
1784
/* Initialize a section structure with information peculiar to this
1785
   particular implementation of COFF.  */
1786
1787
static bool
1788
coff_new_section_hook (bfd * abfd, asection * section)
1789
206k
{
1790
206k
  combined_entry_type *native;
1791
206k
  size_t amt;
1792
206k
  unsigned char sclass = C_STAT;
1793
1794
206k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
4.84k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
4.84k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
0
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
4.84k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
4.84k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
4.84k
  else
1804
4.84k
    {
1805
4.84k
      int i;
1806
1807
57.8k
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
53.1k
  if (strcmp (bfd_section_name (section),
1809
53.1k
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
153
    {
1811
153
      section->alignment_power = 0;
1812
153
      sclass = C_DWARF;
1813
153
      break;
1814
153
    }
1815
4.84k
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
206k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
206k
  amt = sizeof (combined_entry_type) * 10;
1828
206k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
206k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
206k
  native->is_sym = true;
1839
206k
  native->u.syment.n_type = T_NULL;
1840
206k
  native->u.syment.n_sclass = sclass;
1841
1842
206k
  coffsymbol (section->symbol)->native = native;
1843
1844
206k
  coff_set_custom_section_alignment (abfd, section,
1845
206k
             coff_section_alignment_table,
1846
206k
             coff_section_alignment_table_size);
1847
1848
206k
  return true;
1849
206k
}
pei-i386.c:coff_new_section_hook
Line
Count
Source
1789
1.15k
{
1790
1.15k
  combined_entry_type *native;
1791
1.15k
  size_t amt;
1792
1.15k
  unsigned char sclass = C_STAT;
1793
1794
1.15k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.15k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.15k
  amt = sizeof (combined_entry_type) * 10;
1828
1.15k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.15k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.15k
  native->is_sym = true;
1839
1.15k
  native->u.syment.n_type = T_NULL;
1840
1.15k
  native->u.syment.n_sclass = sclass;
1841
1842
1.15k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.15k
  coff_set_custom_section_alignment (abfd, section,
1845
1.15k
             coff_section_alignment_table,
1846
1.15k
             coff_section_alignment_table_size);
1847
1848
1.15k
  return true;
1849
1.15k
}
pe-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
1.91k
{
1790
1.91k
  combined_entry_type *native;
1791
1.91k
  size_t amt;
1792
1.91k
  unsigned char sclass = C_STAT;
1793
1794
1.91k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.91k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.91k
  amt = sizeof (combined_entry_type) * 10;
1828
1.91k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.91k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.91k
  native->is_sym = true;
1839
1.91k
  native->u.syment.n_type = T_NULL;
1840
1.91k
  native->u.syment.n_sclass = sclass;
1841
1842
1.91k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.91k
  coff_set_custom_section_alignment (abfd, section,
1845
1.91k
             coff_section_alignment_table,
1846
1.91k
             coff_section_alignment_table_size);
1847
1848
1.91k
  return true;
1849
1.91k
}
pei-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
929
{
1790
929
  combined_entry_type *native;
1791
929
  size_t amt;
1792
929
  unsigned char sclass = C_STAT;
1793
1794
929
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
929
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
929
  amt = sizeof (combined_entry_type) * 10;
1828
929
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
929
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
929
  native->is_sym = true;
1839
929
  native->u.syment.n_type = T_NULL;
1840
929
  native->u.syment.n_sclass = sclass;
1841
1842
929
  coffsymbol (section->symbol)->native = native;
1843
1844
929
  coff_set_custom_section_alignment (abfd, section,
1845
929
             coff_section_alignment_table,
1846
929
             coff_section_alignment_table_size);
1847
1848
929
  return true;
1849
929
}
coff-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
6.18k
{
1790
6.18k
  combined_entry_type *native;
1791
6.18k
  size_t amt;
1792
6.18k
  unsigned char sclass = C_STAT;
1793
1794
6.18k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
6.18k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
6.18k
  amt = sizeof (combined_entry_type) * 10;
1828
6.18k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
6.18k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
6.18k
  native->is_sym = true;
1839
6.18k
  native->u.syment.n_type = T_NULL;
1840
6.18k
  native->u.syment.n_sclass = sclass;
1841
1842
6.18k
  coffsymbol (section->symbol)->native = native;
1843
1844
6.18k
  coff_set_custom_section_alignment (abfd, section,
1845
6.18k
             coff_section_alignment_table,
1846
6.18k
             coff_section_alignment_table_size);
1847
1848
6.18k
  return true;
1849
6.18k
}
coff64-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
2.70k
{
1790
2.70k
  combined_entry_type *native;
1791
2.70k
  size_t amt;
1792
2.70k
  unsigned char sclass = C_STAT;
1793
1794
2.70k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
2.70k
#ifdef RS6000COFF_C
1797
2.70k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
2.70k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
0
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
2.70k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
2.70k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
2.70k
  else
1804
2.70k
    {
1805
2.70k
      int i;
1806
1807
32.4k
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
29.7k
  if (strcmp (bfd_section_name (section),
1809
29.7k
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
4
    {
1811
4
      section->alignment_power = 0;
1812
4
      sclass = C_DWARF;
1813
4
      break;
1814
4
    }
1815
2.70k
    }
1816
2.70k
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.70k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.70k
  amt = sizeof (combined_entry_type) * 10;
1828
2.70k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.70k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.70k
  native->is_sym = true;
1839
2.70k
  native->u.syment.n_type = T_NULL;
1840
2.70k
  native->u.syment.n_sclass = sclass;
1841
1842
2.70k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.70k
  coff_set_custom_section_alignment (abfd, section,
1845
2.70k
             coff_section_alignment_table,
1846
2.70k
             coff_section_alignment_table_size);
1847
1848
2.70k
  return true;
1849
2.70k
}
pe-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
2.30k
{
1790
2.30k
  combined_entry_type *native;
1791
2.30k
  size_t amt;
1792
2.30k
  unsigned char sclass = C_STAT;
1793
1794
2.30k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.30k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.30k
  amt = sizeof (combined_entry_type) * 10;
1828
2.30k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.30k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.30k
  native->is_sym = true;
1839
2.30k
  native->u.syment.n_type = T_NULL;
1840
2.30k
  native->u.syment.n_sclass = sclass;
1841
1842
2.30k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.30k
  coff_set_custom_section_alignment (abfd, section,
1845
2.30k
             coff_section_alignment_table,
1846
2.30k
             coff_section_alignment_table_size);
1847
1848
2.30k
  return true;
1849
2.30k
}
pei-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
15.1k
{
1790
15.1k
  combined_entry_type *native;
1791
15.1k
  size_t amt;
1792
15.1k
  unsigned char sclass = C_STAT;
1793
1794
15.1k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
15.1k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
15.1k
  amt = sizeof (combined_entry_type) * 10;
1828
15.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
15.1k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
15.1k
  native->is_sym = true;
1839
15.1k
  native->u.syment.n_type = T_NULL;
1840
15.1k
  native->u.syment.n_sclass = sclass;
1841
1842
15.1k
  coffsymbol (section->symbol)->native = native;
1843
1844
15.1k
  coff_set_custom_section_alignment (abfd, section,
1845
15.1k
             coff_section_alignment_table,
1846
15.1k
             coff_section_alignment_table_size);
1847
1848
15.1k
  return true;
1849
15.1k
}
pei-ia64.c:coff_new_section_hook
Line
Count
Source
1789
2.44k
{
1790
2.44k
  combined_entry_type *native;
1791
2.44k
  size_t amt;
1792
2.44k
  unsigned char sclass = C_STAT;
1793
1794
2.44k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.44k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.44k
  amt = sizeof (combined_entry_type) * 10;
1828
2.44k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.44k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.44k
  native->is_sym = true;
1839
2.44k
  native->u.syment.n_type = T_NULL;
1840
2.44k
  native->u.syment.n_sclass = sclass;
1841
1842
2.44k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.44k
  coff_set_custom_section_alignment (abfd, section,
1845
2.44k
             coff_section_alignment_table,
1846
2.44k
             coff_section_alignment_table_size);
1847
1848
2.44k
  return true;
1849
2.44k
}
pei-loongarch64.c:coff_new_section_hook
Line
Count
Source
1789
699
{
1790
699
  combined_entry_type *native;
1791
699
  size_t amt;
1792
699
  unsigned char sclass = C_STAT;
1793
1794
699
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
699
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
699
  amt = sizeof (combined_entry_type) * 10;
1828
699
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
699
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
699
  native->is_sym = true;
1839
699
  native->u.syment.n_type = T_NULL;
1840
699
  native->u.syment.n_sclass = sclass;
1841
1842
699
  coffsymbol (section->symbol)->native = native;
1843
1844
699
  coff_set_custom_section_alignment (abfd, section,
1845
699
             coff_section_alignment_table,
1846
699
             coff_section_alignment_table_size);
1847
1848
699
  return true;
1849
699
}
cf-i386lynx.c:coff_new_section_hook
Line
Count
Source
1789
9.20k
{
1790
9.20k
  combined_entry_type *native;
1791
9.20k
  size_t amt;
1792
9.20k
  unsigned char sclass = C_STAT;
1793
1794
9.20k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
9.20k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
9.20k
  amt = sizeof (combined_entry_type) * 10;
1828
9.20k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
9.20k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
9.20k
  native->is_sym = true;
1839
9.20k
  native->u.syment.n_type = T_NULL;
1840
9.20k
  native->u.syment.n_sclass = sclass;
1841
1842
9.20k
  coffsymbol (section->symbol)->native = native;
1843
1844
9.20k
  coff_set_custom_section_alignment (abfd, section,
1845
9.20k
             coff_section_alignment_table,
1846
9.20k
             coff_section_alignment_table_size);
1847
1848
9.20k
  return true;
1849
9.20k
}
coff-go32.c:coff_new_section_hook
Line
Count
Source
1789
6.15k
{
1790
6.15k
  combined_entry_type *native;
1791
6.15k
  size_t amt;
1792
6.15k
  unsigned char sclass = C_STAT;
1793
1794
6.15k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
6.15k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
6.15k
  amt = sizeof (combined_entry_type) * 10;
1828
6.15k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
6.15k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
6.15k
  native->is_sym = true;
1839
6.15k
  native->u.syment.n_type = T_NULL;
1840
6.15k
  native->u.syment.n_sclass = sclass;
1841
1842
6.15k
  coffsymbol (section->symbol)->native = native;
1843
1844
6.15k
  coff_set_custom_section_alignment (abfd, section,
1845
6.15k
             coff_section_alignment_table,
1846
6.15k
             coff_section_alignment_table_size);
1847
1848
6.15k
  return true;
1849
6.15k
}
coff-i386.c:coff_new_section_hook
Line
Count
Source
1789
7.30k
{
1790
7.30k
  combined_entry_type *native;
1791
7.30k
  size_t amt;
1792
7.30k
  unsigned char sclass = C_STAT;
1793
1794
7.30k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
7.30k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
7.30k
  amt = sizeof (combined_entry_type) * 10;
1828
7.30k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
7.30k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
7.30k
  native->is_sym = true;
1839
7.30k
  native->u.syment.n_type = T_NULL;
1840
7.30k
  native->u.syment.n_sclass = sclass;
1841
1842
7.30k
  coffsymbol (section->symbol)->native = native;
1843
1844
7.30k
  coff_set_custom_section_alignment (abfd, section,
1845
7.30k
             coff_section_alignment_table,
1846
7.30k
             coff_section_alignment_table_size);
1847
1848
7.30k
  return true;
1849
7.30k
}
coff-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
2.14k
{
1790
2.14k
  combined_entry_type *native;
1791
2.14k
  size_t amt;
1792
2.14k
  unsigned char sclass = C_STAT;
1793
1794
2.14k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
2.14k
#ifdef RS6000COFF_C
1797
2.14k
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
2.14k
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
0
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
2.14k
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
2.14k
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
0
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
2.14k
  else
1804
2.14k
    {
1805
2.14k
      int i;
1806
1807
25.4k
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
23.4k
  if (strcmp (bfd_section_name (section),
1809
23.4k
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
149
    {
1811
149
      section->alignment_power = 0;
1812
149
      sclass = C_DWARF;
1813
149
      break;
1814
149
    }
1815
2.14k
    }
1816
2.14k
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.14k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.14k
  amt = sizeof (combined_entry_type) * 10;
1828
2.14k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.14k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.14k
  native->is_sym = true;
1839
2.14k
  native->u.syment.n_type = T_NULL;
1840
2.14k
  native->u.syment.n_sclass = sclass;
1841
1842
2.14k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.14k
  coff_set_custom_section_alignment (abfd, section,
1845
2.14k
             coff_section_alignment_table,
1846
2.14k
             coff_section_alignment_table_size);
1847
1848
2.14k
  return true;
1849
2.14k
}
coff-sh.c:coff_new_section_hook
Line
Count
Source
1789
10.6k
{
1790
10.6k
  combined_entry_type *native;
1791
10.6k
  size_t amt;
1792
10.6k
  unsigned char sclass = C_STAT;
1793
1794
10.6k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
10.6k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
10.6k
  amt = sizeof (combined_entry_type) * 10;
1828
10.6k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
10.6k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
10.6k
  native->is_sym = true;
1839
10.6k
  native->u.syment.n_type = T_NULL;
1840
10.6k
  native->u.syment.n_sclass = sclass;
1841
1842
10.6k
  coffsymbol (section->symbol)->native = native;
1843
1844
10.6k
  coff_set_custom_section_alignment (abfd, section,
1845
10.6k
             coff_section_alignment_table,
1846
10.6k
             coff_section_alignment_table_size);
1847
1848
10.6k
  return true;
1849
10.6k
}
coff-stgo32.c:coff_new_section_hook
Line
Count
Source
1789
1.92k
{
1790
1.92k
  combined_entry_type *native;
1791
1.92k
  size_t amt;
1792
1.92k
  unsigned char sclass = C_STAT;
1793
1794
1.92k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.92k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.92k
  amt = sizeof (combined_entry_type) * 10;
1828
1.92k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.92k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.92k
  native->is_sym = true;
1839
1.92k
  native->u.syment.n_type = T_NULL;
1840
1.92k
  native->u.syment.n_sclass = sclass;
1841
1842
1.92k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.92k
  coff_set_custom_section_alignment (abfd, section,
1845
1.92k
             coff_section_alignment_table,
1846
1.92k
             coff_section_alignment_table_size);
1847
1848
1.92k
  return true;
1849
1.92k
}
coff-tic30.c:coff_new_section_hook
Line
Count
Source
1789
110k
{
1790
110k
  combined_entry_type *native;
1791
110k
  size_t amt;
1792
110k
  unsigned char sclass = C_STAT;
1793
1794
110k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
110k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
110k
  amt = sizeof (combined_entry_type) * 10;
1828
110k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
110k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
110k
  native->is_sym = true;
1839
110k
  native->u.syment.n_type = T_NULL;
1840
110k
  native->u.syment.n_sclass = sclass;
1841
1842
110k
  coffsymbol (section->symbol)->native = native;
1843
1844
110k
  coff_set_custom_section_alignment (abfd, section,
1845
110k
             coff_section_alignment_table,
1846
110k
             coff_section_alignment_table_size);
1847
1848
110k
  return true;
1849
110k
}
Unexecuted instantiation: coff-tic4x.c:coff_new_section_hook
coff-tic54x.c:coff_new_section_hook
Line
Count
Source
1789
11.4k
{
1790
11.4k
  combined_entry_type *native;
1791
11.4k
  size_t amt;
1792
11.4k
  unsigned char sclass = C_STAT;
1793
1794
11.4k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
11.4k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
11.4k
  amt = sizeof (combined_entry_type) * 10;
1828
11.4k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
11.4k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
11.4k
  native->is_sym = true;
1839
11.4k
  native->u.syment.n_type = T_NULL;
1840
11.4k
  native->u.syment.n_sclass = sclass;
1841
1842
11.4k
  coffsymbol (section->symbol)->native = native;
1843
1844
11.4k
  coff_set_custom_section_alignment (abfd, section,
1845
11.4k
             coff_section_alignment_table,
1846
11.4k
             coff_section_alignment_table_size);
1847
1848
11.4k
  return true;
1849
11.4k
}
coff-z80.c:coff_new_section_hook
Line
Count
Source
1789
2.51k
{
1790
2.51k
  combined_entry_type *native;
1791
2.51k
  size_t amt;
1792
2.51k
  unsigned char sclass = C_STAT;
1793
1794
2.51k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.51k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.51k
  amt = sizeof (combined_entry_type) * 10;
1828
2.51k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.51k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.51k
  native->is_sym = true;
1839
2.51k
  native->u.syment.n_type = T_NULL;
1840
2.51k
  native->u.syment.n_sclass = sclass;
1841
1842
2.51k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.51k
  coff_set_custom_section_alignment (abfd, section,
1845
2.51k
             coff_section_alignment_table,
1846
2.51k
             coff_section_alignment_table_size);
1847
1848
2.51k
  return true;
1849
2.51k
}
coff-z8k.c:coff_new_section_hook
Line
Count
Source
1789
4.89k
{
1790
4.89k
  combined_entry_type *native;
1791
4.89k
  size_t amt;
1792
4.89k
  unsigned char sclass = C_STAT;
1793
1794
4.89k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
4.89k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
4.89k
  amt = sizeof (combined_entry_type) * 10;
1828
4.89k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4.89k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
4.89k
  native->is_sym = true;
1839
4.89k
  native->u.syment.n_type = T_NULL;
1840
4.89k
  native->u.syment.n_sclass = sclass;
1841
1842
4.89k
  coffsymbol (section->symbol)->native = native;
1843
1844
4.89k
  coff_set_custom_section_alignment (abfd, section,
1845
4.89k
             coff_section_alignment_table,
1846
4.89k
             coff_section_alignment_table_size);
1847
1848
4.89k
  return true;
1849
4.89k
}
pe-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
119
{
1790
119
  combined_entry_type *native;
1791
119
  size_t amt;
1792
119
  unsigned char sclass = C_STAT;
1793
1794
119
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
119
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
119
  amt = sizeof (combined_entry_type) * 10;
1828
119
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
119
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
119
  native->is_sym = true;
1839
119
  native->u.syment.n_type = T_NULL;
1840
119
  native->u.syment.n_sclass = sclass;
1841
1842
119
  coffsymbol (section->symbol)->native = native;
1843
1844
119
  coff_set_custom_section_alignment (abfd, section,
1845
119
             coff_section_alignment_table,
1846
119
             coff_section_alignment_table_size);
1847
1848
119
  return true;
1849
119
}
pe-arm.c:coff_new_section_hook
Line
Count
Source
1789
119
{
1790
119
  combined_entry_type *native;
1791
119
  size_t amt;
1792
119
  unsigned char sclass = C_STAT;
1793
1794
119
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
119
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
119
  amt = sizeof (combined_entry_type) * 10;
1828
119
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
119
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
119
  native->is_sym = true;
1839
119
  native->u.syment.n_type = T_NULL;
1840
119
  native->u.syment.n_sclass = sclass;
1841
1842
119
  coffsymbol (section->symbol)->native = native;
1843
1844
119
  coff_set_custom_section_alignment (abfd, section,
1845
119
             coff_section_alignment_table,
1846
119
             coff_section_alignment_table_size);
1847
1848
119
  return true;
1849
119
}
pe-i386.c:coff_new_section_hook
Line
Count
Source
1789
2.01k
{
1790
2.01k
  combined_entry_type *native;
1791
2.01k
  size_t amt;
1792
2.01k
  unsigned char sclass = C_STAT;
1793
1794
2.01k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
2.01k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
2.01k
  amt = sizeof (combined_entry_type) * 10;
1828
2.01k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
2.01k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
2.01k
  native->is_sym = true;
1839
2.01k
  native->u.syment.n_type = T_NULL;
1840
2.01k
  native->u.syment.n_sclass = sclass;
1841
1842
2.01k
  coffsymbol (section->symbol)->native = native;
1843
1844
2.01k
  coff_set_custom_section_alignment (abfd, section,
1845
2.01k
             coff_section_alignment_table,
1846
2.01k
             coff_section_alignment_table_size);
1847
1848
2.01k
  return true;
1849
2.01k
}
pe-mcore.c:coff_new_section_hook
Line
Count
Source
1789
526
{
1790
526
  combined_entry_type *native;
1791
526
  size_t amt;
1792
526
  unsigned char sclass = C_STAT;
1793
1794
526
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
526
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
526
  amt = sizeof (combined_entry_type) * 10;
1828
526
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
526
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
526
  native->is_sym = true;
1839
526
  native->u.syment.n_type = T_NULL;
1840
526
  native->u.syment.n_sclass = sclass;
1841
1842
526
  coffsymbol (section->symbol)->native = native;
1843
1844
526
  coff_set_custom_section_alignment (abfd, section,
1845
526
             coff_section_alignment_table,
1846
526
             coff_section_alignment_table_size);
1847
1848
526
  return true;
1849
526
}
pe-sh.c:coff_new_section_hook
Line
Count
Source
1789
287
{
1790
287
  combined_entry_type *native;
1791
287
  size_t amt;
1792
287
  unsigned char sclass = C_STAT;
1793
1794
287
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
287
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
287
  amt = sizeof (combined_entry_type) * 10;
1828
287
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
287
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
287
  native->is_sym = true;
1839
287
  native->u.syment.n_type = T_NULL;
1840
287
  native->u.syment.n_sclass = sclass;
1841
1842
287
  coffsymbol (section->symbol)->native = native;
1843
1844
287
  coff_set_custom_section_alignment (abfd, section,
1845
287
             coff_section_alignment_table,
1846
287
             coff_section_alignment_table_size);
1847
1848
287
  return true;
1849
287
}
pei-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
373
{
1790
373
  combined_entry_type *native;
1791
373
  size_t amt;
1792
373
  unsigned char sclass = C_STAT;
1793
1794
373
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
373
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
373
  amt = sizeof (combined_entry_type) * 10;
1828
373
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
373
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
373
  native->is_sym = true;
1839
373
  native->u.syment.n_type = T_NULL;
1840
373
  native->u.syment.n_sclass = sclass;
1841
1842
373
  coffsymbol (section->symbol)->native = native;
1843
1844
373
  coff_set_custom_section_alignment (abfd, section,
1845
373
             coff_section_alignment_table,
1846
373
             coff_section_alignment_table_size);
1847
1848
373
  return true;
1849
373
}
pei-arm.c:coff_new_section_hook
Line
Count
Source
1789
1.07k
{
1790
1.07k
  combined_entry_type *native;
1791
1.07k
  size_t amt;
1792
1.07k
  unsigned char sclass = C_STAT;
1793
1794
1.07k
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
1.07k
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
1.07k
  amt = sizeof (combined_entry_type) * 10;
1828
1.07k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
1.07k
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
1.07k
  native->is_sym = true;
1839
1.07k
  native->u.syment.n_type = T_NULL;
1840
1.07k
  native->u.syment.n_sclass = sclass;
1841
1842
1.07k
  coffsymbol (section->symbol)->native = native;
1843
1844
1.07k
  coff_set_custom_section_alignment (abfd, section,
1845
1.07k
             coff_section_alignment_table,
1846
1.07k
             coff_section_alignment_table_size);
1847
1848
1.07k
  return true;
1849
1.07k
}
pei-mcore.c:coff_new_section_hook
Line
Count
Source
1789
856
{
1790
856
  combined_entry_type *native;
1791
856
  size_t amt;
1792
856
  unsigned char sclass = C_STAT;
1793
1794
856
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
856
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
856
  amt = sizeof (combined_entry_type) * 10;
1828
856
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
856
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
856
  native->is_sym = true;
1839
856
  native->u.syment.n_type = T_NULL;
1840
856
  native->u.syment.n_sclass = sclass;
1841
1842
856
  coffsymbol (section->symbol)->native = native;
1843
1844
856
  coff_set_custom_section_alignment (abfd, section,
1845
856
             coff_section_alignment_table,
1846
856
             coff_section_alignment_table_size);
1847
1848
856
  return true;
1849
856
}
pei-sh.c:coff_new_section_hook
Line
Count
Source
1789
982
{
1790
982
  combined_entry_type *native;
1791
982
  size_t amt;
1792
982
  unsigned char sclass = C_STAT;
1793
1794
982
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
982
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
982
  amt = sizeof (combined_entry_type) * 10;
1828
982
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
982
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
982
  native->is_sym = true;
1839
982
  native->u.syment.n_type = T_NULL;
1840
982
  native->u.syment.n_sclass = sclass;
1841
1842
982
  coffsymbol (section->symbol)->native = native;
1843
1844
982
  coff_set_custom_section_alignment (abfd, section,
1845
982
             coff_section_alignment_table,
1846
982
             coff_section_alignment_table_size);
1847
1848
982
  return true;
1849
982
}
1850
1851
#ifdef COFF_ALIGN_IN_SECTION_HEADER
1852
1853
/* Set the alignment of a BFD section.  */
1854
1855
static void
1856
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1857
       asection * section,
1858
       void * scnhdr)
1859
13.9k
{
1860
13.9k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
13.9k
  unsigned int i;
1862
1863
13.9k
#ifdef COFF_DECODE_ALIGNMENT
1864
13.9k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
13.9k
#endif
1866
13.9k
  section->alignment_power = i;
1867
1868
#ifdef coff_set_section_load_page
1869
11.4k
  coff_set_section_load_page (section, hdr->s_page);
1870
#endif
1871
13.9k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_alignment_hook
coff-tic54x.c:coff_set_alignment_hook
Line
Count
Source
1859
11.4k
{
1860
11.4k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
11.4k
  unsigned int i;
1862
1863
11.4k
#ifdef COFF_DECODE_ALIGNMENT
1864
11.4k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
11.4k
#endif
1866
11.4k
  section->alignment_power = i;
1867
1868
11.4k
#ifdef coff_set_section_load_page
1869
11.4k
  coff_set_section_load_page (section, hdr->s_page);
1870
11.4k
#endif
1871
11.4k
}
coff-z80.c:coff_set_alignment_hook
Line
Count
Source
1859
2.51k
{
1860
2.51k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
2.51k
  unsigned int i;
1862
1863
2.51k
#ifdef COFF_DECODE_ALIGNMENT
1864
2.51k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
2.51k
#endif
1866
2.51k
  section->alignment_power = i;
1867
1868
#ifdef coff_set_section_load_page
1869
  coff_set_section_load_page (section, hdr->s_page);
1870
#endif
1871
2.51k
}
1872
1873
#else /* ! COFF_ALIGN_IN_SECTION_HEADER */
1874
#ifdef COFF_WITH_PE
1875
1876
static void
1877
coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
1878
       asection * section,
1879
       void * scnhdr)
1880
30.5k
{
1881
30.5k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
30.5k
  size_t amt;
1883
30.5k
  unsigned int alignment_power_const
1884
30.5k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
30.5k
  switch (alignment_power_const)
1887
30.5k
    {
1888
786
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
843
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
1.28k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
1.37k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
2.66k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
2.77k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
2.94k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
3.16k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
6.45k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
6.53k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
7.04k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
7.22k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
7.65k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
8.25k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
8.25k
      section->alignment_power
1903
8.25k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
8.25k
      break;
1905
22.2k
    default:
1906
22.2k
      break;
1907
30.5k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
30.5k
  if (coff_section_data (abfd, section) == NULL)
1914
30.5k
    {
1915
30.5k
      amt = sizeof (struct coff_section_tdata);
1916
30.5k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
30.5k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
30.5k
    }
1921
1922
30.5k
  if (pei_section_data (abfd, section) == NULL)
1923
30.5k
    {
1924
30.5k
      amt = sizeof (struct pei_section_tdata);
1925
30.5k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
30.5k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
30.5k
    }
1930
30.5k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
30.5k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
30.5k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
30.5k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
4.02k
    {
1938
4.02k
      struct external_reloc dst;
1939
4.02k
      struct internal_reloc n;
1940
4.02k
      file_ptr oldpos = bfd_tell (abfd);
1941
4.02k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
4.02k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
4.02k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
3.39k
  return;
1947
1948
631
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
631
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
631
      if (n.r_vaddr < 0x10000)
1952
90
  {
1953
90
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
90
    bfd_set_error (bfd_error_bad_value);
1955
90
    return;
1956
90
  }
1957
541
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
541
      section->rel_filepos += relsz;
1959
541
    }
1960
26.5k
  else if (hdr->s_nreloc == 0xffff)
1961
55
    _bfd_error_handler
1962
55
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
55
       abfd);
1964
30.5k
}
pei-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
1.13k
{
1881
1.13k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
1.13k
  size_t amt;
1883
1.13k
  unsigned int alignment_power_const
1884
1.13k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
1.13k
  switch (alignment_power_const)
1887
1.13k
    {
1888
17
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
17
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
32
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
36
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
40
    case IMAGE_SCN_ALIGN_512BYTES:
1893
57
    case IMAGE_SCN_ALIGN_256BYTES:
1894
61
    case IMAGE_SCN_ALIGN_128BYTES:
1895
65
    case IMAGE_SCN_ALIGN_64BYTES:
1896
144
    case IMAGE_SCN_ALIGN_32BYTES:
1897
156
    case IMAGE_SCN_ALIGN_16BYTES:
1898
169
    case IMAGE_SCN_ALIGN_8BYTES:
1899
188
    case IMAGE_SCN_ALIGN_4BYTES:
1900
194
    case IMAGE_SCN_ALIGN_2BYTES:
1901
212
    case IMAGE_SCN_ALIGN_1BYTES:
1902
212
      section->alignment_power
1903
212
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
212
      break;
1905
926
    default:
1906
926
      break;
1907
1.13k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
1.13k
  if (coff_section_data (abfd, section) == NULL)
1914
1.13k
    {
1915
1.13k
      amt = sizeof (struct coff_section_tdata);
1916
1.13k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
1.13k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
1.13k
    }
1921
1922
1.13k
  if (pei_section_data (abfd, section) == NULL)
1923
1.13k
    {
1924
1.13k
      amt = sizeof (struct pei_section_tdata);
1925
1.13k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
1.13k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
1.13k
    }
1930
1.13k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
1.13k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
1.13k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
1.13k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
55
    {
1938
55
      struct external_reloc dst;
1939
55
      struct internal_reloc n;
1940
55
      file_ptr oldpos = bfd_tell (abfd);
1941
55
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
55
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
55
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
39
  return;
1947
1948
16
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
16
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
16
      if (n.r_vaddr < 0x10000)
1952
7
  {
1953
7
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
7
    bfd_set_error (bfd_error_bad_value);
1955
7
    return;
1956
7
  }
1957
9
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
9
      section->rel_filepos += relsz;
1959
9
    }
1960
1.08k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
1.13k
}
pe-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
1.91k
{
1881
1.91k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
1.91k
  size_t amt;
1883
1.91k
  unsigned int alignment_power_const
1884
1.91k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
1.91k
  switch (alignment_power_const)
1887
1.91k
    {
1888
38
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
54
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
66
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
88
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
149
    case IMAGE_SCN_ALIGN_512BYTES:
1893
162
    case IMAGE_SCN_ALIGN_256BYTES:
1894
196
    case IMAGE_SCN_ALIGN_128BYTES:
1895
256
    case IMAGE_SCN_ALIGN_64BYTES:
1896
314
    case IMAGE_SCN_ALIGN_32BYTES:
1897
324
    case IMAGE_SCN_ALIGN_16BYTES:
1898
342
    case IMAGE_SCN_ALIGN_8BYTES:
1899
395
    case IMAGE_SCN_ALIGN_4BYTES:
1900
426
    case IMAGE_SCN_ALIGN_2BYTES:
1901
565
    case IMAGE_SCN_ALIGN_1BYTES:
1902
565
      section->alignment_power
1903
565
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
565
      break;
1905
1.35k
    default:
1906
1.35k
      break;
1907
1.91k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
1.91k
  if (coff_section_data (abfd, section) == NULL)
1914
1.91k
    {
1915
1.91k
      amt = sizeof (struct coff_section_tdata);
1916
1.91k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
1.91k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
1.91k
    }
1921
1922
1.91k
  if (pei_section_data (abfd, section) == NULL)
1923
1.91k
    {
1924
1.91k
      amt = sizeof (struct pei_section_tdata);
1925
1.91k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
1.91k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
1.91k
    }
1930
1.91k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
1.91k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
1.91k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
1.91k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
320
    {
1938
320
      struct external_reloc dst;
1939
320
      struct internal_reloc n;
1940
320
      file_ptr oldpos = bfd_tell (abfd);
1941
320
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
320
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
320
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
204
  return;
1947
1948
116
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
116
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
116
      if (n.r_vaddr < 0x10000)
1952
6
  {
1953
6
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
6
    bfd_set_error (bfd_error_bad_value);
1955
6
    return;
1956
6
  }
1957
110
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
110
      section->rel_filepos += relsz;
1959
110
    }
1960
1.59k
  else if (hdr->s_nreloc == 0xffff)
1961
18
    _bfd_error_handler
1962
18
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
18
       abfd);
1964
1.91k
}
pei-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
919
{
1881
919
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
919
  size_t amt;
1883
919
  unsigned int alignment_power_const
1884
919
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
919
  switch (alignment_power_const)
1887
919
    {
1888
10
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
10
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
18
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
18
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
23
    case IMAGE_SCN_ALIGN_512BYTES:
1893
31
    case IMAGE_SCN_ALIGN_256BYTES:
1894
32
    case IMAGE_SCN_ALIGN_128BYTES:
1895
35
    case IMAGE_SCN_ALIGN_64BYTES:
1896
97
    case IMAGE_SCN_ALIGN_32BYTES:
1897
97
    case IMAGE_SCN_ALIGN_16BYTES:
1898
102
    case IMAGE_SCN_ALIGN_8BYTES:
1899
112
    case IMAGE_SCN_ALIGN_4BYTES:
1900
117
    case IMAGE_SCN_ALIGN_2BYTES:
1901
119
    case IMAGE_SCN_ALIGN_1BYTES:
1902
119
      section->alignment_power
1903
119
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
119
      break;
1905
800
    default:
1906
800
      break;
1907
919
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
919
  if (coff_section_data (abfd, section) == NULL)
1914
919
    {
1915
919
      amt = sizeof (struct coff_section_tdata);
1916
919
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
919
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
919
    }
1921
1922
919
  if (pei_section_data (abfd, section) == NULL)
1923
919
    {
1924
919
      amt = sizeof (struct pei_section_tdata);
1925
919
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
919
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
919
    }
1930
919
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
919
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
919
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
919
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
85
    {
1938
85
      struct external_reloc dst;
1939
85
      struct internal_reloc n;
1940
85
      file_ptr oldpos = bfd_tell (abfd);
1941
85
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
85
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
85
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
72
  return;
1947
1948
13
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
13
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
13
      if (n.r_vaddr < 0x10000)
1952
3
  {
1953
3
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
3
    bfd_set_error (bfd_error_bad_value);
1955
3
    return;
1956
3
  }
1957
10
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
10
      section->rel_filepos += relsz;
1959
10
    }
1960
834
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
919
}
pe-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
2.30k
{
1881
2.30k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
2.30k
  size_t amt;
1883
2.30k
  unsigned int alignment_power_const
1884
2.30k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
2.30k
  switch (alignment_power_const)
1887
2.30k
    {
1888
57
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
63
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
64
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
70
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
1.09k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
1.10k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
1.11k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
1.19k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
1.20k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
1.21k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
1.21k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
1.22k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
1.23k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
1.24k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
1.24k
      section->alignment_power
1903
1.24k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
1.24k
      break;
1905
1.06k
    default:
1906
1.06k
      break;
1907
2.30k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
2.30k
  if (coff_section_data (abfd, section) == NULL)
1914
2.30k
    {
1915
2.30k
      amt = sizeof (struct coff_section_tdata);
1916
2.30k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
2.30k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
2.30k
    }
1921
1922
2.30k
  if (pei_section_data (abfd, section) == NULL)
1923
2.30k
    {
1924
2.30k
      amt = sizeof (struct pei_section_tdata);
1925
2.30k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
2.30k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
2.30k
    }
1930
2.30k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
2.30k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
2.30k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
2.30k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
237
    {
1938
237
      struct external_reloc dst;
1939
237
      struct internal_reloc n;
1940
237
      file_ptr oldpos = bfd_tell (abfd);
1941
237
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
237
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
237
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
174
  return;
1947
1948
63
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
63
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
63
      if (n.r_vaddr < 0x10000)
1952
16
  {
1953
16
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
16
    bfd_set_error (bfd_error_bad_value);
1955
16
    return;
1956
16
  }
1957
47
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
47
      section->rel_filepos += relsz;
1959
47
    }
1960
2.06k
  else if (hdr->s_nreloc == 0xffff)
1961
7
    _bfd_error_handler
1962
7
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
7
       abfd);
1964
2.30k
}
pei-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
15.0k
{
1881
15.0k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
15.0k
  size_t amt;
1883
15.0k
  unsigned int alignment_power_const
1884
15.0k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
15.0k
  switch (alignment_power_const)
1887
15.0k
    {
1888
32
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
34
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
38
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
63
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
86
    case IMAGE_SCN_ALIGN_512BYTES:
1893
89
    case IMAGE_SCN_ALIGN_256BYTES:
1894
128
    case IMAGE_SCN_ALIGN_128BYTES:
1895
144
    case IMAGE_SCN_ALIGN_64BYTES:
1896
3.01k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
3.01k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
3.07k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
3.07k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
3.09k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
3.17k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
3.17k
      section->alignment_power
1903
3.17k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
3.17k
      break;
1905
11.9k
    default:
1906
11.9k
      break;
1907
15.0k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
15.0k
  if (coff_section_data (abfd, section) == NULL)
1914
15.0k
    {
1915
15.0k
      amt = sizeof (struct coff_section_tdata);
1916
15.0k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
15.0k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
15.0k
    }
1921
1922
15.0k
  if (pei_section_data (abfd, section) == NULL)
1923
15.0k
    {
1924
15.0k
      amt = sizeof (struct pei_section_tdata);
1925
15.0k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
15.0k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
15.0k
    }
1930
15.0k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
15.0k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
15.0k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
15.0k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
2.46k
    {
1938
2.46k
      struct external_reloc dst;
1939
2.46k
      struct internal_reloc n;
1940
2.46k
      file_ptr oldpos = bfd_tell (abfd);
1941
2.46k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
2.46k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
2.46k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
2.41k
  return;
1947
1948
50
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
50
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
50
      if (n.r_vaddr < 0x10000)
1952
24
  {
1953
24
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
24
    bfd_set_error (bfd_error_bad_value);
1955
24
    return;
1956
24
  }
1957
26
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
26
      section->rel_filepos += relsz;
1959
26
    }
1960
12.6k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
15.0k
}
pei-ia64.c:coff_set_alignment_hook
Line
Count
Source
1880
2.43k
{
1881
2.43k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
2.43k
  size_t amt;
1883
2.43k
  unsigned int alignment_power_const
1884
2.43k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
2.43k
  switch (alignment_power_const)
1887
2.43k
    {
1888
39
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
41
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
44
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
48
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
77
    case IMAGE_SCN_ALIGN_512BYTES:
1893
85
    case IMAGE_SCN_ALIGN_256BYTES:
1894
95
    case IMAGE_SCN_ALIGN_128BYTES:
1895
100
    case IMAGE_SCN_ALIGN_64BYTES:
1896
118
    case IMAGE_SCN_ALIGN_32BYTES:
1897
123
    case IMAGE_SCN_ALIGN_16BYTES:
1898
329
    case IMAGE_SCN_ALIGN_8BYTES:
1899
353
    case IMAGE_SCN_ALIGN_4BYTES:
1900
380
    case IMAGE_SCN_ALIGN_2BYTES:
1901
433
    case IMAGE_SCN_ALIGN_1BYTES:
1902
433
      section->alignment_power
1903
433
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
433
      break;
1905
2.00k
    default:
1906
2.00k
      break;
1907
2.43k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
2.43k
  if (coff_section_data (abfd, section) == NULL)
1914
2.43k
    {
1915
2.43k
      amt = sizeof (struct coff_section_tdata);
1916
2.43k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
2.43k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
2.43k
    }
1921
1922
2.43k
  if (pei_section_data (abfd, section) == NULL)
1923
2.43k
    {
1924
2.43k
      amt = sizeof (struct pei_section_tdata);
1925
2.43k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
2.43k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
2.43k
    }
1930
2.43k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
2.43k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
2.43k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
2.43k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
91
    {
1938
91
      struct external_reloc dst;
1939
91
      struct internal_reloc n;
1940
91
      file_ptr oldpos = bfd_tell (abfd);
1941
91
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
91
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
91
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
43
  return;
1947
1948
48
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
48
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
48
      if (n.r_vaddr < 0x10000)
1952
9
  {
1953
9
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
9
    bfd_set_error (bfd_error_bad_value);
1955
9
    return;
1956
9
  }
1957
39
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
39
      section->rel_filepos += relsz;
1959
39
    }
1960
2.34k
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
2.43k
}
pei-loongarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
673
{
1881
673
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
673
  size_t amt;
1883
673
  unsigned int alignment_power_const
1884
673
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
673
  switch (alignment_power_const)
1887
673
    {
1888
0
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
6
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
18
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
22
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
29
    case IMAGE_SCN_ALIGN_512BYTES:
1893
31
    case IMAGE_SCN_ALIGN_256BYTES:
1894
41
    case IMAGE_SCN_ALIGN_128BYTES:
1895
47
    case IMAGE_SCN_ALIGN_64BYTES:
1896
114
    case IMAGE_SCN_ALIGN_32BYTES:
1897
118
    case IMAGE_SCN_ALIGN_16BYTES:
1898
196
    case IMAGE_SCN_ALIGN_8BYTES:
1899
207
    case IMAGE_SCN_ALIGN_4BYTES:
1900
222
    case IMAGE_SCN_ALIGN_2BYTES:
1901
227
    case IMAGE_SCN_ALIGN_1BYTES:
1902
227
      section->alignment_power
1903
227
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
227
      break;
1905
446
    default:
1906
446
      break;
1907
673
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
673
  if (coff_section_data (abfd, section) == NULL)
1914
673
    {
1915
673
      amt = sizeof (struct coff_section_tdata);
1916
673
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
673
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
673
    }
1921
1922
673
  if (pei_section_data (abfd, section) == NULL)
1923
673
    {
1924
673
      amt = sizeof (struct pei_section_tdata);
1925
673
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
673
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
673
    }
1930
673
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
673
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
673
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
673
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
123
    {
1938
123
      struct external_reloc dst;
1939
123
      struct internal_reloc n;
1940
123
      file_ptr oldpos = bfd_tell (abfd);
1941
123
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
123
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
123
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
100
  return;
1947
1948
23
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
23
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
23
      if (n.r_vaddr < 0x10000)
1952
3
  {
1953
3
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
3
    bfd_set_error (bfd_error_bad_value);
1955
3
    return;
1956
3
  }
1957
20
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
20
      section->rel_filepos += relsz;
1959
20
    }
1960
550
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
673
}
pe-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
119
{
1881
119
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
119
  size_t amt;
1883
119
  unsigned int alignment_power_const
1884
119
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
119
  switch (alignment_power_const)
1887
119
    {
1888
2
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
2
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
10
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
10
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
10
    case IMAGE_SCN_ALIGN_512BYTES:
1893
13
    case IMAGE_SCN_ALIGN_256BYTES:
1894
13
    case IMAGE_SCN_ALIGN_128BYTES:
1895
20
    case IMAGE_SCN_ALIGN_64BYTES:
1896
25
    case IMAGE_SCN_ALIGN_32BYTES:
1897
33
    case IMAGE_SCN_ALIGN_16BYTES:
1898
40
    case IMAGE_SCN_ALIGN_8BYTES:
1899
41
    case IMAGE_SCN_ALIGN_4BYTES:
1900
48
    case IMAGE_SCN_ALIGN_2BYTES:
1901
50
    case IMAGE_SCN_ALIGN_1BYTES:
1902
50
      section->alignment_power
1903
50
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
50
      break;
1905
69
    default:
1906
69
      break;
1907
119
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
119
  if (coff_section_data (abfd, section) == NULL)
1914
119
    {
1915
119
      amt = sizeof (struct coff_section_tdata);
1916
119
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
119
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
119
    }
1921
1922
119
  if (pei_section_data (abfd, section) == NULL)
1923
119
    {
1924
119
      amt = sizeof (struct pei_section_tdata);
1925
119
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
119
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
119
    }
1930
119
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
119
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
119
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
119
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
41
    {
1938
41
      struct external_reloc dst;
1939
41
      struct internal_reloc n;
1940
41
      file_ptr oldpos = bfd_tell (abfd);
1941
41
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
41
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
41
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
31
  return;
1947
1948
10
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
10
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
10
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
10
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
10
      section->rel_filepos += relsz;
1959
10
    }
1960
78
  else if (hdr->s_nreloc == 0xffff)
1961
3
    _bfd_error_handler
1962
3
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
3
       abfd);
1964
119
}
pe-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
119
{
1881
119
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
119
  size_t amt;
1883
119
  unsigned int alignment_power_const
1884
119
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
119
  switch (alignment_power_const)
1887
119
    {
1888
2
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
2
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
10
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
10
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
10
    case IMAGE_SCN_ALIGN_512BYTES:
1893
13
    case IMAGE_SCN_ALIGN_256BYTES:
1894
13
    case IMAGE_SCN_ALIGN_128BYTES:
1895
20
    case IMAGE_SCN_ALIGN_64BYTES:
1896
25
    case IMAGE_SCN_ALIGN_32BYTES:
1897
33
    case IMAGE_SCN_ALIGN_16BYTES:
1898
40
    case IMAGE_SCN_ALIGN_8BYTES:
1899
41
    case IMAGE_SCN_ALIGN_4BYTES:
1900
48
    case IMAGE_SCN_ALIGN_2BYTES:
1901
50
    case IMAGE_SCN_ALIGN_1BYTES:
1902
50
      section->alignment_power
1903
50
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
50
      break;
1905
69
    default:
1906
69
      break;
1907
119
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
119
  if (coff_section_data (abfd, section) == NULL)
1914
119
    {
1915
119
      amt = sizeof (struct coff_section_tdata);
1916
119
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
119
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
119
    }
1921
1922
119
  if (pei_section_data (abfd, section) == NULL)
1923
119
    {
1924
119
      amt = sizeof (struct pei_section_tdata);
1925
119
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
119
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
119
    }
1930
119
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
119
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
119
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
119
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
41
    {
1938
41
      struct external_reloc dst;
1939
41
      struct internal_reloc n;
1940
41
      file_ptr oldpos = bfd_tell (abfd);
1941
41
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
41
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
41
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
31
  return;
1947
1948
10
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
10
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
10
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
10
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
10
      section->rel_filepos += relsz;
1959
10
    }
1960
78
  else if (hdr->s_nreloc == 0xffff)
1961
3
    _bfd_error_handler
1962
3
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
3
       abfd);
1964
119
}
pe-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
2.01k
{
1881
2.01k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
2.01k
  size_t amt;
1883
2.01k
  unsigned int alignment_power_const
1884
2.01k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
2.01k
  switch (alignment_power_const)
1887
2.01k
    {
1888
8
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
18
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
132
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
136
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
148
    case IMAGE_SCN_ALIGN_512BYTES:
1893
166
    case IMAGE_SCN_ALIGN_256BYTES:
1894
175
    case IMAGE_SCN_ALIGN_128BYTES:
1895
181
    case IMAGE_SCN_ALIGN_64BYTES:
1896
206
    case IMAGE_SCN_ALIGN_32BYTES:
1897
215
    case IMAGE_SCN_ALIGN_16BYTES:
1898
225
    case IMAGE_SCN_ALIGN_8BYTES:
1899
245
    case IMAGE_SCN_ALIGN_4BYTES:
1900
493
    case IMAGE_SCN_ALIGN_2BYTES:
1901
762
    case IMAGE_SCN_ALIGN_1BYTES:
1902
762
      section->alignment_power
1903
762
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
762
      break;
1905
1.25k
    default:
1906
1.25k
      break;
1907
2.01k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
2.01k
  if (coff_section_data (abfd, section) == NULL)
1914
2.01k
    {
1915
2.01k
      amt = sizeof (struct coff_section_tdata);
1916
2.01k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
2.01k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
2.01k
    }
1921
1922
2.01k
  if (pei_section_data (abfd, section) == NULL)
1923
2.01k
    {
1924
2.01k
      amt = sizeof (struct pei_section_tdata);
1925
2.01k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
2.01k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
2.01k
    }
1930
2.01k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
2.01k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
2.01k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
2.01k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
148
    {
1938
148
      struct external_reloc dst;
1939
148
      struct internal_reloc n;
1940
148
      file_ptr oldpos = bfd_tell (abfd);
1941
148
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
148
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
148
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
92
  return;
1947
1948
56
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
56
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
56
      if (n.r_vaddr < 0x10000)
1952
10
  {
1953
10
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
10
    bfd_set_error (bfd_error_bad_value);
1955
10
    return;
1956
10
  }
1957
46
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
46
      section->rel_filepos += relsz;
1959
46
    }
1960
1.86k
  else if (hdr->s_nreloc == 0xffff)
1961
12
    _bfd_error_handler
1962
12
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
12
       abfd);
1964
2.01k
}
pe-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
526
{
1881
526
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
526
  size_t amt;
1883
526
  unsigned int alignment_power_const
1884
526
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
526
  switch (alignment_power_const)
1887
526
    {
1888
3
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
6
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
18
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
18
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
21
    case IMAGE_SCN_ALIGN_512BYTES:
1893
27
    case IMAGE_SCN_ALIGN_256BYTES:
1894
34
    case IMAGE_SCN_ALIGN_128BYTES:
1895
35
    case IMAGE_SCN_ALIGN_64BYTES:
1896
45
    case IMAGE_SCN_ALIGN_32BYTES:
1897
45
    case IMAGE_SCN_ALIGN_16BYTES:
1898
47
    case IMAGE_SCN_ALIGN_8BYTES:
1899
52
    case IMAGE_SCN_ALIGN_4BYTES:
1900
58
    case IMAGE_SCN_ALIGN_2BYTES:
1901
62
    case IMAGE_SCN_ALIGN_1BYTES:
1902
62
      section->alignment_power
1903
62
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
62
      break;
1905
464
    default:
1906
464
      break;
1907
526
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
526
  if (coff_section_data (abfd, section) == NULL)
1914
526
    {
1915
526
      amt = sizeof (struct coff_section_tdata);
1916
526
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
526
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
526
    }
1921
1922
526
  if (pei_section_data (abfd, section) == NULL)
1923
526
    {
1924
526
      amt = sizeof (struct pei_section_tdata);
1925
526
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
526
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
526
    }
1930
526
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
526
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
526
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
526
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
36
    {
1938
36
      struct external_reloc dst;
1939
36
      struct internal_reloc n;
1940
36
      file_ptr oldpos = bfd_tell (abfd);
1941
36
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
36
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
36
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
15
  return;
1947
1948
21
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
21
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
21
      if (n.r_vaddr < 0x10000)
1952
3
  {
1953
3
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
3
    bfd_set_error (bfd_error_bad_value);
1955
3
    return;
1956
3
  }
1957
18
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
18
      section->rel_filepos += relsz;
1959
18
    }
1960
490
  else if (hdr->s_nreloc == 0xffff)
1961
7
    _bfd_error_handler
1962
7
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
7
       abfd);
1964
526
}
pe-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
287
{
1881
287
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
287
  size_t amt;
1883
287
  unsigned int alignment_power_const
1884
287
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
287
  switch (alignment_power_const)
1887
287
    {
1888
5
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
8
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
19
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
23
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
44
    case IMAGE_SCN_ALIGN_512BYTES:
1893
47
    case IMAGE_SCN_ALIGN_256BYTES:
1894
48
    case IMAGE_SCN_ALIGN_128BYTES:
1895
55
    case IMAGE_SCN_ALIGN_64BYTES:
1896
67
    case IMAGE_SCN_ALIGN_32BYTES:
1897
68
    case IMAGE_SCN_ALIGN_16BYTES:
1898
80
    case IMAGE_SCN_ALIGN_8BYTES:
1899
87
    case IMAGE_SCN_ALIGN_4BYTES:
1900
93
    case IMAGE_SCN_ALIGN_2BYTES:
1901
97
    case IMAGE_SCN_ALIGN_1BYTES:
1902
97
      section->alignment_power
1903
97
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
97
      break;
1905
190
    default:
1906
190
      break;
1907
287
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
287
  if (coff_section_data (abfd, section) == NULL)
1914
287
    {
1915
287
      amt = sizeof (struct coff_section_tdata);
1916
287
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
287
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
287
    }
1921
1922
287
  if (pei_section_data (abfd, section) == NULL)
1923
287
    {
1924
287
      amt = sizeof (struct pei_section_tdata);
1925
287
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
287
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
287
    }
1930
287
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
287
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
287
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
287
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
42
    {
1938
42
      struct external_reloc dst;
1939
42
      struct internal_reloc n;
1940
42
      file_ptr oldpos = bfd_tell (abfd);
1941
42
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
42
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
42
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
26
  return;
1947
1948
16
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
16
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
16
      if (n.r_vaddr < 0x10000)
1952
3
  {
1953
3
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
3
    bfd_set_error (bfd_error_bad_value);
1955
3
    return;
1956
3
  }
1957
13
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
13
      section->rel_filepos += relsz;
1959
13
    }
1960
245
  else if (hdr->s_nreloc == 0xffff)
1961
5
    _bfd_error_handler
1962
5
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
5
       abfd);
1964
287
}
pei-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
333
{
1881
333
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
333
  size_t amt;
1883
333
  unsigned int alignment_power_const
1884
333
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
333
  switch (alignment_power_const)
1887
333
    {
1888
55
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
58
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
156
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
157
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
164
    case IMAGE_SCN_ALIGN_512BYTES:
1893
169
    case IMAGE_SCN_ALIGN_256BYTES:
1894
178
    case IMAGE_SCN_ALIGN_128BYTES:
1895
180
    case IMAGE_SCN_ALIGN_64BYTES:
1896
182
    case IMAGE_SCN_ALIGN_32BYTES:
1897
182
    case IMAGE_SCN_ALIGN_16BYTES:
1898
209
    case IMAGE_SCN_ALIGN_8BYTES:
1899
219
    case IMAGE_SCN_ALIGN_4BYTES:
1900
220
    case IMAGE_SCN_ALIGN_2BYTES:
1901
226
    case IMAGE_SCN_ALIGN_1BYTES:
1902
226
      section->alignment_power
1903
226
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
226
      break;
1905
107
    default:
1906
107
      break;
1907
333
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
333
  if (coff_section_data (abfd, section) == NULL)
1914
333
    {
1915
333
      amt = sizeof (struct coff_section_tdata);
1916
333
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
333
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
333
    }
1921
1922
333
  if (pei_section_data (abfd, section) == NULL)
1923
333
    {
1924
333
      amt = sizeof (struct pei_section_tdata);
1925
333
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
333
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
333
    }
1930
333
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
333
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
333
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
333
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
37
    {
1938
37
      struct external_reloc dst;
1939
37
      struct internal_reloc n;
1940
37
      file_ptr oldpos = bfd_tell (abfd);
1941
37
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
37
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
37
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
29
  return;
1947
1948
8
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
8
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
8
      if (n.r_vaddr < 0x10000)
1952
2
  {
1953
2
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
2
    bfd_set_error (bfd_error_bad_value);
1955
2
    return;
1956
2
  }
1957
6
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
6
      section->rel_filepos += relsz;
1959
6
    }
1960
296
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
333
}
pei-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
1.03k
{
1881
1.03k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
1.03k
  size_t amt;
1883
1.03k
  unsigned int alignment_power_const
1884
1.03k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
1.03k
  switch (alignment_power_const)
1887
1.03k
    {
1888
96
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
99
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
202
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
213
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
220
    case IMAGE_SCN_ALIGN_512BYTES:
1893
226
    case IMAGE_SCN_ALIGN_256BYTES:
1894
235
    case IMAGE_SCN_ALIGN_128BYTES:
1895
240
    case IMAGE_SCN_ALIGN_64BYTES:
1896
292
    case IMAGE_SCN_ALIGN_32BYTES:
1897
294
    case IMAGE_SCN_ALIGN_16BYTES:
1898
326
    case IMAGE_SCN_ALIGN_8BYTES:
1899
337
    case IMAGE_SCN_ALIGN_4BYTES:
1900
341
    case IMAGE_SCN_ALIGN_2BYTES:
1901
349
    case IMAGE_SCN_ALIGN_1BYTES:
1902
349
      section->alignment_power
1903
349
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
349
      break;
1905
686
    default:
1906
686
      break;
1907
1.03k
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
1.03k
  if (coff_section_data (abfd, section) == NULL)
1914
1.03k
    {
1915
1.03k
      amt = sizeof (struct coff_section_tdata);
1916
1.03k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
1.03k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
1.03k
    }
1921
1922
1.03k
  if (pei_section_data (abfd, section) == NULL)
1923
1.03k
    {
1924
1.03k
      amt = sizeof (struct pei_section_tdata);
1925
1.03k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
1.03k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
1.03k
    }
1930
1.03k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
1.03k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
1.03k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
1.03k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
194
    {
1938
194
      struct external_reloc dst;
1939
194
      struct internal_reloc n;
1940
194
      file_ptr oldpos = bfd_tell (abfd);
1941
194
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
194
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
194
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
49
  return;
1947
1948
145
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
145
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
145
      if (n.r_vaddr < 0x10000)
1952
3
  {
1953
3
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
3
    bfd_set_error (bfd_error_bad_value);
1955
3
    return;
1956
3
  }
1957
142
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
142
      section->rel_filepos += relsz;
1959
142
    }
1960
841
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
1.03k
}
pei-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
851
{
1881
851
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
851
  size_t amt;
1883
851
  unsigned int alignment_power_const
1884
851
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
851
  switch (alignment_power_const)
1887
851
    {
1888
92
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
94
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
120
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
127
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
152
    case IMAGE_SCN_ALIGN_512BYTES:
1893
152
    case IMAGE_SCN_ALIGN_256BYTES:
1894
171
    case IMAGE_SCN_ALIGN_128BYTES:
1895
177
    case IMAGE_SCN_ALIGN_64BYTES:
1896
185
    case IMAGE_SCN_ALIGN_32BYTES:
1897
188
    case IMAGE_SCN_ALIGN_16BYTES:
1898
208
    case IMAGE_SCN_ALIGN_8BYTES:
1899
210
    case IMAGE_SCN_ALIGN_4BYTES:
1900
235
    case IMAGE_SCN_ALIGN_2BYTES:
1901
241
    case IMAGE_SCN_ALIGN_1BYTES:
1902
241
      section->alignment_power
1903
241
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
241
      break;
1905
610
    default:
1906
610
      break;
1907
851
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
851
  if (coff_section_data (abfd, section) == NULL)
1914
851
    {
1915
851
      amt = sizeof (struct coff_section_tdata);
1916
851
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
851
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
851
    }
1921
1922
851
  if (pei_section_data (abfd, section) == NULL)
1923
851
    {
1924
851
      amt = sizeof (struct pei_section_tdata);
1925
851
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
851
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
851
    }
1930
851
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
851
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
851
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
851
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
86
    {
1938
86
      struct external_reloc dst;
1939
86
      struct internal_reloc n;
1940
86
      file_ptr oldpos = bfd_tell (abfd);
1941
86
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
86
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
86
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
59
  return;
1947
1948
27
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
27
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
27
      if (n.r_vaddr < 0x10000)
1952
1
  {
1953
1
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1
    bfd_set_error (bfd_error_bad_value);
1955
1
    return;
1956
1
  }
1957
26
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
26
      section->rel_filepos += relsz;
1959
26
    }
1960
765
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
851
}
pei-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
790
{
1881
790
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
790
  size_t amt;
1883
790
  unsigned int alignment_power_const
1884
790
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
790
  switch (alignment_power_const)
1887
790
    {
1888
330
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
331
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
334
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
338
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
397
    case IMAGE_SCN_ALIGN_512BYTES:
1893
404
    case IMAGE_SCN_ALIGN_256BYTES:
1894
404
    case IMAGE_SCN_ALIGN_128BYTES:
1895
407
    case IMAGE_SCN_ALIGN_64BYTES:
1896
423
    case IMAGE_SCN_ALIGN_32BYTES:
1897
429
    case IMAGE_SCN_ALIGN_16BYTES:
1898
443
    case IMAGE_SCN_ALIGN_8BYTES:
1899
443
    case IMAGE_SCN_ALIGN_4BYTES:
1900
447
    case IMAGE_SCN_ALIGN_2BYTES:
1901
448
    case IMAGE_SCN_ALIGN_1BYTES:
1902
448
      section->alignment_power
1903
448
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
448
      break;
1905
342
    default:
1906
342
      break;
1907
790
    }
1908
1909
  /* In a PE image file, the s_paddr field holds the virtual size of a
1910
     section, while the s_size field holds the raw size.  We also keep
1911
     the original section flag value, since not every bit can be
1912
     mapped onto a generic BFD section bit.  */
1913
790
  if (coff_section_data (abfd, section) == NULL)
1914
790
    {
1915
790
      amt = sizeof (struct coff_section_tdata);
1916
790
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
790
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
790
    }
1921
1922
790
  if (pei_section_data (abfd, section) == NULL)
1923
790
    {
1924
790
      amt = sizeof (struct pei_section_tdata);
1925
790
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
790
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
790
    }
1930
790
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
790
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
790
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
790
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
26
    {
1938
26
      struct external_reloc dst;
1939
26
      struct internal_reloc n;
1940
26
      file_ptr oldpos = bfd_tell (abfd);
1941
26
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
26
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
26
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
17
  return;
1947
1948
9
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
9
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
9
      if (n.r_vaddr < 0x10000)
1952
0
  {
1953
0
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
0
    bfd_set_error (bfd_error_bad_value);
1955
0
    return;
1956
0
  }
1957
9
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
9
      section->rel_filepos += relsz;
1959
9
    }
1960
764
  else if (hdr->s_nreloc == 0xffff)
1961
0
    _bfd_error_handler
1962
0
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
0
       abfd);
1964
790
}
1965
#undef ALIGN_SET
1966
#undef ELIFALIGN_SET
1967
1968
#else /* ! COFF_WITH_PE */
1969
#ifdef RS6000COFF_C
1970
1971
/* We grossly abuse this function to handle XCOFF overflow headers.
1972
   When we see one, we correct the reloc and line number counts in the
1973
   real header, and remove the section we just created.  */
1974
1975
static void
1976
coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
1977
4.84k
{
1978
4.84k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
4.84k
  asection *real_sec;
1980
1981
4.84k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
3.56k
    return;
1983
1984
1.28k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
1.28k
  if (real_sec == NULL)
1986
0
    return;
1987
1988
1.28k
  real_sec->reloc_count = hdr->s_paddr;
1989
1.28k
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
1.28k
  if (!bfd_section_removed_from_list (abfd, section))
1992
1.28k
    {
1993
1.28k
      bfd_section_list_remove (abfd, section);
1994
1.28k
      --abfd->section_count;
1995
1.28k
    }
1996
1.28k
}
coff64-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
2.70k
{
1978
2.70k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
2.70k
  asection *real_sec;
1980
1981
2.70k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
2.07k
    return;
1983
1984
632
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
632
  if (real_sec == NULL)
1986
0
    return;
1987
1988
632
  real_sec->reloc_count = hdr->s_paddr;
1989
632
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
632
  if (!bfd_section_removed_from_list (abfd, section))
1992
632
    {
1993
632
      bfd_section_list_remove (abfd, section);
1994
632
      --abfd->section_count;
1995
632
    }
1996
632
}
coff-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
2.14k
{
1978
2.14k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
2.14k
  asection *real_sec;
1980
1981
2.14k
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
1.49k
    return;
1983
1984
648
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
648
  if (real_sec == NULL)
1986
0
    return;
1987
1988
648
  real_sec->reloc_count = hdr->s_paddr;
1989
648
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
648
  if (!bfd_section_removed_from_list (abfd, section))
1992
648
    {
1993
648
      bfd_section_list_remove (abfd, section);
1994
648
      --abfd->section_count;
1995
648
    }
1996
648
}
1997
1998
#else /* ! RS6000COFF_C */
1999
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
2000
2001
static void
2002
coff_set_alignment_hook (bfd * abfd, asection * section, void * scnhdr)
2003
8.07k
{
2004
8.07k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
8.07k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
2.82k
    {
2009
2.82k
      struct external_reloc dst;
2010
2.82k
      struct internal_reloc n;
2011
2.82k
      const file_ptr oldpos = bfd_tell (abfd);
2012
2.82k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
2.82k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
2.82k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
2.59k
  return;
2018
2019
225
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
225
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
225
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
225
      section->rel_filepos += relsz;
2024
225
    }
2025
5.25k
  else if (hdr->s_nreloc == 0xffff)
2026
90
    _bfd_error_handler
2027
90
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
90
       abfd);
2029
8.07k
}
coff-go32.c:coff_set_alignment_hook
Line
Count
Source
2003
6.15k
{
2004
6.15k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
6.15k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
2.40k
    {
2009
2.40k
      struct external_reloc dst;
2010
2.40k
      struct internal_reloc n;
2011
2.40k
      const file_ptr oldpos = bfd_tell (abfd);
2012
2.40k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
2.40k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
2.40k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
2.28k
  return;
2018
2019
124
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
124
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
124
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
124
      section->rel_filepos += relsz;
2024
124
    }
2025
3.74k
  else if (hdr->s_nreloc == 0xffff)
2026
55
    _bfd_error_handler
2027
55
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
55
       abfd);
2029
6.15k
}
coff-stgo32.c:coff_set_alignment_hook
Line
Count
Source
2003
1.92k
{
2004
1.92k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
1.92k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
417
    {
2009
417
      struct external_reloc dst;
2010
417
      struct internal_reloc n;
2011
417
      const file_ptr oldpos = bfd_tell (abfd);
2012
417
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
417
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
417
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
316
  return;
2018
2019
101
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
101
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
101
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
101
      section->rel_filepos += relsz;
2024
101
    }
2025
1.50k
  else if (hdr->s_nreloc == 0xffff)
2026
35
    _bfd_error_handler
2027
35
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
35
       abfd);
2029
1.92k
}
2030
2031
#else /* ! COFF_GO32_EXE && ! COFF_GO32 */
2032
2033
static void
2034
coff_set_alignment_hook (bfd *abfd ATTRIBUTE_UNUSED,
2035
       asection *section ATTRIBUTE_UNUSED,
2036
       void *scnhdr ATTRIBUTE_UNUSED)
2037
148k
{
2038
148k
}
coff-x86_64.c:coff_set_alignment_hook
Line
Count
Source
2037
6.18k
{
2038
6.18k
}
cf-i386lynx.c:coff_set_alignment_hook
Line
Count
Source
2037
9.20k
{
2038
9.20k
}
coff-i386.c:coff_set_alignment_hook
Line
Count
Source
2037
7.30k
{
2038
7.30k
}
coff-sh.c:coff_set_alignment_hook
Line
Count
Source
2037
10.6k
{
2038
10.6k
}
coff-tic30.c:coff_set_alignment_hook
Line
Count
Source
2037
110k
{
2038
110k
}
coff-z8k.c:coff_set_alignment_hook
Line
Count
Source
2037
4.89k
{
2038
4.89k
}
2039
2040
#endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
2041
#endif /* ! RS6000COFF_C */
2042
#endif /* ! COFF_WITH_PE */
2043
#endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
2044
2045
#ifndef coff_mkobject
2046
2047
static bool
2048
coff_mkobject (bfd * abfd)
2049
2.00k
{
2050
2.00k
  coff_data_type *coff;
2051
2.00k
  size_t amt = sizeof (coff_data_type);
2052
2053
2.00k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
2.00k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
2.00k
  coff = coff_data (abfd);
2058
2.00k
  coff->symbols = NULL;
2059
2.00k
  coff->conversion_table = NULL;
2060
2.00k
  coff->raw_syments = NULL;
2061
2.00k
  coff->relocbase = 0;
2062
2.00k
  coff->local_toc_sym_map = 0;
2063
2064
2.00k
  bfd_coff_long_section_names (abfd)
2065
2.00k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
2.00k
  return true;
2070
2.00k
}
coff-x86_64.c:coff_mkobject
Line
Count
Source
2049
610
{
2050
610
  coff_data_type *coff;
2051
610
  size_t amt = sizeof (coff_data_type);
2052
2053
610
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
610
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
610
  coff = coff_data (abfd);
2058
610
  coff->symbols = NULL;
2059
610
  coff->conversion_table = NULL;
2060
610
  coff->raw_syments = NULL;
2061
610
  coff->relocbase = 0;
2062
610
  coff->local_toc_sym_map = 0;
2063
2064
610
  bfd_coff_long_section_names (abfd)
2065
610
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
610
  return true;
2070
610
}
cf-i386lynx.c:coff_mkobject
Line
Count
Source
2049
219
{
2050
219
  coff_data_type *coff;
2051
219
  size_t amt = sizeof (coff_data_type);
2052
2053
219
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
219
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
219
  coff = coff_data (abfd);
2058
219
  coff->symbols = NULL;
2059
219
  coff->conversion_table = NULL;
2060
219
  coff->raw_syments = NULL;
2061
219
  coff->relocbase = 0;
2062
219
  coff->local_toc_sym_map = 0;
2063
2064
219
  bfd_coff_long_section_names (abfd)
2065
219
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
219
  return true;
2070
219
}
coff-i386.c:coff_mkobject
Line
Count
Source
2049
106
{
2050
106
  coff_data_type *coff;
2051
106
  size_t amt = sizeof (coff_data_type);
2052
2053
106
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
106
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
106
  coff = coff_data (abfd);
2058
106
  coff->symbols = NULL;
2059
106
  coff->conversion_table = NULL;
2060
106
  coff->raw_syments = NULL;
2061
106
  coff->relocbase = 0;
2062
106
  coff->local_toc_sym_map = 0;
2063
2064
106
  bfd_coff_long_section_names (abfd)
2065
106
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
106
  return true;
2070
106
}
coff-sh.c:coff_mkobject
Line
Count
Source
2049
155
{
2050
155
  coff_data_type *coff;
2051
155
  size_t amt = sizeof (coff_data_type);
2052
2053
155
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
155
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
155
  coff = coff_data (abfd);
2058
155
  coff->symbols = NULL;
2059
155
  coff->conversion_table = NULL;
2060
155
  coff->raw_syments = NULL;
2061
155
  coff->relocbase = 0;
2062
155
  coff->local_toc_sym_map = 0;
2063
2064
155
  bfd_coff_long_section_names (abfd)
2065
155
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
155
  return true;
2070
155
}
coff-tic30.c:coff_mkobject
Line
Count
Source
2049
253
{
2050
253
  coff_data_type *coff;
2051
253
  size_t amt = sizeof (coff_data_type);
2052
2053
253
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
253
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
253
  coff = coff_data (abfd);
2058
253
  coff->symbols = NULL;
2059
253
  coff->conversion_table = NULL;
2060
253
  coff->raw_syments = NULL;
2061
253
  coff->relocbase = 0;
2062
253
  coff->local_toc_sym_map = 0;
2063
2064
253
  bfd_coff_long_section_names (abfd)
2065
253
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
253
  return true;
2070
253
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject
coff-tic54x.c:coff_mkobject
Line
Count
Source
2049
300
{
2050
300
  coff_data_type *coff;
2051
300
  size_t amt = sizeof (coff_data_type);
2052
2053
300
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
300
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
300
  coff = coff_data (abfd);
2058
300
  coff->symbols = NULL;
2059
300
  coff->conversion_table = NULL;
2060
300
  coff->raw_syments = NULL;
2061
300
  coff->relocbase = 0;
2062
300
  coff->local_toc_sym_map = 0;
2063
2064
300
  bfd_coff_long_section_names (abfd)
2065
300
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
300
  return true;
2070
300
}
coff-z80.c:coff_mkobject
Line
Count
Source
2049
142
{
2050
142
  coff_data_type *coff;
2051
142
  size_t amt = sizeof (coff_data_type);
2052
2053
142
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
142
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
142
  coff = coff_data (abfd);
2058
142
  coff->symbols = NULL;
2059
142
  coff->conversion_table = NULL;
2060
142
  coff->raw_syments = NULL;
2061
142
  coff->relocbase = 0;
2062
142
  coff->local_toc_sym_map = 0;
2063
2064
142
  bfd_coff_long_section_names (abfd)
2065
142
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
142
  return true;
2070
142
}
coff-z8k.c:coff_mkobject
Line
Count
Source
2049
218
{
2050
218
  coff_data_type *coff;
2051
218
  size_t amt = sizeof (coff_data_type);
2052
2053
218
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
218
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
218
  coff = coff_data (abfd);
2058
218
  coff->symbols = NULL;
2059
218
  coff->conversion_table = NULL;
2060
218
  coff->raw_syments = NULL;
2061
218
  coff->relocbase = 0;
2062
218
  coff->local_toc_sym_map = 0;
2063
2064
218
  bfd_coff_long_section_names (abfd)
2065
218
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
218
  return true;
2070
218
}
2071
#endif
2072
2073
/* Create the COFF backend specific information.  */
2074
2075
#ifndef coff_mkobject_hook
2076
static void *
2077
coff_mkobject_hook (bfd * abfd,
2078
        void * filehdr,
2079
        void * aouthdr ATTRIBUTE_UNUSED)
2080
2.73k
{
2081
2.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
2.73k
  coff_data_type *coff;
2083
2084
2.73k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
2.73k
  coff = coff_data (abfd);
2088
2089
2.73k
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
2.73k
  coff->local_n_btmask = N_BTMASK;
2095
2.73k
  coff->local_n_btshft = N_BTSHFT;
2096
2.73k
  coff->local_n_tmask = N_TMASK;
2097
2.73k
  coff->local_n_tshift = N_TSHIFT;
2098
2.73k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
2.73k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
2.73k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
2.73k
  coff->timestamp = internal_f->f_timdat;
2103
2104
2.73k
  obj_raw_syment_count (abfd) =
2105
2.73k
    obj_conv_table_size (abfd) =
2106
2.73k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
510
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
39
    abfd->flags |= DYNAMIC;
2111
510
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
9
    {
2113
9
      struct internal_aouthdr *internal_a =
2114
9
  (struct internal_aouthdr *) aouthdr;
2115
9
      struct xcoff_tdata *xcoff;
2116
2117
9
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
5
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
9
      xcoff->full_aouthdr = true;
2124
9
      xcoff->toc = internal_a->o_toc;
2125
9
      xcoff->sntoc = internal_a->o_sntoc;
2126
9
      xcoff->snentry = internal_a->o_snentry;
2127
9
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
9
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
9
      xcoff->modtype = internal_a->o_modtype;
2130
9
      xcoff->cputype = internal_a->o_cputype;
2131
9
      xcoff->maxdata = internal_a->o_maxdata;
2132
9
      xcoff->maxstack = internal_a->o_maxstack;
2133
9
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
2.73k
  return coff;
2150
2.73k
}
coff-x86_64.c:coff_mkobject_hook
Line
Count
Source
2080
610
{
2081
610
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
610
  coff_data_type *coff;
2083
2084
610
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
610
  coff = coff_data (abfd);
2088
2089
610
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
610
  coff->local_n_btmask = N_BTMASK;
2095
610
  coff->local_n_btshft = N_BTSHFT;
2096
610
  coff->local_n_tmask = N_TMASK;
2097
610
  coff->local_n_tshift = N_TSHIFT;
2098
610
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
610
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
610
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
610
  coff->timestamp = internal_f->f_timdat;
2103
2104
610
  obj_raw_syment_count (abfd) =
2105
610
    obj_conv_table_size (abfd) =
2106
610
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
610
  return coff;
2150
610
}
coff64-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
214
{
2081
214
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
214
  coff_data_type *coff;
2083
2084
214
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
214
  coff = coff_data (abfd);
2088
2089
214
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
214
  coff->local_n_btmask = N_BTMASK;
2095
214
  coff->local_n_btshft = N_BTSHFT;
2096
214
  coff->local_n_tmask = N_TMASK;
2097
214
  coff->local_n_tshift = N_TSHIFT;
2098
214
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
214
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
214
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
214
  coff->timestamp = internal_f->f_timdat;
2103
2104
214
  obj_raw_syment_count (abfd) =
2105
214
    obj_conv_table_size (abfd) =
2106
214
      internal_f->f_nsyms;
2107
2108
214
#ifdef RS6000COFF_C
2109
214
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
22
    abfd->flags |= DYNAMIC;
2111
214
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
5
    {
2113
5
      struct internal_aouthdr *internal_a =
2114
5
  (struct internal_aouthdr *) aouthdr;
2115
5
      struct xcoff_tdata *xcoff;
2116
2117
5
      xcoff = xcoff_data (abfd);
2118
5
# ifdef U803XTOCMAGIC
2119
5
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
5
      xcoff->full_aouthdr = true;
2124
5
      xcoff->toc = internal_a->o_toc;
2125
5
      xcoff->sntoc = internal_a->o_sntoc;
2126
5
      xcoff->snentry = internal_a->o_snentry;
2127
5
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
5
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
5
      xcoff->modtype = internal_a->o_modtype;
2130
5
      xcoff->cputype = internal_a->o_cputype;
2131
5
      xcoff->maxdata = internal_a->o_maxdata;
2132
5
      xcoff->maxstack = internal_a->o_maxstack;
2133
5
    }
2134
214
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
214
  return coff;
2150
214
}
cf-i386lynx.c:coff_mkobject_hook
Line
Count
Source
2080
219
{
2081
219
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
219
  coff_data_type *coff;
2083
2084
219
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
219
  coff = coff_data (abfd);
2088
2089
219
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
219
  coff->local_n_btmask = N_BTMASK;
2095
219
  coff->local_n_btshft = N_BTSHFT;
2096
219
  coff->local_n_tmask = N_TMASK;
2097
219
  coff->local_n_tshift = N_TSHIFT;
2098
219
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
219
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
219
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
219
  coff->timestamp = internal_f->f_timdat;
2103
2104
219
  obj_raw_syment_count (abfd) =
2105
219
    obj_conv_table_size (abfd) =
2106
219
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
219
  return coff;
2150
219
}
coff-go32.c:coff_mkobject_hook
Line
Count
Source
2080
106
{
2081
106
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
106
  coff_data_type *coff;
2083
2084
106
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
106
  coff = coff_data (abfd);
2088
2089
106
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
106
  coff->local_n_btmask = N_BTMASK;
2095
106
  coff->local_n_btshft = N_BTSHFT;
2096
106
  coff->local_n_tmask = N_TMASK;
2097
106
  coff->local_n_tshift = N_TSHIFT;
2098
106
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
106
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
106
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
106
  coff->timestamp = internal_f->f_timdat;
2103
2104
106
  obj_raw_syment_count (abfd) =
2105
106
    obj_conv_table_size (abfd) =
2106
106
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
106
  return coff;
2150
106
}
coff-i386.c:coff_mkobject_hook
Line
Count
Source
2080
106
{
2081
106
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
106
  coff_data_type *coff;
2083
2084
106
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
106
  coff = coff_data (abfd);
2088
2089
106
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
106
  coff->local_n_btmask = N_BTMASK;
2095
106
  coff->local_n_btshft = N_BTSHFT;
2096
106
  coff->local_n_tmask = N_TMASK;
2097
106
  coff->local_n_tshift = N_TSHIFT;
2098
106
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
106
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
106
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
106
  coff->timestamp = internal_f->f_timdat;
2103
2104
106
  obj_raw_syment_count (abfd) =
2105
106
    obj_conv_table_size (abfd) =
2106
106
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
106
  return coff;
2150
106
}
coff-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
296
{
2081
296
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
296
  coff_data_type *coff;
2083
2084
296
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
296
  coff = coff_data (abfd);
2088
2089
296
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
296
  coff->local_n_btmask = N_BTMASK;
2095
296
  coff->local_n_btshft = N_BTSHFT;
2096
296
  coff->local_n_tmask = N_TMASK;
2097
296
  coff->local_n_tshift = N_TSHIFT;
2098
296
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
296
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
296
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
296
  coff->timestamp = internal_f->f_timdat;
2103
2104
296
  obj_raw_syment_count (abfd) =
2105
296
    obj_conv_table_size (abfd) =
2106
296
      internal_f->f_nsyms;
2107
2108
296
#ifdef RS6000COFF_C
2109
296
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
17
    abfd->flags |= DYNAMIC;
2111
296
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
4
    {
2113
4
      struct internal_aouthdr *internal_a =
2114
4
  (struct internal_aouthdr *) aouthdr;
2115
4
      struct xcoff_tdata *xcoff;
2116
2117
4
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
4
      xcoff->xcoff64 = 0;
2122
4
# endif
2123
4
      xcoff->full_aouthdr = true;
2124
4
      xcoff->toc = internal_a->o_toc;
2125
4
      xcoff->sntoc = internal_a->o_sntoc;
2126
4
      xcoff->snentry = internal_a->o_snentry;
2127
4
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
4
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
4
      xcoff->modtype = internal_a->o_modtype;
2130
4
      xcoff->cputype = internal_a->o_cputype;
2131
4
      xcoff->maxdata = internal_a->o_maxdata;
2132
4
      xcoff->maxstack = internal_a->o_maxstack;
2133
4
    }
2134
296
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
296
  return coff;
2150
296
}
coff-sh.c:coff_mkobject_hook
Line
Count
Source
2080
155
{
2081
155
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
155
  coff_data_type *coff;
2083
2084
155
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
155
  coff = coff_data (abfd);
2088
2089
155
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
155
  coff->local_n_btmask = N_BTMASK;
2095
155
  coff->local_n_btshft = N_BTSHFT;
2096
155
  coff->local_n_tmask = N_TMASK;
2097
155
  coff->local_n_tshift = N_TSHIFT;
2098
155
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
155
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
155
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
155
  coff->timestamp = internal_f->f_timdat;
2103
2104
155
  obj_raw_syment_count (abfd) =
2105
155
    obj_conv_table_size (abfd) =
2106
155
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
155
  return coff;
2150
155
}
coff-stgo32.c:coff_mkobject_hook
Line
Count
Source
2080
119
{
2081
119
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
119
  coff_data_type *coff;
2083
2084
119
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
119
  coff = coff_data (abfd);
2088
2089
119
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
119
  coff->local_n_btmask = N_BTMASK;
2095
119
  coff->local_n_btshft = N_BTSHFT;
2096
119
  coff->local_n_tmask = N_TMASK;
2097
119
  coff->local_n_tshift = N_TSHIFT;
2098
119
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
119
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
119
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
119
  coff->timestamp = internal_f->f_timdat;
2103
2104
119
  obj_raw_syment_count (abfd) =
2105
119
    obj_conv_table_size (abfd) =
2106
119
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
119
  return coff;
2150
119
}
coff-tic30.c:coff_mkobject_hook
Line
Count
Source
2080
253
{
2081
253
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
253
  coff_data_type *coff;
2083
2084
253
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
253
  coff = coff_data (abfd);
2088
2089
253
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
253
  coff->local_n_btmask = N_BTMASK;
2095
253
  coff->local_n_btshft = N_BTSHFT;
2096
253
  coff->local_n_tmask = N_TMASK;
2097
253
  coff->local_n_tshift = N_TSHIFT;
2098
253
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
253
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
253
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
253
  coff->timestamp = internal_f->f_timdat;
2103
2104
253
  obj_raw_syment_count (abfd) =
2105
253
    obj_conv_table_size (abfd) =
2106
253
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
253
  return coff;
2150
253
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject_hook
coff-tic54x.c:coff_mkobject_hook
Line
Count
Source
2080
300
{
2081
300
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
300
  coff_data_type *coff;
2083
2084
300
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
300
  coff = coff_data (abfd);
2088
2089
300
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
300
  coff->local_n_btmask = N_BTMASK;
2095
300
  coff->local_n_btshft = N_BTSHFT;
2096
300
  coff->local_n_tmask = N_TMASK;
2097
300
  coff->local_n_tshift = N_TSHIFT;
2098
300
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
300
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
300
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
300
  coff->timestamp = internal_f->f_timdat;
2103
2104
300
  obj_raw_syment_count (abfd) =
2105
300
    obj_conv_table_size (abfd) =
2106
300
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
300
  return coff;
2150
300
}
coff-z80.c:coff_mkobject_hook
Line
Count
Source
2080
142
{
2081
142
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
142
  coff_data_type *coff;
2083
2084
142
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
142
  coff = coff_data (abfd);
2088
2089
142
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
142
  coff->local_n_btmask = N_BTMASK;
2095
142
  coff->local_n_btshft = N_BTSHFT;
2096
142
  coff->local_n_tmask = N_TMASK;
2097
142
  coff->local_n_tshift = N_TSHIFT;
2098
142
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
142
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
142
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
142
  coff->timestamp = internal_f->f_timdat;
2103
2104
142
  obj_raw_syment_count (abfd) =
2105
142
    obj_conv_table_size (abfd) =
2106
142
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
142
  return coff;
2150
142
}
coff-z8k.c:coff_mkobject_hook
Line
Count
Source
2080
218
{
2081
218
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
218
  coff_data_type *coff;
2083
2084
218
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
218
  coff = coff_data (abfd);
2088
2089
218
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
218
  coff->local_n_btmask = N_BTMASK;
2095
218
  coff->local_n_btshft = N_BTSHFT;
2096
218
  coff->local_n_tmask = N_TMASK;
2097
218
  coff->local_n_tshift = N_TSHIFT;
2098
218
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
218
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
218
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
218
  coff->timestamp = internal_f->f_timdat;
2103
2104
218
  obj_raw_syment_count (abfd) =
2105
218
    obj_conv_table_size (abfd) =
2106
218
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
218
  return coff;
2150
218
}
2151
#endif
2152
2153
/* Determine the machine architecture and type.  FIXME: This is target
2154
   dependent because the magic numbers are defined in the target
2155
   dependent header files.  But there is no particular need for this.
2156
   If the magic numbers were moved to a separate file, this function
2157
   would be target independent and would also be much more successful
2158
   at linking together COFF files for different architectures.  */
2159
2160
static bool
2161
coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
2162
11.6k
{
2163
11.6k
  unsigned long machine;
2164
11.6k
  enum bfd_architecture arch;
2165
11.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
11.6k
  machine = 0;
2169
11.6k
  switch (internal_f->f_magic)
2170
11.6k
    {
2171
#ifdef I386MAGIC
2172
202
    case I386MAGIC:
2173
557
    case I386PTXMAGIC:
2174
2.14k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
2.18k
    case LYNXCOFFMAGIC:
2176
2.25k
    case I386_APPLE_MAGIC:
2177
2.25k
    case I386_FREEBSD_MAGIC:
2178
2.25k
    case I386_LINUX_MAGIC:
2179
2.47k
    case I386_NETBSD_MAGIC:
2180
2.47k
      arch = bfd_arch_i386;
2181
2.47k
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
851
    case AMD64MAGIC:
2185
1.54k
    case AMD64_APPLE_MAGIC:
2186
1.54k
    case AMD64_FREEBSD_MAGIC:
2187
1.54k
    case AMD64_LINUX_MAGIC:
2188
1.54k
    case AMD64_NETBSD_MAGIC:
2189
1.54k
      arch = bfd_arch_i386;
2190
1.54k
      machine = bfd_mach_x86_64;
2191
1.54k
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
309
    case IA64MAGIC:
2195
309
      arch = bfd_arch_ia64;
2196
309
      break;
2197
0
#endif
2198
#ifdef ARMMAGIC
2199
125
    case ARMMAGIC:
2200
175
    case ARMPEMAGIC:
2201
203
    case THUMBPEMAGIC:
2202
203
      arch = bfd_arch_arm;
2203
203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
203
      if (machine == bfd_mach_arm_unknown)
2205
203
  {
2206
203
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
203
      {
2208
4
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
2
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
8
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
114
      default:
2212
114
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
9
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
12
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
54
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
203
      }
2222
203
  }
2223
203
      break;
2224
203
#endif
2225
#ifdef AARCH64MAGIC
2226
4.78k
    case AARCH64MAGIC:
2227
4.78k
      arch = bfd_arch_aarch64;
2228
4.78k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
4.78k
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
213
    case LOONGARCH64MAGIC:
2233
213
      arch = bfd_arch_loongarch;
2234
213
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
213
      break;
2236
0
#endif
2237
#ifdef Z80MAGIC
2238
141
    case Z80MAGIC:
2239
141
      arch = bfd_arch_z80;
2240
141
      switch (internal_f->f_flags & F_MACHMASK)
2241
141
  {
2242
1
  case bfd_mach_z80strict << 12:
2243
1
  case bfd_mach_z80 << 12:
2244
15
  case bfd_mach_z80n << 12:
2245
33
  case bfd_mach_z80full << 12:
2246
34
  case bfd_mach_r800 << 12:
2247
36
  case bfd_mach_gbz80 << 12:
2248
38
  case bfd_mach_z180 << 12:
2249
46
  case bfd_mach_ez80_z80 << 12:
2250
140
  case bfd_mach_ez80_adl << 12:
2251
140
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
140
    break;
2253
1
  default:
2254
1
    return false;
2255
141
  }
2256
140
      break;
2257
140
#endif
2258
#ifdef Z8KMAGIC
2259
216
    case Z8KMAGIC:
2260
216
      arch = bfd_arch_z8k;
2261
216
      switch (internal_f->f_flags & F_MACHMASK)
2262
216
  {
2263
204
  case F_Z8001:
2264
204
    machine = bfd_mach_z8001;
2265
204
    break;
2266
10
  case F_Z8002:
2267
10
    machine = bfd_mach_z8002;
2268
10
    break;
2269
2
  default:
2270
2
    return false;
2271
216
  }
2272
214
      break;
2273
214
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
211
    case U64_TOCMAGIC:
2278
212
    case U803XTOCMAGIC:
2279
#else
2280
74
    case U802ROMAGIC:
2281
121
    case U802WRMAGIC:
2282
290
    case U802TOCMAGIC:
2283
#endif
2284
290
      {
2285
290
  int cputype;
2286
2287
502
  if (xcoff_data (abfd)->cputype != -1)
2288
7
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
495
  else
2290
495
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
495
      if (obj_raw_syment_count (abfd) == 0)
2296
320
        cputype = 0;
2297
175
      else
2298
175
        {
2299
175
    bfd_byte *buf;
2300
175
    struct internal_syment sym;
2301
175
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
175
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
2
      return false;
2305
173
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
173
    if (buf == NULL)
2307
4
      return false;
2308
169
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
169
    if (sym.n_sclass == C_FILE)
2310
2
      cputype = sym.n_type & 0xff;
2311
167
    else
2312
167
      cputype = 0;
2313
169
    free (buf);
2314
169
        }
2315
495
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
496
  switch (cputype)
2319
496
    {
2320
1
    default:
2321
493
    case 0:
2322
493
      arch = bfd_xcoff_architecture (abfd);
2323
493
      machine = bfd_xcoff_machine (abfd);
2324
493
      break;
2325
2326
2
    case 1:
2327
2
      arch = bfd_arch_powerpc;
2328
2
      machine = bfd_mach_ppc_601;
2329
2
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
1
    case 3:
2335
1
      arch = bfd_arch_powerpc;
2336
1
      machine = bfd_mach_ppc;
2337
1
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
496
    }
2343
496
      }
2344
496
      break;
2345
496
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
161
    case SH_ARCH_MAGIC_BIG:
2349
163
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
249
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
249
      arch = bfd_arch_sh;
2354
249
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
252
    case TIC30MAGIC:
2374
252
      arch = bfd_arch_tic30;
2375
252
      break;
2376
0
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
298
    case TICOFF0MAGIC:
2382
298
      arch = TICOFF_TARGET_ARCH;
2383
298
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
298
      break;
2385
0
#endif
2386
0
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
0
    case TICOFF1MAGIC:
2392
0
    case TICOFF2MAGIC:
2393
0
      switch (internal_f->f_target_id)
2394
0
  {
2395
0
#ifdef TI_TARGET_ID
2396
0
  case TI_TARGET_ID:
2397
0
    arch = TICOFF_TARGET_ARCH;
2398
0
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
0
    break;
2400
0
#endif
2401
0
  default:
2402
0
    arch = bfd_arch_obscure;
2403
0
    _bfd_error_handler
2404
0
      (_("unrecognized TI COFF target id '0x%x'"),
2405
0
       internal_f->f_target_id);
2406
0
    break;
2407
0
  }
2408
0
      break;
2409
0
#endif
2410
2411
#ifdef MCOREMAGIC
2412
233
    case MCOREMAGIC:
2413
233
      arch = bfd_arch_mcore;
2414
233
      break;
2415
0
#endif
2416
2417
102
    default:      /* Unreadable input file type.  */
2418
102
      arch = bfd_arch_obscure;
2419
102
      break;
2420
11.6k
    }
2421
2422
11.6k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
11.6k
  return true;
2424
11.6k
}
pei-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
230
{
2163
230
  unsigned long machine;
2164
230
  enum bfd_architecture arch;
2165
230
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
230
  machine = 0;
2169
230
  switch (internal_f->f_magic)
2170
230
    {
2171
0
#ifdef I386MAGIC
2172
142
    case I386MAGIC:
2173
221
    case I386PTXMAGIC:
2174
230
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
230
    case LYNXCOFFMAGIC:
2176
230
    case I386_APPLE_MAGIC:
2177
230
    case I386_FREEBSD_MAGIC:
2178
230
    case I386_LINUX_MAGIC:
2179
230
    case I386_NETBSD_MAGIC:
2180
230
      arch = bfd_arch_i386;
2181
230
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
230
    }
2421
2422
230
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
230
  return true;
2424
230
}
pe-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
700
{
2163
700
  unsigned long machine;
2164
700
  enum bfd_architecture arch;
2165
700
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
700
  machine = 0;
2169
700
  switch (internal_f->f_magic)
2170
700
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
311
    case AMD64MAGIC:
2185
697
    case AMD64_APPLE_MAGIC:
2186
697
    case AMD64_FREEBSD_MAGIC:
2187
697
    case AMD64_LINUX_MAGIC:
2188
700
    case AMD64_NETBSD_MAGIC:
2189
700
      arch = bfd_arch_i386;
2190
700
      machine = bfd_mach_x86_64;
2191
700
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
700
    }
2421
2422
700
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
700
  return true;
2424
700
}
pei-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
251
{
2163
251
  unsigned long machine;
2164
251
  enum bfd_architecture arch;
2165
251
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
251
  machine = 0;
2169
251
  switch (internal_f->f_magic)
2170
251
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
249
    case AMD64MAGIC:
2185
251
    case AMD64_APPLE_MAGIC:
2186
251
    case AMD64_FREEBSD_MAGIC:
2187
251
    case AMD64_LINUX_MAGIC:
2188
251
    case AMD64_NETBSD_MAGIC:
2189
251
      arch = bfd_arch_i386;
2190
251
      machine = bfd_mach_x86_64;
2191
251
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
251
    }
2421
2422
251
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
251
  return true;
2424
251
}
coff-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
598
{
2163
598
  unsigned long machine;
2164
598
  enum bfd_architecture arch;
2165
598
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
598
  machine = 0;
2169
598
  switch (internal_f->f_magic)
2170
598
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
0
#ifdef AMD64MAGIC
2184
291
    case AMD64MAGIC:
2185
597
    case AMD64_APPLE_MAGIC:
2186
597
    case AMD64_FREEBSD_MAGIC:
2187
597
    case AMD64_LINUX_MAGIC:
2188
598
    case AMD64_NETBSD_MAGIC:
2189
598
      arch = bfd_arch_i386;
2190
598
      machine = bfd_mach_x86_64;
2191
598
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
598
    }
2421
2422
598
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
598
  return true;
2424
598
}
coff64-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
212
{
2163
212
  unsigned long machine;
2164
212
  enum bfd_architecture arch;
2165
212
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
212
  machine = 0;
2169
212
  switch (internal_f->f_magic)
2170
212
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
0
#ifdef RS6000COFF_C
2276
0
#ifdef XCOFF64
2277
211
    case U64_TOCMAGIC:
2278
212
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
212
      {
2285
212
  int cputype;
2286
2287
212
  if (xcoff_data (abfd)->cputype != -1)
2288
5
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
207
  else
2290
207
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
207
      if (obj_raw_syment_count (abfd) == 0)
2296
126
        cputype = 0;
2297
81
      else
2298
81
        {
2299
81
    bfd_byte *buf;
2300
81
    struct internal_syment sym;
2301
81
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
81
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
2
      return false;
2305
79
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
79
    if (buf == NULL)
2307
1
      return false;
2308
78
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
78
    if (sym.n_sclass == C_FILE)
2310
1
      cputype = sym.n_type & 0xff;
2311
77
    else
2312
77
      cputype = 0;
2313
78
    free (buf);
2314
78
        }
2315
207
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
209
  switch (cputype)
2319
209
    {
2320
1
    default:
2321
208
    case 0:
2322
208
      arch = bfd_xcoff_architecture (abfd);
2323
208
      machine = bfd_xcoff_machine (abfd);
2324
208
      break;
2325
2326
1
    case 1:
2327
1
      arch = bfd_arch_powerpc;
2328
1
      machine = bfd_mach_ppc_601;
2329
1
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
0
    case 3:
2335
0
      arch = bfd_arch_powerpc;
2336
0
      machine = bfd_mach_ppc;
2337
0
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
209
    }
2343
209
      }
2344
209
      break;
2345
209
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
209
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
212
    }
2421
2422
209
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
209
  return true;
2424
212
}
pe-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
1.81k
{
2163
1.81k
  unsigned long machine;
2164
1.81k
  enum bfd_architecture arch;
2165
1.81k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
1.81k
  machine = 0;
2169
1.81k
  switch (internal_f->f_magic)
2170
1.81k
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
0
#ifdef AARCH64MAGIC
2226
1.81k
    case AARCH64MAGIC:
2227
1.81k
      arch = bfd_arch_aarch64;
2228
1.81k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
1.81k
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
1.81k
    }
2421
2422
1.81k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
1.81k
  return true;
2424
1.81k
}
pei-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
2.96k
{
2163
2.96k
  unsigned long machine;
2164
2.96k
  enum bfd_architecture arch;
2165
2.96k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
2.96k
  machine = 0;
2169
2.96k
  switch (internal_f->f_magic)
2170
2.96k
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
0
#ifdef AARCH64MAGIC
2226
2.96k
    case AARCH64MAGIC:
2227
2.96k
      arch = bfd_arch_aarch64;
2228
2.96k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
2.96k
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
2.96k
    }
2421
2422
2.96k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
2.96k
  return true;
2424
2.96k
}
pei-ia64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
309
{
2163
309
  unsigned long machine;
2164
309
  enum bfd_architecture arch;
2165
309
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
309
  machine = 0;
2169
309
  switch (internal_f->f_magic)
2170
309
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
0
#ifdef IA64MAGIC
2194
309
    case IA64MAGIC:
2195
309
      arch = bfd_arch_ia64;
2196
309
      break;
2197
0
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
309
    }
2421
2422
309
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
309
  return true;
2424
309
}
pei-loongarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
213
{
2163
213
  unsigned long machine;
2164
213
  enum bfd_architecture arch;
2165
213
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
213
  machine = 0;
2169
213
  switch (internal_f->f_magic)
2170
213
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
0
#ifdef LOONGARCH64MAGIC
2232
213
    case LOONGARCH64MAGIC:
2233
213
      arch = bfd_arch_loongarch;
2234
213
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
213
      break;
2236
0
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
213
    }
2421
2422
213
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
213
  return true;
2424
213
}
cf-i386lynx.c:coff_set_arch_mach_hook
Line
Count
Source
2162
203
{
2163
203
  unsigned long machine;
2164
203
  enum bfd_architecture arch;
2165
203
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
203
  machine = 0;
2169
203
  switch (internal_f->f_magic)
2170
203
    {
2171
0
#ifdef I386MAGIC
2172
15
    case I386MAGIC:
2173
87
    case I386PTXMAGIC:
2174
105
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
115
    case LYNXCOFFMAGIC:
2176
130
    case I386_APPLE_MAGIC:
2177
130
    case I386_FREEBSD_MAGIC:
2178
131
    case I386_LINUX_MAGIC:
2179
203
    case I386_NETBSD_MAGIC:
2180
203
      arch = bfd_arch_i386;
2181
203
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
203
    }
2421
2422
203
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
203
  return true;
2424
203
}
coff-go32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
90
{
2163
90
  unsigned long machine;
2164
90
  enum bfd_architecture arch;
2165
90
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
90
  machine = 0;
2169
90
  switch (internal_f->f_magic)
2170
90
    {
2171
0
#ifdef I386MAGIC
2172
15
    case I386MAGIC:
2173
47
    case I386PTXMAGIC:
2174
65
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
75
    case LYNXCOFFMAGIC:
2176
90
    case I386_APPLE_MAGIC:
2177
90
    case I386_FREEBSD_MAGIC:
2178
90
    case I386_LINUX_MAGIC:
2179
90
    case I386_NETBSD_MAGIC:
2180
90
      arch = bfd_arch_i386;
2181
90
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
90
    }
2421
2422
90
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
90
  return true;
2424
90
}
coff-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
90
{
2163
90
  unsigned long machine;
2164
90
  enum bfd_architecture arch;
2165
90
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
90
  machine = 0;
2169
90
  switch (internal_f->f_magic)
2170
90
    {
2171
0
#ifdef I386MAGIC
2172
15
    case I386MAGIC:
2173
47
    case I386PTXMAGIC:
2174
65
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
75
    case LYNXCOFFMAGIC:
2176
90
    case I386_APPLE_MAGIC:
2177
90
    case I386_FREEBSD_MAGIC:
2178
90
    case I386_LINUX_MAGIC:
2179
90
    case I386_NETBSD_MAGIC:
2180
90
      arch = bfd_arch_i386;
2181
90
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
90
    }
2421
2422
90
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
90
  return true;
2424
90
}
coff-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
290
{
2163
290
  unsigned long machine;
2164
290
  enum bfd_architecture arch;
2165
290
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
290
  machine = 0;
2169
290
  switch (internal_f->f_magic)
2170
290
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
0
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
74
    case U802ROMAGIC:
2281
121
    case U802WRMAGIC:
2282
290
    case U802TOCMAGIC:
2283
290
#endif
2284
290
      {
2285
290
  int cputype;
2286
2287
290
  if (xcoff_data (abfd)->cputype != -1)
2288
2
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
288
  else
2290
288
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
288
      if (obj_raw_syment_count (abfd) == 0)
2296
194
        cputype = 0;
2297
94
      else
2298
94
        {
2299
94
    bfd_byte *buf;
2300
94
    struct internal_syment sym;
2301
94
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
94
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
0
      return false;
2305
94
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
94
    if (buf == NULL)
2307
3
      return false;
2308
91
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
91
    if (sym.n_sclass == C_FILE)
2310
1
      cputype = sym.n_type & 0xff;
2311
90
    else
2312
90
      cputype = 0;
2313
91
    free (buf);
2314
91
        }
2315
288
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
287
  switch (cputype)
2319
287
    {
2320
0
    default:
2321
285
    case 0:
2322
285
      arch = bfd_xcoff_architecture (abfd);
2323
285
      machine = bfd_xcoff_machine (abfd);
2324
285
      break;
2325
2326
1
    case 1:
2327
1
      arch = bfd_arch_powerpc;
2328
1
      machine = bfd_mach_ppc_601;
2329
1
      break;
2330
0
    case 2: /* 64 bit PowerPC */
2331
0
      arch = bfd_arch_powerpc;
2332
0
      machine = bfd_mach_ppc_620;
2333
0
      break;
2334
1
    case 3:
2335
1
      arch = bfd_arch_powerpc;
2336
1
      machine = bfd_mach_ppc;
2337
1
      break;
2338
0
    case 4:
2339
0
      arch = bfd_arch_rs6000;
2340
0
      machine = bfd_mach_rs6k;
2341
0
      break;
2342
287
    }
2343
287
      }
2344
287
      break;
2345
287
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
287
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
290
    }
2421
2422
287
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
287
  return true;
2424
290
}
coff-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
149
{
2163
149
  unsigned long machine;
2164
149
  enum bfd_architecture arch;
2165
149
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
149
  machine = 0;
2169
149
  switch (internal_f->f_magic)
2170
149
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
94
    case SH_ARCH_MAGIC_BIG:
2349
95
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
95
      arch = bfd_arch_sh;
2354
95
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
54
    default:      /* Unreadable input file type.  */
2418
54
      arch = bfd_arch_obscure;
2419
54
      break;
2420
149
    }
2421
2422
149
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
149
  return true;
2424
149
}
coff-stgo32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
115
{
2163
115
  unsigned long machine;
2164
115
  enum bfd_architecture arch;
2165
115
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
115
  machine = 0;
2169
115
  switch (internal_f->f_magic)
2170
115
    {
2171
0
#ifdef I386MAGIC
2172
0
    case I386MAGIC:
2173
41
    case I386PTXMAGIC:
2174
41
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
41
    case LYNXCOFFMAGIC:
2176
41
    case I386_APPLE_MAGIC:
2177
41
    case I386_FREEBSD_MAGIC:
2178
42
    case I386_LINUX_MAGIC:
2179
115
    case I386_NETBSD_MAGIC:
2180
115
      arch = bfd_arch_i386;
2181
115
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
115
    }
2421
2422
115
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
115
  return true;
2424
115
}
coff-tic30.c:coff_set_arch_mach_hook
Line
Count
Source
2162
252
{
2163
252
  unsigned long machine;
2164
252
  enum bfd_architecture arch;
2165
252
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
252
  machine = 0;
2169
252
  switch (internal_f->f_magic)
2170
252
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
0
#ifdef TIC30MAGIC
2373
252
    case TIC30MAGIC:
2374
252
      arch = bfd_arch_tic30;
2375
252
      break;
2376
0
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
252
    }
2421
2422
252
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
252
  return true;
2424
252
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach_hook
coff-tic54x.c:coff_set_arch_mach_hook
Line
Count
Source
2162
298
{
2163
298
  unsigned long machine;
2164
298
  enum bfd_architecture arch;
2165
298
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
298
  machine = 0;
2169
298
  switch (internal_f->f_magic)
2170
298
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
0
#ifdef TICOFF0MAGIC
2379
0
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
298
    case TICOFF0MAGIC:
2382
298
      arch = TICOFF_TARGET_ARCH;
2383
298
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
298
      break;
2385
0
#endif
2386
0
#endif
2387
2388
0
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
0
    case TICOFF1MAGIC:
2392
0
    case TICOFF2MAGIC:
2393
0
      switch (internal_f->f_target_id)
2394
0
  {
2395
0
#ifdef TI_TARGET_ID
2396
0
  case TI_TARGET_ID:
2397
0
    arch = TICOFF_TARGET_ARCH;
2398
0
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
0
    break;
2400
0
#endif
2401
0
  default:
2402
0
    arch = bfd_arch_obscure;
2403
0
    _bfd_error_handler
2404
0
      (_("unrecognized TI COFF target id '0x%x'"),
2405
0
       internal_f->f_target_id);
2406
0
    break;
2407
0
  }
2408
0
      break;
2409
0
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
298
    }
2421
2422
298
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
298
  return true;
2424
298
}
coff-z80.c:coff_set_arch_mach_hook
Line
Count
Source
2162
141
{
2163
141
  unsigned long machine;
2164
141
  enum bfd_architecture arch;
2165
141
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
141
  machine = 0;
2169
141
  switch (internal_f->f_magic)
2170
141
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
0
#ifdef Z80MAGIC
2238
141
    case Z80MAGIC:
2239
141
      arch = bfd_arch_z80;
2240
141
      switch (internal_f->f_flags & F_MACHMASK)
2241
141
  {
2242
1
  case bfd_mach_z80strict << 12:
2243
1
  case bfd_mach_z80 << 12:
2244
15
  case bfd_mach_z80n << 12:
2245
33
  case bfd_mach_z80full << 12:
2246
34
  case bfd_mach_r800 << 12:
2247
36
  case bfd_mach_gbz80 << 12:
2248
38
  case bfd_mach_z180 << 12:
2249
46
  case bfd_mach_ez80_z80 << 12:
2250
140
  case bfd_mach_ez80_adl << 12:
2251
140
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
140
    break;
2253
1
  default:
2254
1
    return false;
2255
141
  }
2256
140
      break;
2257
140
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
140
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
141
    }
2421
2422
140
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
140
  return true;
2424
141
}
coff-z8k.c:coff_set_arch_mach_hook
Line
Count
Source
2162
216
{
2163
216
  unsigned long machine;
2164
216
  enum bfd_architecture arch;
2165
216
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
216
  machine = 0;
2169
216
  switch (internal_f->f_magic)
2170
216
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
0
#ifdef Z8KMAGIC
2259
216
    case Z8KMAGIC:
2260
216
      arch = bfd_arch_z8k;
2261
216
      switch (internal_f->f_flags & F_MACHMASK)
2262
216
  {
2263
204
  case F_Z8001:
2264
204
    machine = bfd_mach_z8001;
2265
204
    break;
2266
10
  case F_Z8002:
2267
10
    machine = bfd_mach_z8002;
2268
10
    break;
2269
2
  default:
2270
2
    return false;
2271
216
  }
2272
214
      break;
2273
214
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
214
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
216
    }
2421
2422
214
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
214
  return true;
2424
216
}
pe-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
46
{
2163
46
  unsigned long machine;
2164
46
  enum bfd_architecture arch;
2165
46
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
46
  machine = 0;
2169
46
  switch (internal_f->f_magic)
2170
46
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
22
    case ARMMAGIC:
2200
29
    case ARMPEMAGIC:
2201
31
    case THUMBPEMAGIC:
2202
31
      arch = bfd_arch_arm;
2203
31
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
31
      if (machine == bfd_mach_arm_unknown)
2205
31
  {
2206
31
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
31
      {
2208
1
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
1
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
3
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
16
      default:
2212
16
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
2
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
1
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
7
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
31
      }
2222
31
  }
2223
31
      break;
2224
31
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
31
    default:      /* Unreadable input file type.  */
2418
15
      arch = bfd_arch_obscure;
2419
15
      break;
2420
46
    }
2421
2422
46
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
46
  return true;
2424
46
}
pe-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
46
{
2163
46
  unsigned long machine;
2164
46
  enum bfd_architecture arch;
2165
46
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
46
  machine = 0;
2169
46
  switch (internal_f->f_magic)
2170
46
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
22
    case ARMMAGIC:
2200
29
    case ARMPEMAGIC:
2201
31
    case THUMBPEMAGIC:
2202
31
      arch = bfd_arch_arm;
2203
31
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
31
      if (machine == bfd_mach_arm_unknown)
2205
31
  {
2206
31
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
31
      {
2208
1
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
1
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
3
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
16
      default:
2212
16
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
2
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
1
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
7
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
31
      }
2222
31
  }
2223
31
      break;
2224
31
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
31
    default:      /* Unreadable input file type.  */
2418
15
      arch = bfd_arch_obscure;
2419
15
      break;
2420
46
    }
2421
2422
46
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
46
  return true;
2424
46
}
pe-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
1.74k
{
2163
1.74k
  unsigned long machine;
2164
1.74k
  enum bfd_architecture arch;
2165
1.74k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
1.74k
  machine = 0;
2169
1.74k
  switch (internal_f->f_magic)
2170
1.74k
    {
2171
0
#ifdef I386MAGIC
2172
15
    case I386MAGIC:
2173
114
    case I386PTXMAGIC:
2174
1.63k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
1.64k
    case LYNXCOFFMAGIC:
2176
1.66k
    case I386_APPLE_MAGIC:
2177
1.66k
    case I386_FREEBSD_MAGIC:
2178
1.67k
    case I386_LINUX_MAGIC:
2179
1.74k
    case I386_NETBSD_MAGIC:
2180
1.74k
      arch = bfd_arch_i386;
2181
1.74k
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
1.74k
    }
2421
2422
1.74k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
1.74k
  return true;
2424
1.74k
}
pe-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
140
{
2163
140
  unsigned long machine;
2164
140
  enum bfd_architecture arch;
2165
140
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
140
  machine = 0;
2169
140
  switch (internal_f->f_magic)
2170
140
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
0
#ifdef MCOREMAGIC
2412
140
    case MCOREMAGIC:
2413
140
      arch = bfd_arch_mcore;
2414
140
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
140
    }
2421
2422
140
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
140
  return true;
2424
140
}
pe-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
129
{
2163
129
  unsigned long machine;
2164
129
  enum bfd_architecture arch;
2165
129
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
129
  machine = 0;
2169
129
  switch (internal_f->f_magic)
2170
129
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
19
    case SH_ARCH_MAGIC_BIG:
2349
20
    case SH_ARCH_MAGIC_LITTLE:
2350
20
#ifdef COFF_WITH_PE
2351
129
    case SH_ARCH_MAGIC_WINCE:
2352
129
#endif
2353
129
      arch = bfd_arch_sh;
2354
129
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
129
    }
2421
2422
129
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
129
  return true;
2424
129
}
pei-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
54
{
2163
54
  unsigned long machine;
2164
54
  enum bfd_architecture arch;
2165
54
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
54
  machine = 0;
2169
54
  switch (internal_f->f_magic)
2170
54
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
22
    case ARMMAGIC:
2200
40
    case ARMPEMAGIC:
2201
52
    case THUMBPEMAGIC:
2202
52
      arch = bfd_arch_arm;
2203
52
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
52
      if (machine == bfd_mach_arm_unknown)
2205
52
  {
2206
52
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
52
      {
2208
0
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
0
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
1
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
28
      default:
2212
28
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
0
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
4
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
19
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
52
      }
2222
52
  }
2223
52
      break;
2224
52
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
52
    default:      /* Unreadable input file type.  */
2418
2
      arch = bfd_arch_obscure;
2419
2
      break;
2420
54
    }
2421
2422
54
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
54
  return true;
2424
54
}
pei-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
105
{
2163
105
  unsigned long machine;
2164
105
  enum bfd_architecture arch;
2165
105
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
105
  machine = 0;
2169
105
  switch (internal_f->f_magic)
2170
105
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
0
#ifdef ARMMAGIC
2199
59
    case ARMMAGIC:
2200
77
    case ARMPEMAGIC:
2201
89
    case THUMBPEMAGIC:
2202
89
      arch = bfd_arch_arm;
2203
89
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
89
      if (machine == bfd_mach_arm_unknown)
2205
89
  {
2206
89
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
89
      {
2208
2
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
0
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
1
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
54
      default:
2212
54
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
5
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
6
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
21
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
89
      }
2222
89
  }
2223
89
      break;
2224
89
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
89
    default:      /* Unreadable input file type.  */
2418
16
      arch = bfd_arch_obscure;
2419
16
      break;
2420
105
    }
2421
2422
105
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
105
  return true;
2424
105
}
pei-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
93
{
2163
93
  unsigned long machine;
2164
93
  enum bfd_architecture arch;
2165
93
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
93
  machine = 0;
2169
93
  switch (internal_f->f_magic)
2170
93
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
    case SH_ARCH_MAGIC_BIG:
2349
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
      arch = bfd_arch_sh;
2354
      break;
2355
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
0
#ifdef MCOREMAGIC
2412
93
    case MCOREMAGIC:
2413
93
      arch = bfd_arch_mcore;
2414
93
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
93
    }
2421
2422
93
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
93
  return true;
2424
93
}
pei-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
120
{
2163
120
  unsigned long machine;
2164
120
  enum bfd_architecture arch;
2165
120
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
120
  machine = 0;
2169
120
  switch (internal_f->f_magic)
2170
120
    {
2171
#ifdef I386MAGIC
2172
    case I386MAGIC:
2173
    case I386PTXMAGIC:
2174
    case I386AIXMAGIC:    /* Danbury PS/2 AIX C Compiler.  */
2175
    case LYNXCOFFMAGIC:
2176
    case I386_APPLE_MAGIC:
2177
    case I386_FREEBSD_MAGIC:
2178
    case I386_LINUX_MAGIC:
2179
    case I386_NETBSD_MAGIC:
2180
      arch = bfd_arch_i386;
2181
      break;
2182
#endif
2183
#ifdef AMD64MAGIC
2184
    case AMD64MAGIC:
2185
    case AMD64_APPLE_MAGIC:
2186
    case AMD64_FREEBSD_MAGIC:
2187
    case AMD64_LINUX_MAGIC:
2188
    case AMD64_NETBSD_MAGIC:
2189
      arch = bfd_arch_i386;
2190
      machine = bfd_mach_x86_64;
2191
      break;
2192
#endif
2193
#ifdef IA64MAGIC
2194
    case IA64MAGIC:
2195
      arch = bfd_arch_ia64;
2196
      break;
2197
#endif
2198
#ifdef ARMMAGIC
2199
    case ARMMAGIC:
2200
    case ARMPEMAGIC:
2201
    case THUMBPEMAGIC:
2202
      arch = bfd_arch_arm;
2203
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
      if (machine == bfd_mach_arm_unknown)
2205
  {
2206
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
      {
2208
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
      default:
2212
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
      case F_ARM_4T: machine = bfd_mach_arm_4T; break;
2215
        /* The COFF header does not have enough bits available
2216
     to cover all the different ARM architectures.  So
2217
     we interpret F_ARM_5, the highest flag value to mean
2218
     "the highest ARM architecture known to BFD" which is
2219
     currently the XScale.  */
2220
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
      }
2222
  }
2223
      break;
2224
#endif
2225
#ifdef AARCH64MAGIC
2226
    case AARCH64MAGIC:
2227
      arch = bfd_arch_aarch64;
2228
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
      break;
2230
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
    case LOONGARCH64MAGIC:
2233
      arch = bfd_arch_loongarch;
2234
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
      break;
2236
#endif
2237
#ifdef Z80MAGIC
2238
    case Z80MAGIC:
2239
      arch = bfd_arch_z80;
2240
      switch (internal_f->f_flags & F_MACHMASK)
2241
  {
2242
  case bfd_mach_z80strict << 12:
2243
  case bfd_mach_z80 << 12:
2244
  case bfd_mach_z80n << 12:
2245
  case bfd_mach_z80full << 12:
2246
  case bfd_mach_r800 << 12:
2247
  case bfd_mach_gbz80 << 12:
2248
  case bfd_mach_z180 << 12:
2249
  case bfd_mach_ez80_z80 << 12:
2250
  case bfd_mach_ez80_adl << 12:
2251
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
    break;
2253
  default:
2254
    return false;
2255
  }
2256
      break;
2257
#endif
2258
#ifdef Z8KMAGIC
2259
    case Z8KMAGIC:
2260
      arch = bfd_arch_z8k;
2261
      switch (internal_f->f_flags & F_MACHMASK)
2262
  {
2263
  case F_Z8001:
2264
    machine = bfd_mach_z8001;
2265
    break;
2266
  case F_Z8002:
2267
    machine = bfd_mach_z8002;
2268
    break;
2269
  default:
2270
    return false;
2271
  }
2272
      break;
2273
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
    case U64_TOCMAGIC:
2278
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
      {
2285
  int cputype;
2286
2287
  if (xcoff_data (abfd)->cputype != -1)
2288
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
  else
2290
    {
2291
      /* We did not get a value from the a.out header.  If the
2292
         file has not been stripped, we may be able to get the
2293
         architecture information from the first symbol, if it
2294
         is a .file symbol.  */
2295
      if (obj_raw_syment_count (abfd) == 0)
2296
        cputype = 0;
2297
      else
2298
        {
2299
    bfd_byte *buf;
2300
    struct internal_syment sym;
2301
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
      return false;
2305
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
    if (buf == NULL)
2307
      return false;
2308
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
    if (sym.n_sclass == C_FILE)
2310
      cputype = sym.n_type & 0xff;
2311
    else
2312
      cputype = 0;
2313
    free (buf);
2314
        }
2315
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
  switch (cputype)
2319
    {
2320
    default:
2321
    case 0:
2322
      arch = bfd_xcoff_architecture (abfd);
2323
      machine = bfd_xcoff_machine (abfd);
2324
      break;
2325
2326
    case 1:
2327
      arch = bfd_arch_powerpc;
2328
      machine = bfd_mach_ppc_601;
2329
      break;
2330
    case 2: /* 64 bit PowerPC */
2331
      arch = bfd_arch_powerpc;
2332
      machine = bfd_mach_ppc_620;
2333
      break;
2334
    case 3:
2335
      arch = bfd_arch_powerpc;
2336
      machine = bfd_mach_ppc;
2337
      break;
2338
    case 4:
2339
      arch = bfd_arch_rs6000;
2340
      machine = bfd_mach_rs6k;
2341
      break;
2342
    }
2343
      }
2344
      break;
2345
#endif
2346
2347
0
#ifdef SH_ARCH_MAGIC_BIG
2348
48
    case SH_ARCH_MAGIC_BIG:
2349
48
    case SH_ARCH_MAGIC_LITTLE:
2350
48
#ifdef COFF_WITH_PE
2351
120
    case SH_ARCH_MAGIC_WINCE:
2352
120
#endif
2353
120
      arch = bfd_arch_sh;
2354
120
      break;
2355
0
#endif
2356
2357
#ifdef MIPS_ARCH_MAGIC_WINCE
2358
    case MIPS_ARCH_MAGIC_WINCE:
2359
      arch = bfd_arch_mips;
2360
      break;
2361
#endif
2362
2363
#ifdef SPARCMAGIC
2364
    case SPARCMAGIC:
2365
#ifdef LYNXCOFFMAGIC
2366
    case LYNXCOFFMAGIC:
2367
#endif
2368
      arch = bfd_arch_sparc;
2369
      break;
2370
#endif
2371
2372
#ifdef TIC30MAGIC
2373
    case TIC30MAGIC:
2374
      arch = bfd_arch_tic30;
2375
      break;
2376
#endif
2377
2378
#ifdef TICOFF0MAGIC
2379
#ifdef TICOFF_TARGET_ARCH
2380
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
2381
    case TICOFF0MAGIC:
2382
      arch = TICOFF_TARGET_ARCH;
2383
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
      break;
2385
#endif
2386
#endif
2387
2388
#ifdef TICOFF1MAGIC
2389
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
2390
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
2391
    case TICOFF1MAGIC:
2392
    case TICOFF2MAGIC:
2393
      switch (internal_f->f_target_id)
2394
  {
2395
#ifdef TI_TARGET_ID
2396
  case TI_TARGET_ID:
2397
    arch = TICOFF_TARGET_ARCH;
2398
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
    break;
2400
#endif
2401
  default:
2402
    arch = bfd_arch_obscure;
2403
    _bfd_error_handler
2404
      (_("unrecognized TI COFF target id '0x%x'"),
2405
       internal_f->f_target_id);
2406
    break;
2407
  }
2408
      break;
2409
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
120
    }
2421
2422
120
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
120
  return true;
2424
120
}
2425
2426
static bool
2427
symname_in_debug_hook (bfd *abfd ATTRIBUTE_UNUSED,
2428
           struct internal_syment *sym ATTRIBUTE_UNUSED)
2429
1.26k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
70
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
1.26k
}
pei-i386.c:symname_in_debug_hook
Line
Count
Source
2429
10
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
10
  return false;
2434
10
#endif
2435
10
}
pe-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
15
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
15
  return false;
2434
15
#endif
2435
15
}
pei-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
495
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
495
  return false;
2434
495
#endif
2435
495
}
coff-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
73
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
73
  return false;
2434
73
#endif
2435
73
}
coff64-rs6000.c:symname_in_debug_hook
Line
Count
Source
2429
36
{
2430
36
#ifdef SYMNAME_IN_DEBUG
2431
36
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
36
}
pe-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
15
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
15
  return false;
2434
15
#endif
2435
15
}
pei-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
8
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
8
  return false;
2434
8
#endif
2435
8
}
pei-ia64.c:symname_in_debug_hook
Line
Count
Source
2429
25
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
25
  return false;
2434
25
#endif
2435
25
}
pei-loongarch64.c:symname_in_debug_hook
Line
Count
Source
2429
12
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
12
  return false;
2434
12
#endif
2435
12
}
Unexecuted instantiation: cf-i386lynx.c:symname_in_debug_hook
Unexecuted instantiation: coff-go32.c:symname_in_debug_hook
Unexecuted instantiation: coff-i386.c:symname_in_debug_hook
coff-rs6000.c:symname_in_debug_hook
Line
Count
Source
2429
34
{
2430
34
#ifdef SYMNAME_IN_DEBUG
2431
34
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
34
}
coff-sh.c:symname_in_debug_hook
Line
Count
Source
2429
214
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
214
  return false;
2434
214
#endif
2435
214
}
Unexecuted instantiation: coff-stgo32.c:symname_in_debug_hook
coff-tic30.c:symname_in_debug_hook
Line
Count
Source
2429
13
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
13
  return false;
2434
13
#endif
2435
13
}
Unexecuted instantiation: coff-tic4x.c:symname_in_debug_hook
coff-tic54x.c:symname_in_debug_hook
Line
Count
Source
2429
12
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
12
  return false;
2434
12
#endif
2435
12
}
coff-z80.c:symname_in_debug_hook
Line
Count
Source
2429
122
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
122
  return false;
2434
122
#endif
2435
122
}
coff-z8k.c:symname_in_debug_hook
Line
Count
Source
2429
142
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
142
  return false;
2434
142
#endif
2435
142
}
Unexecuted instantiation: pe-arm-wince.c:symname_in_debug_hook
Unexecuted instantiation: pe-arm.c:symname_in_debug_hook
pe-i386.c:symname_in_debug_hook
Line
Count
Source
2429
4
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
4
  return false;
2434
4
#endif
2435
4
}
pe-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
11
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
11
  return false;
2434
11
#endif
2435
11
}
pe-sh.c:symname_in_debug_hook
Line
Count
Source
2429
18
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
18
  return false;
2434
18
#endif
2435
18
}
Unexecuted instantiation: pei-arm-wince.c:symname_in_debug_hook
Unexecuted instantiation: pei-arm.c:symname_in_debug_hook
pei-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
2
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
2
  return false;
2434
2
#endif
2435
2
}
pei-sh.c:symname_in_debug_hook
Line
Count
Source
2429
8
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
8
  return false;
2434
8
#endif
2435
8
}
2436
2437
#ifdef RS6000COFF_C
2438
2439
#ifdef XCOFF64
2440
#define FORCE_SYMNAMES_IN_STRINGS
2441
#endif
2442
2443
/* Handle the csect auxent of a C_EXT, C_AIX_WEAKEXT or C_HIDEXT symbol.  */
2444
2445
static bool
2446
coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
2447
        combined_entry_type *table_base,
2448
        combined_entry_type *symbol,
2449
        unsigned int indaux,
2450
        combined_entry_type *aux)
2451
641k
{
2452
641k
  BFD_ASSERT (symbol->is_sym);
2453
641k
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
641k
  if (CSECT_SYM_P (n_sclass)
2456
641k
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
53
    {
2458
53
      BFD_ASSERT (! aux->is_sym);
2459
53
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
53
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
0
  {
2462
0
    aux->u.auxent.x_csect.x_scnlen.p =
2463
0
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
0
    aux->fix_scnlen = 1;
2465
0
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
53
      return true;
2470
53
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
641k
  return false;
2475
641k
}
coff64-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
3.79k
{
2452
3.79k
  BFD_ASSERT (symbol->is_sym);
2453
3.79k
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
3.79k
  if (CSECT_SYM_P (n_sclass)
2456
3.79k
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
3
    {
2458
3
      BFD_ASSERT (! aux->is_sym);
2459
3
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
3
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
0
  {
2462
0
    aux->u.auxent.x_csect.x_scnlen.p =
2463
0
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
0
    aux->fix_scnlen = 1;
2465
0
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
3
      return true;
2470
3
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
3.79k
  return false;
2475
3.79k
}
coff-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
638k
{
2452
638k
  BFD_ASSERT (symbol->is_sym);
2453
638k
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
638k
  if (CSECT_SYM_P (n_sclass)
2456
638k
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
50
    {
2458
50
      BFD_ASSERT (! aux->is_sym);
2459
50
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
50
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
0
  {
2462
0
    aux->u.auxent.x_csect.x_scnlen.p =
2463
0
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
0
    aux->fix_scnlen = 1;
2465
0
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
50
      return true;
2470
50
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
638k
  return false;
2475
638k
}
2476
2477
#else
2478
#define coff_pointerize_aux_hook 0
2479
#endif /* ! RS6000COFF_C */
2480
2481
/* Print an aux entry.  This returns TRUE if it has printed it.  */
2482
2483
static bool
2484
coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
2485
    FILE *file ATTRIBUTE_UNUSED,
2486
    combined_entry_type *table_base ATTRIBUTE_UNUSED,
2487
    combined_entry_type *symbol ATTRIBUTE_UNUSED,
2488
    combined_entry_type *aux ATTRIBUTE_UNUSED,
2489
    unsigned int indaux ATTRIBUTE_UNUSED)
2490
0
{
2491
0
  BFD_ASSERT (symbol->is_sym);
2492
0
  BFD_ASSERT (! aux->is_sym);
2493
#ifdef RS6000COFF_C
2494
0
  if (CSECT_SYM_P (symbol->u.syment.n_sclass)
2495
0
      && indaux + 1 == symbol->u.syment.n_numaux)
2496
0
    {
2497
      /* This is a csect entry.  */
2498
0
      fprintf (file, "AUX ");
2499
0
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
2500
0
  {
2501
0
    BFD_ASSERT (! aux->fix_scnlen);
2502
0
    fprintf (file, "val %5" PRIu64,
2503
0
       aux->u.auxent.x_csect.x_scnlen.u64);
2504
0
  }
2505
0
      else
2506
0
  {
2507
0
    fprintf (file, "indx ");
2508
0
    if (! aux->fix_scnlen)
2509
0
      fprintf (file, "%4" PRIu64,
2510
0
         aux->u.auxent.x_csect.x_scnlen.u64);
2511
0
    else
2512
0
      fprintf (file, "%4ld",
2513
0
         (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
2514
0
  }
2515
0
      fprintf (file,
2516
0
         " prmhsh %u snhsh %u typ %d algn %d clss %u stb %u snstb %u",
2517
0
         aux->u.auxent.x_csect.x_parmhash,
2518
0
         (unsigned int) aux->u.auxent.x_csect.x_snhash,
2519
0
         SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
2520
0
         SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
2521
0
         (unsigned int) aux->u.auxent.x_csect.x_smclas,
2522
0
         aux->u.auxent.x_csect.x_stab,
2523
0
         (unsigned int) aux->u.auxent.x_csect.x_snstab);
2524
0
      return true;
2525
0
    }
2526
0
#endif
2527
2528
  /* Return FALSE to indicate that no special action was taken.  */
2529
0
  return false;
2530
0
}
Unexecuted instantiation: pei-i386.c:coff_print_aux
Unexecuted instantiation: pe-x86_64.c:coff_print_aux
Unexecuted instantiation: pei-x86_64.c:coff_print_aux
Unexecuted instantiation: coff-x86_64.c:coff_print_aux
Unexecuted instantiation: coff64-rs6000.c:coff_print_aux
Unexecuted instantiation: pe-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-ia64.c:coff_print_aux
Unexecuted instantiation: pei-loongarch64.c:coff_print_aux
Unexecuted instantiation: cf-i386lynx.c:coff_print_aux
Unexecuted instantiation: coff-go32.c:coff_print_aux
Unexecuted instantiation: coff-i386.c:coff_print_aux
Unexecuted instantiation: coff-rs6000.c:coff_print_aux
Unexecuted instantiation: coff-sh.c:coff_print_aux
Unexecuted instantiation: coff-stgo32.c:coff_print_aux
Unexecuted instantiation: coff-tic30.c:coff_print_aux
Unexecuted instantiation: coff-tic4x.c:coff_print_aux
Unexecuted instantiation: coff-tic54x.c:coff_print_aux
Unexecuted instantiation: coff-z80.c:coff_print_aux
Unexecuted instantiation: coff-z8k.c:coff_print_aux
Unexecuted instantiation: pe-arm-wince.c:coff_print_aux
Unexecuted instantiation: pe-arm.c:coff_print_aux
Unexecuted instantiation: pe-i386.c:coff_print_aux
Unexecuted instantiation: pe-mcore.c:coff_print_aux
Unexecuted instantiation: pe-sh.c:coff_print_aux
Unexecuted instantiation: pei-arm-wince.c:coff_print_aux
Unexecuted instantiation: pei-arm.c:coff_print_aux
Unexecuted instantiation: pei-mcore.c:coff_print_aux
Unexecuted instantiation: pei-sh.c:coff_print_aux
2531
2532
/*
2533
SUBSUBSECTION
2534
  Writing relocations
2535
2536
  To write relocations, the back end steps though the
2537
  canonical relocation table and create an
2538
  @code{internal_reloc}. The symbol index to use is removed from
2539
  the @code{offset} field in the symbol table supplied.  The
2540
  address comes directly from the sum of the section base
2541
  address and the relocation offset; the type is dug directly
2542
  from the howto field.  Then the @code{internal_reloc} is
2543
  swapped into the shape of an @code{external_reloc} and written
2544
  out to disk.
2545
2546
*/
2547
2548
#ifdef TARG_AUX
2549
2550
2551
/* AUX's ld wants relocations to be sorted.  */
2552
static int
2553
compare_arelent_ptr (const void * x, const void * y)
2554
{
2555
  const arelent **a = (const arelent **) x;
2556
  const arelent **b = (const arelent **) y;
2557
  bfd_size_type aadr = (*a)->address;
2558
  bfd_size_type badr = (*b)->address;
2559
2560
  return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2561
}
2562
2563
#endif /* TARG_AUX */
2564
2565
static bool
2566
coff_write_relocs (bfd * abfd, int first_undef)
2567
0
{
2568
0
  asection *s;
2569
2570
0
  for (s = abfd->sections; s != NULL; s = s->next)
2571
0
    {
2572
0
      unsigned int i;
2573
0
      struct external_reloc dst;
2574
0
      arelent **p;
2575
2576
0
#ifndef TARG_AUX
2577
0
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
0
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
0
#endif
2617
2618
0
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
0
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
0
    n.r_offset = q->addend;
2693
0
#endif
2694
2695
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
0
    if (q->howto)
2701
0
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
0
    }
2714
2715
0
  return true;
2716
0
}
Unexecuted instantiation: pei-i386.c:coff_write_relocs
Unexecuted instantiation: pe-x86_64.c:coff_write_relocs
Unexecuted instantiation: pei-x86_64.c:coff_write_relocs
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
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
2717
2718
/* Set flags and magic number of a coff file from architecture and machine
2719
   type.  Result is TRUE if we can represent the arch&type, FALSE if not.  */
2720
2721
static bool
2722
coff_set_flags (bfd * abfd,
2723
    unsigned int *magicp ATTRIBUTE_UNUSED,
2724
    unsigned short *flagsp ATTRIBUTE_UNUSED)
2725
0
{
2726
0
  switch (bfd_get_arch (abfd))
2727
0
    {
2728
#ifdef Z80MAGIC
2729
0
    case bfd_arch_z80:
2730
0
      *magicp = Z80MAGIC;
2731
0
      switch (bfd_get_mach (abfd))
2732
0
  {
2733
0
  case bfd_mach_z80strict:
2734
0
  case bfd_mach_z80:
2735
0
  case bfd_mach_z80n:
2736
0
  case bfd_mach_z80full:
2737
0
  case bfd_mach_r800:
2738
0
  case bfd_mach_gbz80:
2739
0
  case bfd_mach_z180:
2740
0
  case bfd_mach_ez80_z80:
2741
0
  case bfd_mach_ez80_adl:
2742
0
    *flagsp = bfd_get_mach (abfd) << 12;
2743
0
    break;
2744
0
  default:
2745
0
    return false;
2746
0
  }
2747
0
      return true;
2748
0
#endif
2749
2750
#ifdef Z8KMAGIC
2751
0
    case bfd_arch_z8k:
2752
0
      *magicp = Z8KMAGIC;
2753
2754
0
      switch (bfd_get_mach (abfd))
2755
0
  {
2756
0
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
0
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
0
  default:       return false;
2759
0
  }
2760
0
      return true;
2761
0
#endif
2762
2763
#ifdef TIC30MAGIC
2764
0
    case bfd_arch_tic30:
2765
0
      *magicp = TIC30MAGIC;
2766
0
      return true;
2767
0
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
0
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
0
      if (!abfd->xvec )
2773
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
0
      else
2775
0
  {
2776
    /* We may want to output in a different COFF version.  */
2777
0
    switch (abfd->xvec->name[4])
2778
0
      {
2779
0
      case '0':
2780
0
        *magicp = TICOFF0MAGIC;
2781
0
        break;
2782
0
      case '1':
2783
0
        *magicp = TICOFF1MAGIC;
2784
0
        break;
2785
0
      case '2':
2786
0
        *magicp = TICOFF2MAGIC;
2787
0
        break;
2788
0
      default:
2789
0
        return false;
2790
0
      }
2791
0
  }
2792
0
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
0
      return true;
2794
0
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
0
    case bfd_arch_aarch64:
2798
0
      * magicp = AARCH64MAGIC;
2799
0
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
0
    case bfd_arch_loongarch:
2804
0
      * magicp = LOONGARCH64MAGIC;
2805
0
      return true;
2806
0
#endif
2807
2808
#ifdef ARMMAGIC
2809
0
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
0
      * magicp = ARMMAGIC;
2814
0
#endif
2815
0
      * flagsp = 0;
2816
0
      if (APCS_SET (abfd))
2817
0
  {
2818
0
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
0
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
0
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
0
  }
2827
0
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
0
      switch (bfd_get_mach (abfd))
2830
0
  {
2831
0
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
0
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
0
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
0
  }
2844
0
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
0
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
0
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
0
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
0
      *magicp = AMD64MAGIC;
2858
#endif
2859
0
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
0
    case bfd_arch_ia64:
2864
0
      *magicp = IA64MAGIC;
2865
0
      return true;
2866
0
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
0
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
0
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
0
      if (bfd_big_endian (abfd))
2874
0
  *magicp = SH_ARCH_MAGIC_BIG;
2875
0
      else
2876
0
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
0
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
0
    case bfd_arch_rs6000:
2899
0
    case bfd_arch_powerpc:
2900
0
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
0
      *magicp = bfd_xcoff_magic_number (abfd);
2902
0
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
0
    case bfd_arch_mcore:
2907
0
      * magicp = MCOREMAGIC;
2908
0
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
0
    }
2914
2915
0
  return false;
2916
0
}
Unexecuted instantiation: pei-i386.c:coff_set_flags
Unexecuted instantiation: pe-x86_64.c:coff_set_flags
Unexecuted instantiation: pei-x86_64.c:coff_set_flags
Unexecuted instantiation: coff-x86_64.c:coff_set_flags
Unexecuted instantiation: coff64-rs6000.c:coff_set_flags
Unexecuted instantiation: pe-aarch64.c:coff_set_flags
Unexecuted instantiation: pei-aarch64.c:coff_set_flags
Unexecuted instantiation: pei-ia64.c:coff_set_flags
Unexecuted instantiation: pei-loongarch64.c:coff_set_flags
Unexecuted instantiation: cf-i386lynx.c:coff_set_flags
Unexecuted instantiation: coff-go32.c:coff_set_flags
Unexecuted instantiation: coff-i386.c:coff_set_flags
Unexecuted instantiation: coff-rs6000.c:coff_set_flags
Unexecuted instantiation: coff-sh.c:coff_set_flags
Unexecuted instantiation: coff-stgo32.c:coff_set_flags
Unexecuted instantiation: coff-tic30.c:coff_set_flags
Unexecuted instantiation: coff-tic4x.c:coff_set_flags
Unexecuted instantiation: coff-tic54x.c:coff_set_flags
Unexecuted instantiation: coff-z80.c:coff_set_flags
Unexecuted instantiation: coff-z8k.c:coff_set_flags
Unexecuted instantiation: pe-arm-wince.c:coff_set_flags
Unexecuted instantiation: pe-arm.c:coff_set_flags
Unexecuted instantiation: pe-i386.c:coff_set_flags
Unexecuted instantiation: pe-mcore.c:coff_set_flags
Unexecuted instantiation: pe-sh.c:coff_set_flags
Unexecuted instantiation: pei-arm-wince.c:coff_set_flags
Unexecuted instantiation: pei-arm.c:coff_set_flags
Unexecuted instantiation: pei-mcore.c:coff_set_flags
Unexecuted instantiation: pei-sh.c:coff_set_flags
2917
2918
static bool
2919
coff_set_arch_mach (bfd * abfd,
2920
        enum bfd_architecture arch,
2921
        unsigned long machine)
2922
0
{
2923
0
  unsigned dummy1;
2924
0
  unsigned short dummy2;
2925
2926
0
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
0
  if (arch != bfd_arch_unknown
2930
0
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
0
  return true;     /* We're easy...  */
2934
0
}
Unexecuted instantiation: pei-i386.c:coff_set_arch_mach
Unexecuted instantiation: pe-x86_64.c:coff_set_arch_mach
Unexecuted instantiation: pei-x86_64.c:coff_set_arch_mach
Unexecuted instantiation: coff-x86_64.c:coff_set_arch_mach
Unexecuted instantiation: coff64-rs6000.c:coff_set_arch_mach
Unexecuted instantiation: pe-aarch64.c:coff_set_arch_mach
Unexecuted instantiation: pei-aarch64.c:coff_set_arch_mach
Unexecuted instantiation: pei-ia64.c:coff_set_arch_mach
Unexecuted instantiation: pei-loongarch64.c:coff_set_arch_mach
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
Unexecuted instantiation: coff-rs6000.c:coff_set_arch_mach
Unexecuted instantiation: coff-sh.c:coff_set_arch_mach
Unexecuted instantiation: coff-stgo32.c:coff_set_arch_mach
Unexecuted instantiation: coff-tic30.c:coff_set_arch_mach
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach
Unexecuted instantiation: coff-tic54x.c:coff_set_arch_mach
Unexecuted instantiation: coff-z80.c:coff_set_arch_mach
Unexecuted instantiation: coff-z8k.c:coff_set_arch_mach
Unexecuted instantiation: pe-arm-wince.c:coff_set_arch_mach
Unexecuted instantiation: pe-arm.c:coff_set_arch_mach
Unexecuted instantiation: pe-i386.c:coff_set_arch_mach
Unexecuted instantiation: pe-mcore.c:coff_set_arch_mach
Unexecuted instantiation: pe-sh.c:coff_set_arch_mach
Unexecuted instantiation: pei-arm-wince.c:coff_set_arch_mach
Unexecuted instantiation: pei-arm.c:coff_set_arch_mach
Unexecuted instantiation: pei-mcore.c:coff_set_arch_mach
Unexecuted instantiation: pei-sh.c:coff_set_arch_mach
2935
2936
#ifdef COFF_IMAGE_WITH_PE
2937
2938
/* This is used to sort sections by VMA, as required by PE image
2939
   files.  */
2940
2941
static int
2942
sort_by_secaddr (const void * arg1, const void * arg2)
2943
0
{
2944
0
  const asection *a = *(const asection **) arg1;
2945
0
  const asection *b = *(const asection **) arg2;
2946
2947
0
  if (a->vma < b->vma)
2948
0
    return -1;
2949
0
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
0
  return 0;
2953
0
}
Unexecuted instantiation: pei-i386.c:sort_by_secaddr
Unexecuted instantiation: pei-x86_64.c:sort_by_secaddr
Unexecuted instantiation: pei-aarch64.c:sort_by_secaddr
Unexecuted instantiation: pei-ia64.c:sort_by_secaddr
Unexecuted instantiation: pei-loongarch64.c:sort_by_secaddr
Unexecuted instantiation: pei-arm-wince.c:sort_by_secaddr
Unexecuted instantiation: pei-arm.c:sort_by_secaddr
Unexecuted instantiation: pei-mcore.c:sort_by_secaddr
Unexecuted instantiation: pei-sh.c:sort_by_secaddr
2954
2955
#endif /* COFF_IMAGE_WITH_PE */
2956
2957
/* Calculate the file position for each section.  */
2958
2959
#define ALIGN_SECTIONS_IN_FILE
2960
#ifdef TICOFF
2961
#undef ALIGN_SECTIONS_IN_FILE
2962
#endif
2963
2964
static bool
2965
coff_compute_section_file_positions (bfd * abfd)
2966
0
{
2967
0
  asection *current;
2968
0
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
0
  bool align_adjust;
2970
0
  unsigned int target_index;
2971
#ifdef ALIGN_SECTIONS_IN_FILE
2972
  asection *previous = NULL;
2973
  file_ptr old_sofar;
2974
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
0
  if (coff_data (abfd)->link_info
2980
0
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
0
    {
2982
0
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
0
      if (page_size == 0)
2987
0
  page_size = 1;
2988
0
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
0
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
0
  if (bfd_get_symcount (abfd) > 0)
3000
0
    {
3001
0
      bfd_size_type sz;
3002
0
      bfd_size_type i, symcount;
3003
0
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
0
  {
3009
0
    coff_symbol_type *cf;
3010
3011
0
    cf = coff_symbol_from (*symp);
3012
0
    if (cf != NULL
3013
0
        && cf->native != NULL
3014
0
        && cf->native->is_sym
3015
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
0
      {
3017
0
        size_t len;
3018
3019
0
        len = strlen (bfd_asymbol_name (*symp));
3020
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
0
      }
3023
0
  }
3024
0
      if (sz > 0)
3025
0
  {
3026
0
    asection *dsec;
3027
3028
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
0
    if (dsec == NULL)
3030
0
      abort ();
3031
0
    dsec->size = sz;
3032
0
    dsec->flags |= SEC_HAS_CONTENTS;
3033
0
  }
3034
0
    }
3035
0
#endif
3036
3037
0
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
0
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
0
  else if (xcoff_data (abfd)->full_aouthdr)
3046
0
    sofar += bfd_coff_aoutsz (abfd);
3047
0
  else
3048
0
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
0
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
0
  for (current = abfd->sections; current != NULL; current = current->next)
3057
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
0
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
0
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
0
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
0
       || page_size < COFF_PAGE_SIZE)
3082
0
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
0
    for (current = abfd->sections; current != NULL; current = current->next)
3087
0
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
0
    if (section_list == NULL)
3093
0
      return false;
3094
3095
0
    i = 0;
3096
0
    for (current = abfd->sections; current != NULL; current = current->next)
3097
0
      {
3098
0
  section_list[i] = current;
3099
0
  ++i;
3100
0
      }
3101
0
    section_list[i] = NULL;
3102
3103
0
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
0
    target_index = 1;
3108
0
    abfd->sections = NULL;
3109
0
    abfd->section_last = NULL;
3110
0
    for (i = 0; i < count; i++)
3111
0
      {
3112
0
  current = section_list[i];
3113
0
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
0
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
0
  else
3130
0
    current->target_index = target_index++;
3131
0
      }
3132
3133
0
    free (section_list);
3134
0
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
0
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
0
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
0
  align_adjust = false;
3154
0
  for (current = abfd->sections;
3155
0
       current != NULL;
3156
0
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
0
      if (coff_section_data (abfd, current) == NULL)
3162
0
  {
3163
0
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
0
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
0
  }
3169
0
      if (pei_section_data (abfd, current) == NULL)
3170
0
  {
3171
0
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
0
  }
3177
0
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
0
  pei_section_data (abfd, current)->virt_size = current->size;
3179
0
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
0
      if (current->size == 0)
3190
0
  continue;
3191
0
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
0
    if ((current->flags & SEC_LOAD) != 0
3232
0
        && (!strcmp (current->name, _TEXT)
3233
0
      || !strcmp (current->name, _DATA))
3234
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
0
      {
3236
0
        bfd_vma align = 4096;
3237
0
        bfd_vma sofar_off = sofar % align;
3238
0
        bfd_vma vma_off = current->vma % align;
3239
3240
0
        if (vma_off > sofar_off)
3241
0
    sofar += vma_off - sofar_off;
3242
0
        else if (vma_off < sofar_off)
3243
0
    sofar += align + vma_off - sofar_off;
3244
0
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
0
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
0
  align_adjust = true;
3300
#endif
3301
3302
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
#endif
3309
3310
#ifdef ALIGN_SECTIONS_IN_FILE
3311
      previous = current;
3312
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
0
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
0
  sofar = BFD_ALIGN (sofar,
3334
0
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
0
  obj_relocbase (abfd) = sofar;
3337
0
  abfd->output_has_begun = true;
3338
3339
0
  return true;
3340
0
}
Unexecuted instantiation: pei-i386.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-x86_64.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-x86_64.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-x86_64.c:coff_compute_section_file_positions
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
Unexecuted instantiation: pei-ia64.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-loongarch64.c:coff_compute_section_file_positions
Unexecuted instantiation: cf-i386lynx.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-go32.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-i386.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-rs6000.c:coff_compute_section_file_positions
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
Unexecuted instantiation: pei-arm-wince.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-mcore.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-sh.c:coff_compute_section_file_positions
3341
3342
#ifdef COFF_IMAGE_WITH_PE
3343
3344
static bool
3345
coff_read_word (bfd *abfd, unsigned int *value, unsigned int *pelength)
3346
0
{
3347
0
  unsigned char b[2];
3348
0
  int status;
3349
3350
0
  status = bfd_read (b, 2, abfd);
3351
0
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
0
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
0
  else
3360
0
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
0
  *pelength += status;
3363
3364
0
  return true;
3365
0
}
Unexecuted instantiation: pei-i386.c:coff_read_word
Unexecuted instantiation: pei-x86_64.c:coff_read_word
Unexecuted instantiation: pei-aarch64.c:coff_read_word
Unexecuted instantiation: pei-ia64.c:coff_read_word
Unexecuted instantiation: pei-loongarch64.c:coff_read_word
Unexecuted instantiation: pei-arm-wince.c:coff_read_word
Unexecuted instantiation: pei-arm.c:coff_read_word
Unexecuted instantiation: pei-mcore.c:coff_read_word
Unexecuted instantiation: pei-sh.c:coff_read_word
3366
3367
/* Read a two byte number from buffer B returning the result in VALUE.
3368
   No more than BUF_SIZE bytes will be read.
3369
   Returns true upobn success, false otherwise.
3370
   If successful, increases the value stored in PELENGTH by the number
3371
   of bytes read.  */
3372
3373
static bool
3374
coff_read_word_from_buffer (unsigned char *  b,
3375
          int              buf_size,
3376
                            unsigned int *   value,
3377
          unsigned int *   pelength)
3378
0
{
3379
0
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
0
  if (buf_size == 1)
3386
0
    {
3387
0
      *value = (unsigned int)b[0];
3388
0
      *pelength += 1;
3389
0
    }
3390
0
  else
3391
0
    {
3392
0
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
0
      *pelength += 2;
3394
0
    }
3395
3396
0
  return true;
3397
0
}
Unexecuted instantiation: pei-i386.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-x86_64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-aarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-ia64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-loongarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm-wince.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-mcore.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-sh.c:coff_read_word_from_buffer
3398
3399
0
#define COFF_CHECKSUM_BUFFER_SIZE 0x800000
3400
3401
static unsigned int
3402
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
3403
0
{
3404
0
  file_ptr filepos;
3405
0
  unsigned int value;
3406
0
  unsigned int total;
3407
0
  unsigned char *buf;
3408
0
  int buf_size;
3409
3410
0
  total = 0;
3411
0
  *pelength = 0;
3412
0
  filepos = (file_ptr) 0;
3413
0
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
0
  if (buf == NULL)
3415
0
    return 0;
3416
0
  buf_size = 0;
3417
3418
0
  do
3419
0
    {
3420
0
      unsigned char *cur_buf;
3421
0
      int cur_buf_size;
3422
3423
0
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
0
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
0
      cur_buf_size = buf_size;
3428
0
      cur_buf = buf;
3429
3430
0
      while (cur_buf_size > 0)
3431
0
        {
3432
0
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
0
          cur_buf += 2;
3434
0
          cur_buf_size -= 2;
3435
0
          total += value;
3436
0
          total = 0xffff & (total + (total >> 0x10));
3437
0
        }
3438
3439
0
      filepos += buf_size;
3440
0
    }
3441
0
  while (buf_size > 0);
3442
3443
0
  free (buf);
3444
3445
0
  return (0xffff & (total + (total >> 0x10)));
3446
0
}
Unexecuted instantiation: pei-i386.c:coff_compute_checksum
Unexecuted instantiation: pei-x86_64.c:coff_compute_checksum
Unexecuted instantiation: pei-aarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-ia64.c:coff_compute_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_compute_checksum
Unexecuted instantiation: pei-arm.c:coff_compute_checksum
Unexecuted instantiation: pei-mcore.c:coff_compute_checksum
Unexecuted instantiation: pei-sh.c:coff_compute_checksum
3447
3448
static bool
3449
coff_apply_checksum (bfd *abfd)
3450
0
{
3451
0
  unsigned int computed;
3452
0
  unsigned int checksum = 0;
3453
0
  unsigned int peheader;
3454
0
  unsigned int pelength;
3455
3456
0
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
0
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
0
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
0
  checksum = 0;
3466
0
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
0
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
0
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
0
  checksum = computed + pelength;
3475
3476
0
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
0
  return bfd_write (&checksum, 4, abfd) == 4;
3480
0
}
Unexecuted instantiation: pei-i386.c:coff_apply_checksum
Unexecuted instantiation: pei-x86_64.c:coff_apply_checksum
Unexecuted instantiation: pei-aarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-ia64.c:coff_apply_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_apply_checksum
Unexecuted instantiation: pei-arm.c:coff_apply_checksum
Unexecuted instantiation: pei-mcore.c:coff_apply_checksum
Unexecuted instantiation: pei-sh.c:coff_apply_checksum
3481
3482
#endif /* COFF_IMAGE_WITH_PE */
3483
3484
static bool
3485
coff_write_object_contents (bfd * abfd)
3486
0
{
3487
0
  asection *current;
3488
0
  bool hasrelocs = false;
3489
0
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
0
  file_ptr scn_base;
3494
0
  file_ptr reloc_base;
3495
0
  file_ptr lineno_base;
3496
0
  file_ptr sym_base;
3497
0
  unsigned long reloc_size = 0, reloc_count = 0;
3498
0
  unsigned long lnno_size = 0;
3499
0
  bool long_section_names;
3500
0
  asection *text_sec = NULL;
3501
0
  asection *data_sec = NULL;
3502
0
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
0
  struct internal_filehdr internal_f;
3508
0
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
0
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
0
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
0
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
0
  if (! abfd->output_has_begun)
3520
0
    {
3521
0
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
0
    }
3524
3525
0
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
0
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
0
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
0
  lineno_base = reloc_base + reloc_size;
3543
0
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
0
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
0
  internal_f.f_nscns = 0;
3574
3575
0
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
0
      if (xcoff_data (abfd)->full_aouthdr)
3583
0
  scn_base += bfd_coff_aoutsz (abfd);
3584
0
      else
3585
0
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
0
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
0
  long_section_names = false;
3594
0
  for (current = abfd->sections;
3595
0
       current != NULL;
3596
0
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
0
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
0
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
0
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
0
#endif
3687
3688
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
0
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
      section.s_page = 0;
3702
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
0
      if (coff_section_data (abfd, current) != NULL
3710
0
    && pei_section_data (abfd, current) != NULL)
3711
0
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
0
      if ((current->flags & SEC_DEBUGGING) != 0
3737
0
    && ! is_reloc_section)
3738
0
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
0
  {
3746
0
    section.s_nreloc = 0xffff;
3747
0
    section.s_nlnno = 0xffff;
3748
0
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
0
      else if (!strcmp (current->name, _TDATA))
3762
0
  tdata_sec = current;
3763
0
      else if (!strcmp (current->name, _TBSS))
3764
0
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
0
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
0
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
0
      else
3798
0
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
0
  for (current = abfd->sections; current != NULL; current = current->next)
3910
0
    {
3911
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
0
  {
3913
0
    struct internal_scnhdr scnhdr;
3914
0
    SCNHDR buff;
3915
0
    bfd_size_type amt;
3916
3917
0
    internal_f.f_nscns++;
3918
0
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
0
    scnhdr.s_paddr = current->reloc_count;
3920
0
    scnhdr.s_vaddr = current->lineno_count;
3921
0
    scnhdr.s_size = 0;
3922
0
    scnhdr.s_scnptr = 0;
3923
0
    scnhdr.s_relptr = current->rel_filepos;
3924
0
    scnhdr.s_lnnoptr = current->line_filepos;
3925
0
    scnhdr.s_nreloc = current->target_index;
3926
0
    scnhdr.s_nlnno = current->target_index;
3927
0
    scnhdr.s_flags = STYP_OVRFLO;
3928
0
    amt = bfd_coff_scnhsz (abfd);
3929
0
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
0
        || bfd_write (& buff, amt, abfd) != amt)
3931
0
      return false;
3932
0
  }
3933
0
    }
3934
0
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
0
  if ((abfd->flags & EXEC_P) != 0)
3940
0
    {
3941
0
      asection *s = abfd->sections;
3942
0
      while (s != NULL && s->filepos == 0)
3943
0
  s = s->next;
3944
0
      if (s != NULL)
3945
0
  {
3946
0
    file_ptr cur_ptr
3947
0
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
0
    file_ptr fill_size = s->filepos - cur_ptr;
3949
0
    if (fill_size > 0)
3950
0
      {
3951
0
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
0
        if (!b)
3953
0
    return false;
3954
0
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
0
    {
3956
0
      free (b);
3957
0
      return false;
3958
0
    }
3959
0
        free (b);
3960
0
      }
3961
0
  }
3962
0
    }
3963
0
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
0
  internal_f.f_timdat = 0;
3974
0
  internal_f.f_flags = 0;
3975
3976
0
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
0
      if (xcoff_data (abfd)->full_aouthdr)
3984
0
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
0
      else
3986
0
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
0
  if (!hasrelocs)
3992
0
    internal_f.f_flags |= F_RELFLG;
3993
0
  if (!haslinno)
3994
0
    internal_f.f_flags |= F_LNNO;
3995
0
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
0
  if (! hasdebug)
3999
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
0
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
0
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
0
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
0
  else
4011
0
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
0
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
0
  if ((abfd->flags & DYNAMIC) != 0)
4026
0
    internal_f.f_flags |= F_SHROBJ;
4027
0
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
0
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
0
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
0
  {
4035
0
    unsigned int magic = 0;
4036
0
    unsigned short flags = 0;
4037
4038
0
    coff_set_flags (abfd, &magic, &flags);
4039
0
    internal_f.f_magic = magic;
4040
0
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
0
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
0
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
0
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
0
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
0
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
0
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
0
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
0
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
0
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
0
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
0
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
0
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
0
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
0
#undef __A_MAGIC_SET__
4112
0
#endif
4113
0
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
  internal_a.vstamp = 0;
4121
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
0
  obj_sym_filepos (abfd) = sym_base;
4125
4126
0
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
0
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
0
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
0
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
0
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
0
  else
4162
0
    {
4163
0
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
0
      else
4166
0
  internal_f.f_symptr = 0;
4167
0
      internal_f.f_flags |= F_LSYMS;
4168
0
    }
4169
4170
0
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
0
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
0
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
0
  internal_a.entry = bfd_get_start_address (abfd);
4188
0
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
0
  if (xcoff_data (abfd)->full_aouthdr)
4192
0
    {
4193
0
      bfd_vma toc;
4194
0
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
0
      if (internal_a.o_snentry == 0)
4200
0
  internal_a.entry = (bfd_vma) -1;
4201
4202
0
      if (text_sec != NULL)
4203
0
  {
4204
0
    internal_a.o_sntext = text_sec->target_index;
4205
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
0
  }
4207
0
      else
4208
0
  {
4209
0
    internal_a.o_sntext = 0;
4210
0
    internal_a.o_algntext = 0;
4211
0
  }
4212
0
      if (data_sec != NULL)
4213
0
  {
4214
0
    internal_a.o_sndata = data_sec->target_index;
4215
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
0
  }
4217
0
      else
4218
0
  {
4219
0
    internal_a.o_sndata = 0;
4220
0
    internal_a.o_algndata = 0;
4221
0
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
0
      if (loader_sec != NULL)
4224
0
  internal_a.o_snloader = loader_sec->target_index;
4225
0
      else
4226
0
  internal_a.o_snloader = 0;
4227
0
      if (bss_sec != NULL)
4228
0
  internal_a.o_snbss = bss_sec->target_index;
4229
0
      else
4230
0
  internal_a.o_snbss = 0;
4231
4232
0
      if (tdata_sec != NULL)
4233
0
  {
4234
0
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
0
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
0
  }
4242
0
      else
4243
0
  {
4244
0
    internal_a.o_sntdata = 0;
4245
0
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
0
  }
4250
0
      if (tbss_sec != NULL)
4251
0
    internal_a.o_sntbss = tbss_sec->target_index;
4252
0
      else
4253
0
    internal_a.o_sntbss = 0;
4254
4255
0
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
0
      if (xcoff_data (abfd)->cputype != -1)
4261
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
0
      else
4263
0
  {
4264
0
    switch (bfd_get_arch (abfd))
4265
0
      {
4266
0
      case bfd_arch_rs6000:
4267
0
        internal_a.o_cputype = 4;
4268
0
        break;
4269
0
      case bfd_arch_powerpc:
4270
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
0
    internal_a.o_cputype = 3;
4272
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
0
    internal_a.o_cputype = 2;
4274
0
        else
4275
0
    internal_a.o_cputype = 1;
4276
0
        break;
4277
0
      default:
4278
0
        abort ();
4279
0
      }
4280
0
  }
4281
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
0
    }
4284
0
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
0
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
0
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
0
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
0
  {
4302
0
    char * buff;
4303
0
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
0
    buff = (char *) bfd_malloc (amount);
4306
0
    if (buff == NULL)
4307
0
      return false;
4308
4309
0
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
0
    amount = bfd_write (buff, amount, abfd);
4311
4312
0
    free (buff);
4313
4314
0
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
0
  }
4317
4318
0
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
0
    {
4346
0
      AOUTHDR buff;
4347
0
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
0
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
0
      if (xcoff_data (abfd)->full_aouthdr)
4352
0
  size = bfd_coff_aoutsz (abfd);
4353
0
      else
4354
0
  size = SMALL_AOUTSZ;
4355
0
      if (bfd_write (&buff, size, abfd) != size)
4356
0
  return false;
4357
0
    }
4358
0
#endif
4359
#endif
4360
4361
0
  return true;
4362
0
}
Unexecuted instantiation: pei-i386.c:coff_write_object_contents
Unexecuted instantiation: pe-x86_64.c:coff_write_object_contents
Unexecuted instantiation: pei-x86_64.c:coff_write_object_contents
Unexecuted instantiation: coff-x86_64.c:coff_write_object_contents
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
Unexecuted instantiation: pei-ia64.c:coff_write_object_contents
Unexecuted instantiation: pei-loongarch64.c:coff_write_object_contents
Unexecuted instantiation: cf-i386lynx.c:coff_write_object_contents
Unexecuted instantiation: coff-go32.c:coff_write_object_contents
Unexecuted instantiation: coff-i386.c:coff_write_object_contents
Unexecuted instantiation: coff-rs6000.c:coff_write_object_contents
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
Unexecuted instantiation: pei-arm-wince.c:coff_write_object_contents
Unexecuted instantiation: pei-arm.c:coff_write_object_contents
Unexecuted instantiation: pei-mcore.c:coff_write_object_contents
Unexecuted instantiation: pei-sh.c:coff_write_object_contents
4363
4364
static bool
4365
coff_set_section_contents (bfd * abfd,
4366
         sec_ptr section,
4367
         const void * location,
4368
         file_ptr offset,
4369
         bfd_size_type count)
4370
0
{
4371
0
  if (! abfd->output_has_begun) /* Set by bfd.c handler.  */
4372
0
    {
4373
0
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
0
    }
4376
4377
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
0
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
  rec = (bfd_byte *) location;
4403
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
0
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
0
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
0
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
0
  if (count == 0)
4426
0
    return true;
4427
4428
0
  return bfd_write (location, count, abfd) == count;
4429
0
}
Unexecuted instantiation: pei-i386.c:coff_set_section_contents
Unexecuted instantiation: pe-x86_64.c:coff_set_section_contents
Unexecuted instantiation: pei-x86_64.c:coff_set_section_contents
Unexecuted instantiation: coff-x86_64.c:coff_set_section_contents
Unexecuted instantiation: coff64-rs6000.c:coff_set_section_contents
Unexecuted instantiation: pe-aarch64.c:coff_set_section_contents
Unexecuted instantiation: pei-aarch64.c:coff_set_section_contents
Unexecuted instantiation: pei-ia64.c:coff_set_section_contents
Unexecuted instantiation: pei-loongarch64.c:coff_set_section_contents
Unexecuted instantiation: cf-i386lynx.c:coff_set_section_contents
Unexecuted instantiation: coff-go32.c:coff_set_section_contents
Unexecuted instantiation: coff-i386.c:coff_set_section_contents
Unexecuted instantiation: coff-rs6000.c:coff_set_section_contents
Unexecuted instantiation: coff-sh.c:coff_set_section_contents
Unexecuted instantiation: coff-stgo32.c:coff_set_section_contents
Unexecuted instantiation: coff-tic30.c:coff_set_section_contents
Unexecuted instantiation: coff-tic4x.c:coff_set_section_contents
Unexecuted instantiation: coff-tic54x.c:coff_set_section_contents
Unexecuted instantiation: coff-z80.c:coff_set_section_contents
Unexecuted instantiation: coff-z8k.c:coff_set_section_contents
Unexecuted instantiation: pe-arm-wince.c:coff_set_section_contents
Unexecuted instantiation: pe-arm.c:coff_set_section_contents
Unexecuted instantiation: pe-i386.c:coff_set_section_contents
Unexecuted instantiation: pe-mcore.c:coff_set_section_contents
Unexecuted instantiation: pe-sh.c:coff_set_section_contents
Unexecuted instantiation: pei-arm-wince.c:coff_set_section_contents
Unexecuted instantiation: pei-arm.c:coff_set_section_contents
Unexecuted instantiation: pei-mcore.c:coff_set_section_contents
Unexecuted instantiation: pei-sh.c:coff_set_section_contents
4430
4431
static void *
4432
buy_and_read (bfd *abfd, file_ptr where,
4433
        bfd_size_type nmemb, bfd_size_type size)
4434
11.6k
{
4435
11.6k
  size_t amt;
4436
4437
11.6k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
11.6k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
52
    return NULL;
4444
11.5k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
11.6k
}
pei-i386.c:buy_and_read
Line
Count
Source
4434
8
{
4435
8
  size_t amt;
4436
4437
8
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
8
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
8
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
8
}
pe-x86_64.c:buy_and_read
Line
Count
Source
4434
22
{
4435
22
  size_t amt;
4436
4437
22
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
22
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
22
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
22
}
pei-x86_64.c:buy_and_read
Line
Count
Source
4434
27
{
4435
27
  size_t amt;
4436
4437
27
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
27
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
27
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
27
}
coff-x86_64.c:buy_and_read
Line
Count
Source
4434
347
{
4435
347
  size_t amt;
4436
4437
347
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
347
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
347
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
347
}
coff64-rs6000.c:buy_and_read
Line
Count
Source
4434
98
{
4435
98
  size_t amt;
4436
4437
98
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
98
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
52
    return NULL;
4444
46
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
98
}
pe-aarch64.c:buy_and_read
Line
Count
Source
4434
51
{
4435
51
  size_t amt;
4436
4437
51
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
51
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
51
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
51
}
pei-aarch64.c:buy_and_read
Line
Count
Source
4434
10
{
4435
10
  size_t amt;
4436
4437
10
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
10
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
10
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
10
}
pei-ia64.c:buy_and_read
Line
Count
Source
4434
13
{
4435
13
  size_t amt;
4436
4437
13
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
13
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
13
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
13
}
pei-loongarch64.c:buy_and_read
Line
Count
Source
4434
13
{
4435
13
  size_t amt;
4436
4437
13
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
13
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
13
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
13
}
Unexecuted instantiation: cf-i386lynx.c:buy_and_read
Unexecuted instantiation: coff-go32.c:buy_and_read
Unexecuted instantiation: coff-i386.c:buy_and_read
coff-rs6000.c:buy_and_read
Line
Count
Source
4434
103
{
4435
103
  size_t amt;
4436
4437
103
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
103
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
103
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
103
}
coff-sh.c:buy_and_read
Line
Count
Source
4434
666
{
4435
666
  size_t amt;
4436
4437
666
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
666
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
666
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
666
}
Unexecuted instantiation: coff-stgo32.c:buy_and_read
coff-tic30.c:buy_and_read
Line
Count
Source
4434
9.55k
{
4435
9.55k
  size_t amt;
4436
4437
9.55k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
9.55k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
9.55k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
9.55k
}
Unexecuted instantiation: coff-tic4x.c:buy_and_read
coff-tic54x.c:buy_and_read
Line
Count
Source
4434
251
{
4435
251
  size_t amt;
4436
4437
251
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
251
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
251
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
251
}
coff-z80.c:buy_and_read
Line
Count
Source
4434
131
{
4435
131
  size_t amt;
4436
4437
131
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
131
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
131
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
131
}
coff-z8k.c:buy_and_read
Line
Count
Source
4434
223
{
4435
223
  size_t amt;
4436
4437
223
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
223
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
223
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
223
}
Unexecuted instantiation: pe-arm-wince.c:buy_and_read
Unexecuted instantiation: pe-arm.c:buy_and_read
pe-i386.c:buy_and_read
Line
Count
Source
4434
39
{
4435
39
  size_t amt;
4436
4437
39
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
39
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
39
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
39
}
pe-mcore.c:buy_and_read
Line
Count
Source
4434
10
{
4435
10
  size_t amt;
4436
4437
10
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
10
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
10
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
10
}
pe-sh.c:buy_and_read
Line
Count
Source
4434
29
{
4435
29
  size_t amt;
4436
4437
29
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
29
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
29
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
29
}
Unexecuted instantiation: pei-arm-wince.c:buy_and_read
Unexecuted instantiation: pei-arm.c:buy_and_read
pei-mcore.c:buy_and_read
Line
Count
Source
4434
4
{
4435
4
  size_t amt;
4436
4437
4
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
4
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
4
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
4
}
pei-sh.c:buy_and_read
Line
Count
Source
4434
8
{
4435
8
  size_t amt;
4436
4437
8
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
8
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
8
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
8
}
4446
4447
/*
4448
SUBSUBSECTION
4449
  Reading linenumbers
4450
4451
  Creating the linenumber table is done by reading in the entire
4452
  coff linenumber table, and creating another table for internal use.
4453
4454
  A coff linenumber table is structured so that each function
4455
  is marked as having a line number of 0. Each line within the
4456
  function is an offset from the first line in the function. The
4457
  base of the line number information for the table is stored in
4458
  the symbol associated with the function.
4459
4460
  Note: The PE format uses line number 0 for a flag indicating a
4461
  new source file.
4462
4463
  The information is copied from the external to the internal
4464
  table, and each symbol which marks a function is marked by
4465
  pointing its...
4466
4467
  How does this work ?
4468
*/
4469
4470
static int
4471
coff_sort_func_alent (const void * arg1, const void * arg2)
4472
26.9k
{
4473
26.9k
  const alent *al1 = *(const alent **) arg1;
4474
26.9k
  const alent *al2 = *(const alent **) arg2;
4475
26.9k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
26.9k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
26.9k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
26.9k
  if (s1->symbol.value < s2->symbol.value)
4481
213
    return -1;
4482
26.7k
  else if (s1->symbol.value > s2->symbol.value)
4483
2.21k
    return 1;
4484
4485
24.5k
  return 0;
4486
26.9k
}
Unexecuted instantiation: pei-i386.c:coff_sort_func_alent
pe-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
1.48k
{
4473
1.48k
  const alent *al1 = *(const alent **) arg1;
4474
1.48k
  const alent *al2 = *(const alent **) arg2;
4475
1.48k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
1.48k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
1.48k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
1.48k
  if (s1->symbol.value < s2->symbol.value)
4481
20
    return -1;
4482
1.46k
  else if (s1->symbol.value > s2->symbol.value)
4483
152
    return 1;
4484
4485
1.31k
  return 0;
4486
1.48k
}
pei-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
239
{
4473
239
  const alent *al1 = *(const alent **) arg1;
4474
239
  const alent *al2 = *(const alent **) arg2;
4475
239
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
239
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
239
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
239
  if (s1->symbol.value < s2->symbol.value)
4481
3
    return -1;
4482
236
  else if (s1->symbol.value > s2->symbol.value)
4483
27
    return 1;
4484
4485
209
  return 0;
4486
239
}
coff-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
2.80k
{
4473
2.80k
  const alent *al1 = *(const alent **) arg1;
4474
2.80k
  const alent *al2 = *(const alent **) arg2;
4475
2.80k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
2.80k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
2.80k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
2.80k
  if (s1->symbol.value < s2->symbol.value)
4481
36
    return -1;
4482
2.76k
  else if (s1->symbol.value > s2->symbol.value)
4483
444
    return 1;
4484
4485
2.32k
  return 0;
4486
2.80k
}
Unexecuted instantiation: coff64-rs6000.c:coff_sort_func_alent
pe-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
3.85k
{
4473
3.85k
  const alent *al1 = *(const alent **) arg1;
4474
3.85k
  const alent *al2 = *(const alent **) arg2;
4475
3.85k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
3.85k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
3.85k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
3.85k
  if (s1->symbol.value < s2->symbol.value)
4481
19
    return -1;
4482
3.83k
  else if (s1->symbol.value > s2->symbol.value)
4483
60
    return 1;
4484
4485
3.77k
  return 0;
4486
3.85k
}
pei-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
3
{
4473
3
  const alent *al1 = *(const alent **) arg1;
4474
3
  const alent *al2 = *(const alent **) arg2;
4475
3
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
3
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
3
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
3
  if (s1->symbol.value < s2->symbol.value)
4481
0
    return -1;
4482
3
  else if (s1->symbol.value > s2->symbol.value)
4483
2
    return 1;
4484
4485
1
  return 0;
4486
3
}
pei-ia64.c:coff_sort_func_alent
Line
Count
Source
4472
660
{
4473
660
  const alent *al1 = *(const alent **) arg1;
4474
660
  const alent *al2 = *(const alent **) arg2;
4475
660
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
660
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
660
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
660
  if (s1->symbol.value < s2->symbol.value)
4481
0
    return -1;
4482
660
  else if (s1->symbol.value > s2->symbol.value)
4483
1
    return 1;
4484
4485
659
  return 0;
4486
660
}
pei-loongarch64.c:coff_sort_func_alent
Line
Count
Source
4472
93
{
4473
93
  const alent *al1 = *(const alent **) arg1;
4474
93
  const alent *al2 = *(const alent **) arg2;
4475
93
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
93
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
93
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
93
  if (s1->symbol.value < s2->symbol.value)
4481
7
    return -1;
4482
86
  else if (s1->symbol.value > s2->symbol.value)
4483
19
    return 1;
4484
4485
67
  return 0;
4486
93
}
Unexecuted instantiation: cf-i386lynx.c:coff_sort_func_alent
Unexecuted instantiation: coff-go32.c:coff_sort_func_alent
Unexecuted instantiation: coff-i386.c:coff_sort_func_alent
coff-rs6000.c:coff_sort_func_alent
Line
Count
Source
4472
14
{
4473
14
  const alent *al1 = *(const alent **) arg1;
4474
14
  const alent *al2 = *(const alent **) arg2;
4475
14
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
14
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
14
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
14
  if (s1->symbol.value < s2->symbol.value)
4481
0
    return -1;
4482
14
  else if (s1->symbol.value > s2->symbol.value)
4483
8
    return 1;
4484
4485
6
  return 0;
4486
14
}
coff-sh.c:coff_sort_func_alent
Line
Count
Source
4472
967
{
4473
967
  const alent *al1 = *(const alent **) arg1;
4474
967
  const alent *al2 = *(const alent **) arg2;
4475
967
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
967
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
967
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
967
  if (s1->symbol.value < s2->symbol.value)
4481
4
    return -1;
4482
963
  else if (s1->symbol.value > s2->symbol.value)
4483
211
    return 1;
4484
4485
752
  return 0;
4486
967
}
Unexecuted instantiation: coff-stgo32.c:coff_sort_func_alent
coff-tic30.c:coff_sort_func_alent
Line
Count
Source
4472
11.8k
{
4473
11.8k
  const alent *al1 = *(const alent **) arg1;
4474
11.8k
  const alent *al2 = *(const alent **) arg2;
4475
11.8k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
11.8k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
11.8k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
11.8k
  if (s1->symbol.value < s2->symbol.value)
4481
39
    return -1;
4482
11.7k
  else if (s1->symbol.value > s2->symbol.value)
4483
57
    return 1;
4484
4485
11.7k
  return 0;
4486
11.8k
}
Unexecuted instantiation: coff-tic4x.c:coff_sort_func_alent
coff-tic54x.c:coff_sort_func_alent
Line
Count
Source
4472
893
{
4473
893
  const alent *al1 = *(const alent **) arg1;
4474
893
  const alent *al2 = *(const alent **) arg2;
4475
893
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
893
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
893
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
893
  if (s1->symbol.value < s2->symbol.value)
4481
4
    return -1;
4482
889
  else if (s1->symbol.value > s2->symbol.value)
4483
198
    return 1;
4484
4485
691
  return 0;
4486
893
}
coff-z80.c:coff_sort_func_alent
Line
Count
Source
4472
4.06k
{
4473
4.06k
  const alent *al1 = *(const alent **) arg1;
4474
4.06k
  const alent *al2 = *(const alent **) arg2;
4475
4.06k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
4.06k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
4.06k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
4.06k
  if (s1->symbol.value < s2->symbol.value)
4481
75
    return -1;
4482
3.99k
  else if (s1->symbol.value > s2->symbol.value)
4483
1.02k
    return 1;
4484
4485
2.96k
  return 0;
4486
4.06k
}
coff-z8k.c:coff_sort_func_alent
Line
Count
Source
4472
86
{
4473
86
  const alent *al1 = *(const alent **) arg1;
4474
86
  const alent *al2 = *(const alent **) arg2;
4475
86
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
86
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
86
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
86
  if (s1->symbol.value < s2->symbol.value)
4481
6
    return -1;
4482
80
  else if (s1->symbol.value > s2->symbol.value)
4483
5
    return 1;
4484
4485
75
  return 0;
4486
86
}
Unexecuted instantiation: pe-arm-wince.c:coff_sort_func_alent
Unexecuted instantiation: pe-arm.c:coff_sort_func_alent
Unexecuted instantiation: pe-i386.c:coff_sort_func_alent
Unexecuted instantiation: pe-mcore.c:coff_sort_func_alent
Unexecuted instantiation: pe-sh.c:coff_sort_func_alent
Unexecuted instantiation: pei-arm-wince.c:coff_sort_func_alent
Unexecuted instantiation: pei-arm.c:coff_sort_func_alent
Unexecuted instantiation: pei-mcore.c:coff_sort_func_alent
Unexecuted instantiation: pei-sh.c:coff_sort_func_alent
4487
4488
static bool
4489
coff_slurp_line_table (bfd *abfd, asection *asect)
4490
2.34k
{
4491
2.34k
  LINENO *native_lineno;
4492
2.34k
  alent *lineno_cache;
4493
2.34k
  unsigned int counter;
4494
2.34k
  alent *cache_ptr;
4495
2.34k
  bfd_vma prev_offset = 0;
4496
2.34k
  bool ordered = true;
4497
2.34k
  unsigned int nbr_func;
4498
2.34k
  LINENO *src;
4499
2.34k
  bool have_func;
4500
2.34k
  bool ret = true;
4501
2.34k
  size_t amt;
4502
4503
2.34k
  if (asect->lineno_count == 0)
4504
1.57k
    return true;
4505
4506
761
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
761
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
761
             asect->lineno_count,
4510
761
             bfd_coff_linesz (abfd));
4511
761
  if (native_lineno == NULL)
4512
320
    {
4513
320
      _bfd_error_handler
4514
320
  (_("%pB: warning: line number table read failed"), abfd);
4515
320
      return false;
4516
320
    }
4517
4518
441
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
441
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
441
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
441
  cache_ptr = lineno_cache;
4532
441
  asect->lineno = lineno_cache;
4533
441
  src = native_lineno;
4534
441
  nbr_func = 0;
4535
441
  have_func = false;
4536
4537
406k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
406k
    {
4539
406k
      struct internal_lineno dst;
4540
4541
406k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
406k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
406k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
406k
      if (cache_ptr->line_number == 0)
4549
107k
  {
4550
107k
    combined_entry_type * ent;
4551
107k
    unsigned long symndx;
4552
107k
    coff_symbol_type *sym;
4553
4554
107k
    have_func = false;
4555
107k
    symndx = dst.l_addr.l_symndx;
4556
107k
    if (symndx >= obj_raw_syment_count (abfd))
4557
97.4k
      {
4558
97.4k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
97.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
97.4k
     abfd, symndx, counter);
4562
97.4k
        cache_ptr->line_number = -1;
4563
97.4k
        ret = false;
4564
97.4k
        continue;
4565
97.4k
      }
4566
4567
10.1k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
10.1k
    if (! ent->is_sym)
4571
213
      {
4572
213
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
213
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
213
     abfd, symndx, counter);
4576
213
        cache_ptr->line_number = -1;
4577
213
        ret = false;
4578
213
        continue;
4579
213
      }
4580
9.94k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
9.94k
    if (sym < obj_symbols (abfd)
4584
9.94k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
9.94k
    have_func = true;
4596
9.94k
    nbr_func++;
4597
9.94k
    cache_ptr->u.sym = (asymbol *) sym;
4598
9.94k
    if (sym->lineno != NULL)
4599
9.59k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
9.59k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
9.59k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
9.94k
    sym->lineno = cache_ptr;
4605
9.94k
    if (sym->symbol.value < prev_offset)
4606
127
      ordered = false;
4607
9.94k
    prev_offset = sym->symbol.value;
4608
9.94k
  }
4609
298k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
290k
  continue;
4613
8.14k
      else
4614
8.14k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
18.0k
      cache_ptr++;
4616
18.0k
    }
4617
4618
441
  asect->lineno_count = cache_ptr - lineno_cache;
4619
441
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
441
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
441
  if (!ordered)
4624
74
    {
4625
      /* Sort the table.  */
4626
74
      alent **func_table;
4627
74
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
74
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
74
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
74
  {
4637
74
    alent **p = func_table;
4638
74
    unsigned int i;
4639
4640
11.2k
    for (i = 0; i < asect->lineno_count; i++)
4641
11.2k
      if (lineno_cache[i].line_number == 0)
4642
6.60k
        *p++ = &lineno_cache[i];
4643
4644
74
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
74
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
74
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
74
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
74
      {
4657
74
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
6.68k
        for (i = 0; i < nbr_func; i++)
4660
6.60k
    {
4661
6.60k
      coff_symbol_type *sym;
4662
6.60k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
6.60k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
6.60k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
6.60k
      do
4671
11.2k
        *n_cache_ptr++ = *old_ptr++;
4672
11.2k
      while (old_ptr->line_number != 0);
4673
6.60k
    }
4674
4675
74
        memcpy (lineno_cache, n_lineno_cache,
4676
74
          asect->lineno_count * sizeof (alent));
4677
74
      }
4678
0
    else
4679
0
      ret = false;
4680
74
    bfd_release (abfd, func_table);
4681
74
  }
4682
0
      else
4683
0
  ret = false;
4684
74
    }
4685
4686
441
  return ret;
4687
441
}
pei-i386.c:coff_slurp_line_table
Line
Count
Source
4490
20
{
4491
20
  LINENO *native_lineno;
4492
20
  alent *lineno_cache;
4493
20
  unsigned int counter;
4494
20
  alent *cache_ptr;
4495
20
  bfd_vma prev_offset = 0;
4496
20
  bool ordered = true;
4497
20
  unsigned int nbr_func;
4498
20
  LINENO *src;
4499
20
  bool have_func;
4500
20
  bool ret = true;
4501
20
  size_t amt;
4502
4503
20
  if (asect->lineno_count == 0)
4504
12
    return true;
4505
4506
8
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
8
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
8
             asect->lineno_count,
4510
8
             bfd_coff_linesz (abfd));
4511
8
  if (native_lineno == NULL)
4512
6
    {
4513
6
      _bfd_error_handler
4514
6
  (_("%pB: warning: line number table read failed"), abfd);
4515
6
      return false;
4516
6
    }
4517
4518
2
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
2
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
2
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
2
  cache_ptr = lineno_cache;
4532
2
  asect->lineno = lineno_cache;
4533
2
  src = native_lineno;
4534
2
  nbr_func = 0;
4535
2
  have_func = false;
4536
4537
103
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
101
    {
4539
101
      struct internal_lineno dst;
4540
4541
101
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
101
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
101
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
101
      if (cache_ptr->line_number == 0)
4549
56
  {
4550
56
    combined_entry_type * ent;
4551
56
    unsigned long symndx;
4552
56
    coff_symbol_type *sym;
4553
4554
56
    have_func = false;
4555
56
    symndx = dst.l_addr.l_symndx;
4556
56
    if (symndx >= obj_raw_syment_count (abfd))
4557
36
      {
4558
36
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
36
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
36
     abfd, symndx, counter);
4562
36
        cache_ptr->line_number = -1;
4563
36
        ret = false;
4564
36
        continue;
4565
36
      }
4566
4567
20
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
20
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
20
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
20
    if (sym < obj_symbols (abfd)
4584
20
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
20
    have_func = true;
4596
20
    nbr_func++;
4597
20
    cache_ptr->u.sym = (asymbol *) sym;
4598
20
    if (sym->lineno != NULL)
4599
18
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
18
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
18
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
20
    sym->lineno = cache_ptr;
4605
20
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
20
    prev_offset = sym->symbol.value;
4608
20
  }
4609
45
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
44
  continue;
4613
1
      else
4614
1
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
21
      cache_ptr++;
4616
21
    }
4617
4618
2
  asect->lineno_count = cache_ptr - lineno_cache;
4619
2
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
2
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
2
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
2
  return ret;
4687
2
}
pe-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
100
{
4491
100
  LINENO *native_lineno;
4492
100
  alent *lineno_cache;
4493
100
  unsigned int counter;
4494
100
  alent *cache_ptr;
4495
100
  bfd_vma prev_offset = 0;
4496
100
  bool ordered = true;
4497
100
  unsigned int nbr_func;
4498
100
  LINENO *src;
4499
100
  bool have_func;
4500
100
  bool ret = true;
4501
100
  size_t amt;
4502
4503
100
  if (asect->lineno_count == 0)
4504
80
    return true;
4505
4506
20
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
20
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
20
             asect->lineno_count,
4510
20
             bfd_coff_linesz (abfd));
4511
20
  if (native_lineno == NULL)
4512
5
    {
4513
5
      _bfd_error_handler
4514
5
  (_("%pB: warning: line number table read failed"), abfd);
4515
5
      return false;
4516
5
    }
4517
4518
15
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
15
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
15
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
15
  cache_ptr = lineno_cache;
4532
15
  asect->lineno = lineno_cache;
4533
15
  src = native_lineno;
4534
15
  nbr_func = 0;
4535
15
  have_func = false;
4536
4537
1.25k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
1.23k
    {
4539
1.23k
      struct internal_lineno dst;
4540
4541
1.23k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
1.23k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
1.23k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
1.23k
      if (cache_ptr->line_number == 0)
4549
892
  {
4550
892
    combined_entry_type * ent;
4551
892
    unsigned long symndx;
4552
892
    coff_symbol_type *sym;
4553
4554
892
    have_func = false;
4555
892
    symndx = dst.l_addr.l_symndx;
4556
892
    if (symndx >= obj_raw_syment_count (abfd))
4557
282
      {
4558
282
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
282
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
282
     abfd, symndx, counter);
4562
282
        cache_ptr->line_number = -1;
4563
282
        ret = false;
4564
282
        continue;
4565
282
      }
4566
4567
610
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
610
    if (! ent->is_sym)
4571
8
      {
4572
8
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
8
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
8
     abfd, symndx, counter);
4576
8
        cache_ptr->line_number = -1;
4577
8
        ret = false;
4578
8
        continue;
4579
8
      }
4580
602
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
602
    if (sym < obj_symbols (abfd)
4584
602
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
602
    have_func = true;
4596
602
    nbr_func++;
4597
602
    cache_ptr->u.sym = (asymbol *) sym;
4598
602
    if (sym->lineno != NULL)
4599
577
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
577
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
577
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
602
    sym->lineno = cache_ptr;
4605
602
    if (sym->symbol.value < prev_offset)
4606
17
      ordered = false;
4607
602
    prev_offset = sym->symbol.value;
4608
602
  }
4609
343
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
162
  continue;
4613
181
      else
4614
181
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
783
      cache_ptr++;
4616
783
    }
4617
4618
15
  asect->lineno_count = cache_ptr - lineno_cache;
4619
15
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
15
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
15
  if (!ordered)
4624
9
    {
4625
      /* Sort the table.  */
4626
9
      alent **func_table;
4627
9
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
9
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
9
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
9
  {
4637
9
    alent **p = func_table;
4638
9
    unsigned int i;
4639
4640
606
    for (i = 0; i < asect->lineno_count; i++)
4641
597
      if (lineno_cache[i].line_number == 0)
4642
476
        *p++ = &lineno_cache[i];
4643
4644
9
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
9
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
9
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
9
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
9
      {
4657
9
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
485
        for (i = 0; i < nbr_func; i++)
4660
476
    {
4661
476
      coff_symbol_type *sym;
4662
476
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
476
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
476
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
476
      do
4671
597
        *n_cache_ptr++ = *old_ptr++;
4672
597
      while (old_ptr->line_number != 0);
4673
476
    }
4674
4675
9
        memcpy (lineno_cache, n_lineno_cache,
4676
9
          asect->lineno_count * sizeof (alent));
4677
9
      }
4678
0
    else
4679
0
      ret = false;
4680
9
    bfd_release (abfd, func_table);
4681
9
  }
4682
0
      else
4683
0
  ret = false;
4684
9
    }
4685
4686
15
  return ret;
4687
15
}
pei-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
98
{
4491
98
  LINENO *native_lineno;
4492
98
  alent *lineno_cache;
4493
98
  unsigned int counter;
4494
98
  alent *cache_ptr;
4495
98
  bfd_vma prev_offset = 0;
4496
98
  bool ordered = true;
4497
98
  unsigned int nbr_func;
4498
98
  LINENO *src;
4499
98
  bool have_func;
4500
98
  bool ret = true;
4501
98
  size_t amt;
4502
4503
98
  if (asect->lineno_count == 0)
4504
71
    return true;
4505
4506
27
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
27
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
27
             asect->lineno_count,
4510
27
             bfd_coff_linesz (abfd));
4511
27
  if (native_lineno == NULL)
4512
6
    {
4513
6
      _bfd_error_handler
4514
6
  (_("%pB: warning: line number table read failed"), abfd);
4515
6
      return false;
4516
6
    }
4517
4518
21
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
21
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
21
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
21
  cache_ptr = lineno_cache;
4532
21
  asect->lineno = lineno_cache;
4533
21
  src = native_lineno;
4534
21
  nbr_func = 0;
4535
21
  have_func = false;
4536
4537
985
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
964
    {
4539
964
      struct internal_lineno dst;
4540
4541
964
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
964
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
964
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
964
      if (cache_ptr->line_number == 0)
4549
408
  {
4550
408
    combined_entry_type * ent;
4551
408
    unsigned long symndx;
4552
408
    coff_symbol_type *sym;
4553
4554
408
    have_func = false;
4555
408
    symndx = dst.l_addr.l_symndx;
4556
408
    if (symndx >= obj_raw_syment_count (abfd))
4557
125
      {
4558
125
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
125
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
125
     abfd, symndx, counter);
4562
125
        cache_ptr->line_number = -1;
4563
125
        ret = false;
4564
125
        continue;
4565
125
      }
4566
4567
283
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
283
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
283
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
283
    if (sym < obj_symbols (abfd)
4584
283
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
283
    have_func = true;
4596
283
    nbr_func++;
4597
283
    cache_ptr->u.sym = (asymbol *) sym;
4598
283
    if (sym->lineno != NULL)
4599
257
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
257
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
257
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
283
    sym->lineno = cache_ptr;
4605
283
    if (sym->symbol.value < prev_offset)
4606
6
      ordered = false;
4607
283
    prev_offset = sym->symbol.value;
4608
283
  }
4609
556
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
420
  continue;
4613
136
      else
4614
136
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
419
      cache_ptr++;
4616
419
    }
4617
4618
21
  asect->lineno_count = cache_ptr - lineno_cache;
4619
21
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
21
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
21
  if (!ordered)
4624
6
    {
4625
      /* Sort the table.  */
4626
6
      alent **func_table;
4627
6
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
6
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
6
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
6
  {
4637
6
    alent **p = func_table;
4638
6
    unsigned int i;
4639
4640
167
    for (i = 0; i < asect->lineno_count; i++)
4641
161
      if (lineno_cache[i].line_number == 0)
4642
103
        *p++ = &lineno_cache[i];
4643
4644
6
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
6
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
6
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
6
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
6
      {
4657
6
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
109
        for (i = 0; i < nbr_func; i++)
4660
103
    {
4661
103
      coff_symbol_type *sym;
4662
103
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
103
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
103
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
103
      do
4671
161
        *n_cache_ptr++ = *old_ptr++;
4672
161
      while (old_ptr->line_number != 0);
4673
103
    }
4674
4675
6
        memcpy (lineno_cache, n_lineno_cache,
4676
6
          asect->lineno_count * sizeof (alent));
4677
6
      }
4678
0
    else
4679
0
      ret = false;
4680
6
    bfd_release (abfd, func_table);
4681
6
  }
4682
0
      else
4683
0
  ret = false;
4684
6
    }
4685
4686
21
  return ret;
4687
21
}
coff-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
352
{
4491
352
  LINENO *native_lineno;
4492
352
  alent *lineno_cache;
4493
352
  unsigned int counter;
4494
352
  alent *cache_ptr;
4495
352
  bfd_vma prev_offset = 0;
4496
352
  bool ordered = true;
4497
352
  unsigned int nbr_func;
4498
352
  LINENO *src;
4499
352
  bool have_func;
4500
352
  bool ret = true;
4501
352
  size_t amt;
4502
4503
352
  if (asect->lineno_count == 0)
4504
271
    return true;
4505
4506
81
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
81
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
81
             asect->lineno_count,
4510
81
             bfd_coff_linesz (abfd));
4511
81
  if (native_lineno == NULL)
4512
45
    {
4513
45
      _bfd_error_handler
4514
45
  (_("%pB: warning: line number table read failed"), abfd);
4515
45
      return false;
4516
45
    }
4517
4518
36
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
36
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
36
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
36
  cache_ptr = lineno_cache;
4532
36
  asect->lineno = lineno_cache;
4533
36
  src = native_lineno;
4534
36
  nbr_func = 0;
4535
36
  have_func = false;
4536
4537
3.07k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
3.04k
    {
4539
3.04k
      struct internal_lineno dst;
4540
4541
3.04k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
3.04k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
3.04k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
3.04k
      if (cache_ptr->line_number == 0)
4549
1.83k
  {
4550
1.83k
    combined_entry_type * ent;
4551
1.83k
    unsigned long symndx;
4552
1.83k
    coff_symbol_type *sym;
4553
4554
1.83k
    have_func = false;
4555
1.83k
    symndx = dst.l_addr.l_symndx;
4556
1.83k
    if (symndx >= obj_raw_syment_count (abfd))
4557
753
      {
4558
753
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
753
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
753
     abfd, symndx, counter);
4562
753
        cache_ptr->line_number = -1;
4563
753
        ret = false;
4564
753
        continue;
4565
753
      }
4566
4567
1.08k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.08k
    if (! ent->is_sym)
4571
20
      {
4572
20
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
20
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
20
     abfd, symndx, counter);
4576
20
        cache_ptr->line_number = -1;
4577
20
        ret = false;
4578
20
        continue;
4579
20
      }
4580
1.06k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.06k
    if (sym < obj_symbols (abfd)
4584
1.06k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.06k
    have_func = true;
4596
1.06k
    nbr_func++;
4597
1.06k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.06k
    if (sym->lineno != NULL)
4599
1.00k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.00k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.00k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.06k
    sym->lineno = cache_ptr;
4605
1.06k
    if (sym->symbol.value < prev_offset)
4606
32
      ordered = false;
4607
1.06k
    prev_offset = sym->symbol.value;
4608
1.06k
  }
4609
1.20k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
736
  continue;
4613
473
      else
4614
473
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
1.53k
      cache_ptr++;
4616
1.53k
    }
4617
4618
36
  asect->lineno_count = cache_ptr - lineno_cache;
4619
36
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
36
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
36
  if (!ordered)
4624
18
    {
4625
      /* Sort the table.  */
4626
18
      alent **func_table;
4627
18
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
18
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
18
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
18
  {
4637
18
    alent **p = func_table;
4638
18
    unsigned int i;
4639
4640
1.30k
    for (i = 0; i < asect->lineno_count; i++)
4641
1.29k
      if (lineno_cache[i].line_number == 0)
4642
867
        *p++ = &lineno_cache[i];
4643
4644
18
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
18
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
18
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
18
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
18
      {
4657
18
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
885
        for (i = 0; i < nbr_func; i++)
4660
867
    {
4661
867
      coff_symbol_type *sym;
4662
867
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
867
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
867
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
867
      do
4671
1.29k
        *n_cache_ptr++ = *old_ptr++;
4672
1.29k
      while (old_ptr->line_number != 0);
4673
867
    }
4674
4675
18
        memcpy (lineno_cache, n_lineno_cache,
4676
18
          asect->lineno_count * sizeof (alent));
4677
18
      }
4678
0
    else
4679
0
      ret = false;
4680
18
    bfd_release (abfd, func_table);
4681
18
  }
4682
0
      else
4683
0
  ret = false;
4684
18
    }
4685
4686
36
  return ret;
4687
36
}
coff64-rs6000.c:coff_slurp_line_table
Line
Count
Source
4490
72
{
4491
72
  LINENO *native_lineno;
4492
72
  alent *lineno_cache;
4493
72
  unsigned int counter;
4494
72
  alent *cache_ptr;
4495
72
  bfd_vma prev_offset = 0;
4496
72
  bool ordered = true;
4497
72
  unsigned int nbr_func;
4498
72
  LINENO *src;
4499
72
  bool have_func;
4500
72
  bool ret = true;
4501
72
  size_t amt;
4502
4503
72
  if (asect->lineno_count == 0)
4504
24
    return true;
4505
4506
48
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
48
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
48
             asect->lineno_count,
4510
48
             bfd_coff_linesz (abfd));
4511
48
  if (native_lineno == NULL)
4512
37
    {
4513
37
      _bfd_error_handler
4514
37
  (_("%pB: warning: line number table read failed"), abfd);
4515
37
      return false;
4516
37
    }
4517
4518
11
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
11
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
11
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
11
  cache_ptr = lineno_cache;
4532
11
  asect->lineno = lineno_cache;
4533
11
  src = native_lineno;
4534
11
  nbr_func = 0;
4535
11
  have_func = false;
4536
4537
891
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
880
    {
4539
880
      struct internal_lineno dst;
4540
4541
880
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
880
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
880
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
880
      if (cache_ptr->line_number == 0)
4549
142
  {
4550
142
    combined_entry_type * ent;
4551
142
    unsigned long symndx;
4552
142
    coff_symbol_type *sym;
4553
4554
142
    have_func = false;
4555
142
    symndx = dst.l_addr.l_symndx;
4556
142
    if (symndx >= obj_raw_syment_count (abfd))
4557
136
      {
4558
136
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
136
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
136
     abfd, symndx, counter);
4562
136
        cache_ptr->line_number = -1;
4563
136
        ret = false;
4564
136
        continue;
4565
136
      }
4566
4567
6
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
6
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
6
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
6
    if (sym < obj_symbols (abfd)
4584
6
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
6
    have_func = true;
4596
6
    nbr_func++;
4597
6
    cache_ptr->u.sym = (asymbol *) sym;
4598
6
    if (sym->lineno != NULL)
4599
3
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
3
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
3
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
6
    sym->lineno = cache_ptr;
4605
6
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
6
    prev_offset = sym->symbol.value;
4608
6
  }
4609
738
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
719
  continue;
4613
19
      else
4614
19
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
25
      cache_ptr++;
4616
25
    }
4617
4618
11
  asect->lineno_count = cache_ptr - lineno_cache;
4619
11
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
11
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
11
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
11
  return ret;
4687
11
}
pe-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
123
{
4491
123
  LINENO *native_lineno;
4492
123
  alent *lineno_cache;
4493
123
  unsigned int counter;
4494
123
  alent *cache_ptr;
4495
123
  bfd_vma prev_offset = 0;
4496
123
  bool ordered = true;
4497
123
  unsigned int nbr_func;
4498
123
  LINENO *src;
4499
123
  bool have_func;
4500
123
  bool ret = true;
4501
123
  size_t amt;
4502
4503
123
  if (asect->lineno_count == 0)
4504
91
    return true;
4505
4506
32
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
32
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
32
             asect->lineno_count,
4510
32
             bfd_coff_linesz (abfd));
4511
32
  if (native_lineno == NULL)
4512
17
    {
4513
17
      _bfd_error_handler
4514
17
  (_("%pB: warning: line number table read failed"), abfd);
4515
17
      return false;
4516
17
    }
4517
4518
15
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
15
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
15
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
15
  cache_ptr = lineno_cache;
4532
15
  asect->lineno = lineno_cache;
4533
15
  src = native_lineno;
4534
15
  nbr_func = 0;
4535
15
  have_func = false;
4536
4537
3.95k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
3.94k
    {
4539
3.94k
      struct internal_lineno dst;
4540
4541
3.94k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
3.94k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
3.94k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
3.94k
      if (cache_ptr->line_number == 0)
4549
1.42k
  {
4550
1.42k
    combined_entry_type * ent;
4551
1.42k
    unsigned long symndx;
4552
1.42k
    coff_symbol_type *sym;
4553
4554
1.42k
    have_func = false;
4555
1.42k
    symndx = dst.l_addr.l_symndx;
4556
1.42k
    if (symndx >= obj_raw_syment_count (abfd))
4557
356
      {
4558
356
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
356
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
356
     abfd, symndx, counter);
4562
356
        cache_ptr->line_number = -1;
4563
356
        ret = false;
4564
356
        continue;
4565
356
      }
4566
4567
1.07k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.07k
    if (! ent->is_sym)
4571
2
      {
4572
2
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
2
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
2
     abfd, symndx, counter);
4576
2
        cache_ptr->line_number = -1;
4577
2
        ret = false;
4578
2
        continue;
4579
2
      }
4580
1.07k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.07k
    if (sym < obj_symbols (abfd)
4584
1.07k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.07k
    have_func = true;
4596
1.07k
    nbr_func++;
4597
1.07k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.07k
    if (sym->lineno != NULL)
4599
1.05k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.05k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.05k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.07k
    sym->lineno = cache_ptr;
4605
1.07k
    if (sym->symbol.value < prev_offset)
4606
6
      ordered = false;
4607
1.07k
    prev_offset = sym->symbol.value;
4608
1.07k
  }
4609
2.51k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
866
  continue;
4613
1.64k
      else
4614
1.64k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
2.71k
      cache_ptr++;
4616
2.71k
    }
4617
4618
15
  asect->lineno_count = cache_ptr - lineno_cache;
4619
15
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
15
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
15
  if (!ordered)
4624
5
    {
4625
      /* Sort the table.  */
4626
5
      alent **func_table;
4627
5
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
5
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
5
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
5
  {
4637
5
    alent **p = func_table;
4638
5
    unsigned int i;
4639
4640
2.37k
    for (i = 0; i < asect->lineno_count; i++)
4641
2.37k
      if (lineno_cache[i].line_number == 0)
4642
1.00k
        *p++ = &lineno_cache[i];
4643
4644
5
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
5
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
5
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
5
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
5
      {
4657
5
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
1.00k
        for (i = 0; i < nbr_func; i++)
4660
1.00k
    {
4661
1.00k
      coff_symbol_type *sym;
4662
1.00k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
1.00k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
1.00k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
1.00k
      do
4671
2.37k
        *n_cache_ptr++ = *old_ptr++;
4672
2.37k
      while (old_ptr->line_number != 0);
4673
1.00k
    }
4674
4675
5
        memcpy (lineno_cache, n_lineno_cache,
4676
5
          asect->lineno_count * sizeof (alent));
4677
5
      }
4678
0
    else
4679
0
      ret = false;
4680
5
    bfd_release (abfd, func_table);
4681
5
  }
4682
0
      else
4683
0
  ret = false;
4684
5
    }
4685
4686
15
  return ret;
4687
15
}
pei-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
46
{
4491
46
  LINENO *native_lineno;
4492
46
  alent *lineno_cache;
4493
46
  unsigned int counter;
4494
46
  alent *cache_ptr;
4495
46
  bfd_vma prev_offset = 0;
4496
46
  bool ordered = true;
4497
46
  unsigned int nbr_func;
4498
46
  LINENO *src;
4499
46
  bool have_func;
4500
46
  bool ret = true;
4501
46
  size_t amt;
4502
4503
46
  if (asect->lineno_count == 0)
4504
36
    return true;
4505
4506
10
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
10
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
10
             asect->lineno_count,
4510
10
             bfd_coff_linesz (abfd));
4511
10
  if (native_lineno == NULL)
4512
6
    {
4513
6
      _bfd_error_handler
4514
6
  (_("%pB: warning: line number table read failed"), abfd);
4515
6
      return false;
4516
6
    }
4517
4518
4
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
4
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
4
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
4
  cache_ptr = lineno_cache;
4532
4
  asect->lineno = lineno_cache;
4533
4
  src = native_lineno;
4534
4
  nbr_func = 0;
4535
4
  have_func = false;
4536
4537
294
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
290
    {
4539
290
      struct internal_lineno dst;
4540
4541
290
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
290
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
290
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
290
      if (cache_ptr->line_number == 0)
4549
141
  {
4550
141
    combined_entry_type * ent;
4551
141
    unsigned long symndx;
4552
141
    coff_symbol_type *sym;
4553
4554
141
    have_func = false;
4555
141
    symndx = dst.l_addr.l_symndx;
4556
141
    if (symndx >= obj_raw_syment_count (abfd))
4557
25
      {
4558
25
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
25
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
25
     abfd, symndx, counter);
4562
25
        cache_ptr->line_number = -1;
4563
25
        ret = false;
4564
25
        continue;
4565
25
      }
4566
4567
116
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
116
    if (! ent->is_sym)
4571
1
      {
4572
1
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1
     abfd, symndx, counter);
4576
1
        cache_ptr->line_number = -1;
4577
1
        ret = false;
4578
1
        continue;
4579
1
      }
4580
115
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
115
    if (sym < obj_symbols (abfd)
4584
115
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
115
    have_func = true;
4596
115
    nbr_func++;
4597
115
    cache_ptr->u.sym = (asymbol *) sym;
4598
115
    if (sym->lineno != NULL)
4599
110
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
110
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
110
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
115
    sym->lineno = cache_ptr;
4605
115
    if (sym->symbol.value < prev_offset)
4606
1
      ordered = false;
4607
115
    prev_offset = sym->symbol.value;
4608
115
  }
4609
149
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
45
  continue;
4613
104
      else
4614
104
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
219
      cache_ptr++;
4616
219
    }
4617
4618
4
  asect->lineno_count = cache_ptr - lineno_cache;
4619
4
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
4
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
4
  if (!ordered)
4624
1
    {
4625
      /* Sort the table.  */
4626
1
      alent **func_table;
4627
1
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
1
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
1
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
1
  {
4637
1
    alent **p = func_table;
4638
1
    unsigned int i;
4639
4640
5
    for (i = 0; i < asect->lineno_count; i++)
4641
4
      if (lineno_cache[i].line_number == 0)
4642
3
        *p++ = &lineno_cache[i];
4643
4644
1
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
1
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
1
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
1
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
1
      {
4657
1
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
4
        for (i = 0; i < nbr_func; i++)
4660
3
    {
4661
3
      coff_symbol_type *sym;
4662
3
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
3
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
3
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
3
      do
4671
4
        *n_cache_ptr++ = *old_ptr++;
4672
4
      while (old_ptr->line_number != 0);
4673
3
    }
4674
4675
1
        memcpy (lineno_cache, n_lineno_cache,
4676
1
          asect->lineno_count * sizeof (alent));
4677
1
      }
4678
0
    else
4679
0
      ret = false;
4680
1
    bfd_release (abfd, func_table);
4681
1
  }
4682
0
      else
4683
0
  ret = false;
4684
1
    }
4685
4686
4
  return ret;
4687
4
}
pei-ia64.c:coff_slurp_line_table
Line
Count
Source
4490
137
{
4491
137
  LINENO *native_lineno;
4492
137
  alent *lineno_cache;
4493
137
  unsigned int counter;
4494
137
  alent *cache_ptr;
4495
137
  bfd_vma prev_offset = 0;
4496
137
  bool ordered = true;
4497
137
  unsigned int nbr_func;
4498
137
  LINENO *src;
4499
137
  bool have_func;
4500
137
  bool ret = true;
4501
137
  size_t amt;
4502
4503
137
  if (asect->lineno_count == 0)
4504
124
    return true;
4505
4506
13
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
13
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
13
             asect->lineno_count,
4510
13
             bfd_coff_linesz (abfd));
4511
13
  if (native_lineno == NULL)
4512
3
    {
4513
3
      _bfd_error_handler
4514
3
  (_("%pB: warning: line number table read failed"), abfd);
4515
3
      return false;
4516
3
    }
4517
4518
10
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
10
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
10
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
10
  cache_ptr = lineno_cache;
4532
10
  asect->lineno = lineno_cache;
4533
10
  src = native_lineno;
4534
10
  nbr_func = 0;
4535
10
  have_func = false;
4536
4537
2.10k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
2.09k
    {
4539
2.09k
      struct internal_lineno dst;
4540
4541
2.09k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
2.09k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
2.09k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
2.09k
      if (cache_ptr->line_number == 0)
4549
1.78k
  {
4550
1.78k
    combined_entry_type * ent;
4551
1.78k
    unsigned long symndx;
4552
1.78k
    coff_symbol_type *sym;
4553
4554
1.78k
    have_func = false;
4555
1.78k
    symndx = dst.l_addr.l_symndx;
4556
1.78k
    if (symndx >= obj_raw_syment_count (abfd))
4557
245
      {
4558
245
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
245
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
245
     abfd, symndx, counter);
4562
245
        cache_ptr->line_number = -1;
4563
245
        ret = false;
4564
245
        continue;
4565
245
      }
4566
4567
1.53k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.53k
    if (! ent->is_sym)
4571
1
      {
4572
1
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1
     abfd, symndx, counter);
4576
1
        cache_ptr->line_number = -1;
4577
1
        ret = false;
4578
1
        continue;
4579
1
      }
4580
1.53k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.53k
    if (sym < obj_symbols (abfd)
4584
1.53k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
1.53k
    have_func = true;
4596
1.53k
    nbr_func++;
4597
1.53k
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.53k
    if (sym->lineno != NULL)
4599
1.51k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.51k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.51k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.53k
    sym->lineno = cache_ptr;
4605
1.53k
    if (sym->symbol.value < prev_offset)
4606
1
      ordered = false;
4607
1.53k
    prev_offset = sym->symbol.value;
4608
1.53k
  }
4609
312
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
192
  continue;
4613
120
      else
4614
120
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
1.65k
      cache_ptr++;
4616
1.65k
    }
4617
4618
10
  asect->lineno_count = cache_ptr - lineno_cache;
4619
10
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
10
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
10
  if (!ordered)
4624
1
    {
4625
      /* Sort the table.  */
4626
1
      alent **func_table;
4627
1
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
1
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
1
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
1
  {
4637
1
    alent **p = func_table;
4638
1
    unsigned int i;
4639
4640
200
    for (i = 0; i < asect->lineno_count; i++)
4641
199
      if (lineno_cache[i].line_number == 0)
4642
184
        *p++ = &lineno_cache[i];
4643
4644
1
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
1
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
1
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
1
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
1
      {
4657
1
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
185
        for (i = 0; i < nbr_func; i++)
4660
184
    {
4661
184
      coff_symbol_type *sym;
4662
184
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
184
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
184
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
184
      do
4671
199
        *n_cache_ptr++ = *old_ptr++;
4672
199
      while (old_ptr->line_number != 0);
4673
184
    }
4674
4675
1
        memcpy (lineno_cache, n_lineno_cache,
4676
1
          asect->lineno_count * sizeof (alent));
4677
1
      }
4678
0
    else
4679
0
      ret = false;
4680
1
    bfd_release (abfd, func_table);
4681
1
  }
4682
0
      else
4683
0
  ret = false;
4684
1
    }
4685
4686
10
  return ret;
4687
10
}
pei-loongarch64.c:coff_slurp_line_table
Line
Count
Source
4490
17
{
4491
17
  LINENO *native_lineno;
4492
17
  alent *lineno_cache;
4493
17
  unsigned int counter;
4494
17
  alent *cache_ptr;
4495
17
  bfd_vma prev_offset = 0;
4496
17
  bool ordered = true;
4497
17
  unsigned int nbr_func;
4498
17
  LINENO *src;
4499
17
  bool have_func;
4500
17
  bool ret = true;
4501
17
  size_t amt;
4502
4503
17
  if (asect->lineno_count == 0)
4504
4
    return true;
4505
4506
13
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
13
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
13
             asect->lineno_count,
4510
13
             bfd_coff_linesz (abfd));
4511
13
  if (native_lineno == NULL)
4512
1
    {
4513
1
      _bfd_error_handler
4514
1
  (_("%pB: warning: line number table read failed"), abfd);
4515
1
      return false;
4516
1
    }
4517
4518
12
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
12
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
12
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
12
  cache_ptr = lineno_cache;
4532
12
  asect->lineno = lineno_cache;
4533
12
  src = native_lineno;
4534
12
  nbr_func = 0;
4535
12
  have_func = false;
4536
4537
681
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
669
    {
4539
669
      struct internal_lineno dst;
4540
4541
669
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
669
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
669
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
669
      if (cache_ptr->line_number == 0)
4549
263
  {
4550
263
    combined_entry_type * ent;
4551
263
    unsigned long symndx;
4552
263
    coff_symbol_type *sym;
4553
4554
263
    have_func = false;
4555
263
    symndx = dst.l_addr.l_symndx;
4556
263
    if (symndx >= obj_raw_syment_count (abfd))
4557
170
      {
4558
170
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
170
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
170
     abfd, symndx, counter);
4562
170
        cache_ptr->line_number = -1;
4563
170
        ret = false;
4564
170
        continue;
4565
170
      }
4566
4567
93
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
93
    if (! ent->is_sym)
4571
1
      {
4572
1
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1
     abfd, symndx, counter);
4576
1
        cache_ptr->line_number = -1;
4577
1
        ret = false;
4578
1
        continue;
4579
1
      }
4580
92
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
92
    if (sym < obj_symbols (abfd)
4584
92
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
92
    have_func = true;
4596
92
    nbr_func++;
4597
92
    cache_ptr->u.sym = (asymbol *) sym;
4598
92
    if (sym->lineno != NULL)
4599
73
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
73
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
73
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
92
    sym->lineno = cache_ptr;
4605
92
    if (sym->symbol.value < prev_offset)
4606
9
      ordered = false;
4607
92
    prev_offset = sym->symbol.value;
4608
92
  }
4609
406
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
257
  continue;
4613
149
      else
4614
149
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
241
      cache_ptr++;
4616
241
    }
4617
4618
12
  asect->lineno_count = cache_ptr - lineno_cache;
4619
12
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
12
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
12
  if (!ordered)
4624
8
    {
4625
      /* Sort the table.  */
4626
8
      alent **func_table;
4627
8
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
8
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
8
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
8
  {
4637
8
    alent **p = func_table;
4638
8
    unsigned int i;
4639
4640
182
    for (i = 0; i < asect->lineno_count; i++)
4641
174
      if (lineno_cache[i].line_number == 0)
4642
58
        *p++ = &lineno_cache[i];
4643
4644
8
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
8
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
8
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
8
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
8
      {
4657
8
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
66
        for (i = 0; i < nbr_func; i++)
4660
58
    {
4661
58
      coff_symbol_type *sym;
4662
58
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
58
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
58
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
58
      do
4671
174
        *n_cache_ptr++ = *old_ptr++;
4672
174
      while (old_ptr->line_number != 0);
4673
58
    }
4674
4675
8
        memcpy (lineno_cache, n_lineno_cache,
4676
8
          asect->lineno_count * sizeof (alent));
4677
8
      }
4678
0
    else
4679
0
      ret = false;
4680
8
    bfd_release (abfd, func_table);
4681
8
  }
4682
0
      else
4683
0
  ret = false;
4684
8
    }
4685
4686
12
  return ret;
4687
12
}
Unexecuted instantiation: cf-i386lynx.c:coff_slurp_line_table
Unexecuted instantiation: coff-go32.c:coff_slurp_line_table
Unexecuted instantiation: coff-i386.c:coff_slurp_line_table
coff-rs6000.c:coff_slurp_line_table
Line
Count
Source
4490
119
{
4491
119
  LINENO *native_lineno;
4492
119
  alent *lineno_cache;
4493
119
  unsigned int counter;
4494
119
  alent *cache_ptr;
4495
119
  bfd_vma prev_offset = 0;
4496
119
  bool ordered = true;
4497
119
  unsigned int nbr_func;
4498
119
  LINENO *src;
4499
119
  bool have_func;
4500
119
  bool ret = true;
4501
119
  size_t amt;
4502
4503
119
  if (asect->lineno_count == 0)
4504
62
    return true;
4505
4506
57
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
57
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
57
             asect->lineno_count,
4510
57
             bfd_coff_linesz (abfd));
4511
57
  if (native_lineno == NULL)
4512
29
    {
4513
29
      _bfd_error_handler
4514
29
  (_("%pB: warning: line number table read failed"), abfd);
4515
29
      return false;
4516
29
    }
4517
4518
28
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
28
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
28
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
28
  cache_ptr = lineno_cache;
4532
28
  asect->lineno = lineno_cache;
4533
28
  src = native_lineno;
4534
28
  nbr_func = 0;
4535
28
  have_func = false;
4536
4537
1.67k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
1.64k
    {
4539
1.64k
      struct internal_lineno dst;
4540
4541
1.64k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
1.64k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
1.64k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
1.64k
      if (cache_ptr->line_number == 0)
4549
277
  {
4550
277
    combined_entry_type * ent;
4551
277
    unsigned long symndx;
4552
277
    coff_symbol_type *sym;
4553
4554
277
    have_func = false;
4555
277
    symndx = dst.l_addr.l_symndx;
4556
277
    if (symndx >= obj_raw_syment_count (abfd))
4557
260
      {
4558
260
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
260
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
260
     abfd, symndx, counter);
4562
260
        cache_ptr->line_number = -1;
4563
260
        ret = false;
4564
260
        continue;
4565
260
      }
4566
4567
17
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
17
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
17
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
17
    if (sym < obj_symbols (abfd)
4584
17
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
17
    have_func = true;
4596
17
    nbr_func++;
4597
17
    cache_ptr->u.sym = (asymbol *) sym;
4598
17
    if (sym->lineno != NULL)
4599
6
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
6
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
6
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
17
    sym->lineno = cache_ptr;
4605
17
    if (sym->symbol.value < prev_offset)
4606
2
      ordered = false;
4607
17
    prev_offset = sym->symbol.value;
4608
17
  }
4609
1.36k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.36k
  continue;
4613
6
      else
4614
6
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
23
      cache_ptr++;
4616
23
    }
4617
4618
28
  asect->lineno_count = cache_ptr - lineno_cache;
4619
28
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
28
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
28
  if (!ordered)
4624
2
    {
4625
      /* Sort the table.  */
4626
2
      alent **func_table;
4627
2
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
2
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
2
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
2
  {
4637
2
    alent **p = func_table;
4638
2
    unsigned int i;
4639
4640
18
    for (i = 0; i < asect->lineno_count; i++)
4641
16
      if (lineno_cache[i].line_number == 0)
4642
10
        *p++ = &lineno_cache[i];
4643
4644
2
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
2
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
2
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
2
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
2
      {
4657
2
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
12
        for (i = 0; i < nbr_func; i++)
4660
10
    {
4661
10
      coff_symbol_type *sym;
4662
10
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
10
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
10
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
10
      do
4671
16
        *n_cache_ptr++ = *old_ptr++;
4672
16
      while (old_ptr->line_number != 0);
4673
10
    }
4674
4675
2
        memcpy (lineno_cache, n_lineno_cache,
4676
2
          asect->lineno_count * sizeof (alent));
4677
2
      }
4678
0
    else
4679
0
      ret = false;
4680
2
    bfd_release (abfd, func_table);
4681
2
  }
4682
0
      else
4683
0
  ret = false;
4684
2
    }
4685
4686
28
  return ret;
4687
28
}
coff-sh.c:coff_slurp_line_table
Line
Count
Source
4490
351
{
4491
351
  LINENO *native_lineno;
4492
351
  alent *lineno_cache;
4493
351
  unsigned int counter;
4494
351
  alent *cache_ptr;
4495
351
  bfd_vma prev_offset = 0;
4496
351
  bool ordered = true;
4497
351
  unsigned int nbr_func;
4498
351
  LINENO *src;
4499
351
  bool have_func;
4500
351
  bool ret = true;
4501
351
  size_t amt;
4502
4503
351
  if (asect->lineno_count == 0)
4504
292
    return true;
4505
4506
59
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
59
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
59
             asect->lineno_count,
4510
59
             bfd_coff_linesz (abfd));
4511
59
  if (native_lineno == NULL)
4512
37
    {
4513
37
      _bfd_error_handler
4514
37
  (_("%pB: warning: line number table read failed"), abfd);
4515
37
      return false;
4516
37
    }
4517
4518
22
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
22
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
22
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
22
  cache_ptr = lineno_cache;
4532
22
  asect->lineno = lineno_cache;
4533
22
  src = native_lineno;
4534
22
  nbr_func = 0;
4535
22
  have_func = false;
4536
4537
5.86k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
5.83k
    {
4539
5.83k
      struct internal_lineno dst;
4540
4541
5.83k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
5.83k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
5.83k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
5.83k
      if (cache_ptr->line_number == 0)
4549
1.49k
  {
4550
1.49k
    combined_entry_type * ent;
4551
1.49k
    unsigned long symndx;
4552
1.49k
    coff_symbol_type *sym;
4553
4554
1.49k
    have_func = false;
4555
1.49k
    symndx = dst.l_addr.l_symndx;
4556
1.49k
    if (symndx >= obj_raw_syment_count (abfd))
4557
836
      {
4558
836
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
836
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
836
     abfd, symndx, counter);
4562
836
        cache_ptr->line_number = -1;
4563
836
        ret = false;
4564
836
        continue;
4565
836
      }
4566
4567
654
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
654
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
654
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
654
    if (sym < obj_symbols (abfd)
4584
654
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
654
    have_func = true;
4596
654
    nbr_func++;
4597
654
    cache_ptr->u.sym = (asymbol *) sym;
4598
654
    if (sym->lineno != NULL)
4599
620
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
620
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
620
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
654
    sym->lineno = cache_ptr;
4605
654
    if (sym->symbol.value < prev_offset)
4606
6
      ordered = false;
4607
654
    prev_offset = sym->symbol.value;
4608
654
  }
4609
4.34k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
2.46k
  continue;
4613
1.88k
      else
4614
1.88k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
2.53k
      cache_ptr++;
4616
2.53k
    }
4617
4618
22
  asect->lineno_count = cache_ptr - lineno_cache;
4619
22
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
22
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
22
  if (!ordered)
4624
5
    {
4625
      /* Sort the table.  */
4626
5
      alent **func_table;
4627
5
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
5
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
5
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
5
  {
4637
5
    alent **p = func_table;
4638
5
    unsigned int i;
4639
4640
929
    for (i = 0; i < asect->lineno_count; i++)
4641
924
      if (lineno_cache[i].line_number == 0)
4642
270
        *p++ = &lineno_cache[i];
4643
4644
5
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
5
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
5
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
5
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
5
      {
4657
5
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
275
        for (i = 0; i < nbr_func; i++)
4660
270
    {
4661
270
      coff_symbol_type *sym;
4662
270
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
270
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
270
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
270
      do
4671
924
        *n_cache_ptr++ = *old_ptr++;
4672
924
      while (old_ptr->line_number != 0);
4673
270
    }
4674
4675
5
        memcpy (lineno_cache, n_lineno_cache,
4676
5
          asect->lineno_count * sizeof (alent));
4677
5
      }
4678
0
    else
4679
0
      ret = false;
4680
5
    bfd_release (abfd, func_table);
4681
5
  }
4682
0
      else
4683
0
  ret = false;
4684
5
    }
4685
4686
22
  return ret;
4687
22
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_line_table
coff-tic30.c:coff_slurp_line_table
Line
Count
Source
4490
234
{
4491
234
  LINENO *native_lineno;
4492
234
  alent *lineno_cache;
4493
234
  unsigned int counter;
4494
234
  alent *cache_ptr;
4495
234
  bfd_vma prev_offset = 0;
4496
234
  bool ordered = true;
4497
234
  unsigned int nbr_func;
4498
234
  LINENO *src;
4499
234
  bool have_func;
4500
234
  bool ret = true;
4501
234
  size_t amt;
4502
4503
234
  if (asect->lineno_count == 0)
4504
92
    return true;
4505
4506
142
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
142
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
142
             asect->lineno_count,
4510
142
             bfd_coff_linesz (abfd));
4511
142
  if (native_lineno == NULL)
4512
30
    {
4513
30
      _bfd_error_handler
4514
30
  (_("%pB: warning: line number table read failed"), abfd);
4515
30
      return false;
4516
30
    }
4517
4518
112
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
112
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
112
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
112
  cache_ptr = lineno_cache;
4532
112
  asect->lineno = lineno_cache;
4533
112
  src = native_lineno;
4534
112
  nbr_func = 0;
4535
112
  have_func = false;
4536
4537
375k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
375k
    {
4539
375k
      struct internal_lineno dst;
4540
4541
375k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
375k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
375k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
375k
      if (cache_ptr->line_number == 0)
4549
95.7k
  {
4550
95.7k
    combined_entry_type * ent;
4551
95.7k
    unsigned long symndx;
4552
95.7k
    coff_symbol_type *sym;
4553
4554
95.7k
    have_func = false;
4555
95.7k
    symndx = dst.l_addr.l_symndx;
4556
95.7k
    if (symndx >= obj_raw_syment_count (abfd))
4557
93.0k
      {
4558
93.0k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
93.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
93.0k
     abfd, symndx, counter);
4562
93.0k
        cache_ptr->line_number = -1;
4563
93.0k
        ret = false;
4564
93.0k
        continue;
4565
93.0k
      }
4566
4567
2.72k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
2.72k
    if (! ent->is_sym)
4571
7
      {
4572
7
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
7
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
7
     abfd, symndx, counter);
4576
7
        cache_ptr->line_number = -1;
4577
7
        ret = false;
4578
7
        continue;
4579
7
      }
4580
2.71k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
2.71k
    if (sym < obj_symbols (abfd)
4584
2.71k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
2.71k
    have_func = true;
4596
2.71k
    nbr_func++;
4597
2.71k
    cache_ptr->u.sym = (asymbol *) sym;
4598
2.71k
    if (sym->lineno != NULL)
4599
2.69k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
2.69k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
2.69k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
2.71k
    sym->lineno = cache_ptr;
4605
2.71k
    if (sym->symbol.value < prev_offset)
4606
12
      ordered = false;
4607
2.71k
    prev_offset = sym->symbol.value;
4608
2.71k
  }
4609
279k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
278k
  continue;
4613
423
      else
4614
423
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
3.13k
      cache_ptr++;
4616
3.13k
    }
4617
4618
112
  asect->lineno_count = cache_ptr - lineno_cache;
4619
112
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
112
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
112
  if (!ordered)
4624
6
    {
4625
      /* Sort the table.  */
4626
6
      alent **func_table;
4627
6
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
6
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
6
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
6
  {
4637
6
    alent **p = func_table;
4638
6
    unsigned int i;
4639
4640
2.96k
    for (i = 0; i < asect->lineno_count; i++)
4641
2.96k
      if (lineno_cache[i].line_number == 0)
4642
2.65k
        *p++ = &lineno_cache[i];
4643
4644
6
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
6
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
6
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
6
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
6
      {
4657
6
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
2.65k
        for (i = 0; i < nbr_func; i++)
4660
2.65k
    {
4661
2.65k
      coff_symbol_type *sym;
4662
2.65k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
2.65k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
2.65k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
2.65k
      do
4671
2.96k
        *n_cache_ptr++ = *old_ptr++;
4672
2.96k
      while (old_ptr->line_number != 0);
4673
2.65k
    }
4674
4675
6
        memcpy (lineno_cache, n_lineno_cache,
4676
6
          asect->lineno_count * sizeof (alent));
4677
6
      }
4678
0
    else
4679
0
      ret = false;
4680
6
    bfd_release (abfd, func_table);
4681
6
  }
4682
0
      else
4683
0
  ret = false;
4684
6
    }
4685
4686
112
  return ret;
4687
112
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_line_table
coff-tic54x.c:coff_slurp_line_table
Line
Count
Source
4490
117
{
4491
117
  LINENO *native_lineno;
4492
117
  alent *lineno_cache;
4493
117
  unsigned int counter;
4494
117
  alent *cache_ptr;
4495
117
  bfd_vma prev_offset = 0;
4496
117
  bool ordered = true;
4497
117
  unsigned int nbr_func;
4498
117
  LINENO *src;
4499
117
  bool have_func;
4500
117
  bool ret = true;
4501
117
  size_t amt;
4502
4503
117
  if (asect->lineno_count == 0)
4504
64
    return true;
4505
4506
53
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
53
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
53
             asect->lineno_count,
4510
53
             bfd_coff_linesz (abfd));
4511
53
  if (native_lineno == NULL)
4512
25
    {
4513
25
      _bfd_error_handler
4514
25
  (_("%pB: warning: line number table read failed"), abfd);
4515
25
      return false;
4516
25
    }
4517
4518
28
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
28
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
28
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
28
  cache_ptr = lineno_cache;
4532
28
  asect->lineno = lineno_cache;
4533
28
  src = native_lineno;
4534
28
  nbr_func = 0;
4535
28
  have_func = false;
4536
4537
3.54k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
3.52k
    {
4539
3.52k
      struct internal_lineno dst;
4540
4541
3.52k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
3.52k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
3.52k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
3.52k
      if (cache_ptr->line_number == 0)
4549
1.02k
  {
4550
1.02k
    combined_entry_type * ent;
4551
1.02k
    unsigned long symndx;
4552
1.02k
    coff_symbol_type *sym;
4553
4554
1.02k
    have_func = false;
4555
1.02k
    symndx = dst.l_addr.l_symndx;
4556
1.02k
    if (symndx >= obj_raw_syment_count (abfd))
4557
486
      {
4558
486
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
486
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
486
     abfd, symndx, counter);
4562
486
        cache_ptr->line_number = -1;
4563
486
        ret = false;
4564
486
        continue;
4565
486
      }
4566
4567
535
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
535
    if (! ent->is_sym)
4571
8
      {
4572
8
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
8
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
8
     abfd, symndx, counter);
4576
8
        cache_ptr->line_number = -1;
4577
8
        ret = false;
4578
8
        continue;
4579
8
      }
4580
527
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
527
    if (sym < obj_symbols (abfd)
4584
527
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
527
    have_func = true;
4596
527
    nbr_func++;
4597
527
    cache_ptr->u.sym = (asymbol *) sym;
4598
527
    if (sym->lineno != NULL)
4599
492
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
492
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
492
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
527
    sym->lineno = cache_ptr;
4605
527
    if (sym->symbol.value < prev_offset)
4606
9
      ordered = false;
4607
527
    prev_offset = sym->symbol.value;
4608
527
  }
4609
2.50k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.88k
  continue;
4613
611
      else
4614
611
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
1.13k
      cache_ptr++;
4616
1.13k
    }
4617
4618
28
  asect->lineno_count = cache_ptr - lineno_cache;
4619
28
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
28
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
28
  if (!ordered)
4624
8
    {
4625
      /* Sort the table.  */
4626
8
      alent **func_table;
4627
8
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
8
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
8
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
8
  {
4637
8
    alent **p = func_table;
4638
8
    unsigned int i;
4639
4640
516
    for (i = 0; i < asect->lineno_count; i++)
4641
508
      if (lineno_cache[i].line_number == 0)
4642
259
        *p++ = &lineno_cache[i];
4643
4644
8
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
8
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
8
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
8
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
8
      {
4657
8
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
267
        for (i = 0; i < nbr_func; i++)
4660
259
    {
4661
259
      coff_symbol_type *sym;
4662
259
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
259
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
259
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
259
      do
4671
508
        *n_cache_ptr++ = *old_ptr++;
4672
508
      while (old_ptr->line_number != 0);
4673
259
    }
4674
4675
8
        memcpy (lineno_cache, n_lineno_cache,
4676
8
          asect->lineno_count * sizeof (alent));
4677
8
      }
4678
0
    else
4679
0
      ret = false;
4680
8
    bfd_release (abfd, func_table);
4681
8
  }
4682
0
      else
4683
0
  ret = false;
4684
8
    }
4685
4686
28
  return ret;
4687
28
}
coff-z80.c:coff_slurp_line_table
Line
Count
Source
4490
135
{
4491
135
  LINENO *native_lineno;
4492
135
  alent *lineno_cache;
4493
135
  unsigned int counter;
4494
135
  alent *cache_ptr;
4495
135
  bfd_vma prev_offset = 0;
4496
135
  bool ordered = true;
4497
135
  unsigned int nbr_func;
4498
135
  LINENO *src;
4499
135
  bool have_func;
4500
135
  bool ret = true;
4501
135
  size_t amt;
4502
4503
135
  if (asect->lineno_count == 0)
4504
77
    return true;
4505
4506
58
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
58
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
58
             asect->lineno_count,
4510
58
             bfd_coff_linesz (abfd));
4511
58
  if (native_lineno == NULL)
4512
12
    {
4513
12
      _bfd_error_handler
4514
12
  (_("%pB: warning: line number table read failed"), abfd);
4515
12
      return false;
4516
12
    }
4517
4518
46
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
46
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
46
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
46
  cache_ptr = lineno_cache;
4532
46
  asect->lineno = lineno_cache;
4533
46
  src = native_lineno;
4534
46
  nbr_func = 0;
4535
46
  have_func = false;
4536
4537
4.40k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
4.35k
    {
4539
4.35k
      struct internal_lineno dst;
4540
4541
4.35k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
4.35k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
4.35k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
4.35k
      if (cache_ptr->line_number == 0)
4549
1.44k
  {
4550
1.44k
    combined_entry_type * ent;
4551
1.44k
    unsigned long symndx;
4552
1.44k
    coff_symbol_type *sym;
4553
4554
1.44k
    have_func = false;
4555
1.44k
    symndx = dst.l_addr.l_symndx;
4556
1.44k
    if (symndx >= obj_raw_syment_count (abfd))
4557
456
      {
4558
456
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
456
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
456
     abfd, symndx, counter);
4562
456
        cache_ptr->line_number = -1;
4563
456
        ret = false;
4564
456
        continue;
4565
456
      }
4566
4567
990
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
990
    if (! ent->is_sym)
4571
160
      {
4572
160
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
160
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
160
     abfd, symndx, counter);
4576
160
        cache_ptr->line_number = -1;
4577
160
        ret = false;
4578
160
        continue;
4579
160
      }
4580
830
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
830
    if (sym < obj_symbols (abfd)
4584
830
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
830
    have_func = true;
4596
830
    nbr_func++;
4597
830
    cache_ptr->u.sym = (asymbol *) sym;
4598
830
    if (sym->lineno != NULL)
4599
804
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
804
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
804
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
830
    sym->lineno = cache_ptr;
4605
830
    if (sym->symbol.value < prev_offset)
4606
22
      ordered = false;
4607
830
    prev_offset = sym->symbol.value;
4608
830
  }
4609
2.91k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
1.16k
  continue;
4613
1.75k
      else
4614
1.75k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
2.58k
      cache_ptr++;
4616
2.58k
    }
4617
4618
46
  asect->lineno_count = cache_ptr - lineno_cache;
4619
46
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
46
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
46
  if (!ordered)
4624
1
    {
4625
      /* Sort the table.  */
4626
1
      alent **func_table;
4627
1
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
1
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
1
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
1
  {
4637
1
    alent **p = func_table;
4638
1
    unsigned int i;
4639
4640
1.91k
    for (i = 0; i < asect->lineno_count; i++)
4641
1.91k
      if (lineno_cache[i].line_number == 0)
4642
683
        *p++ = &lineno_cache[i];
4643
4644
1
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
1
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
1
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
1
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
1
      {
4657
1
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
684
        for (i = 0; i < nbr_func; i++)
4660
683
    {
4661
683
      coff_symbol_type *sym;
4662
683
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
683
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
683
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
683
      do
4671
1.91k
        *n_cache_ptr++ = *old_ptr++;
4672
1.91k
      while (old_ptr->line_number != 0);
4673
683
    }
4674
4675
1
        memcpy (lineno_cache, n_lineno_cache,
4676
1
          asect->lineno_count * sizeof (alent));
4677
1
      }
4678
0
    else
4679
0
      ret = false;
4680
1
    bfd_release (abfd, func_table);
4681
1
  }
4682
0
      else
4683
0
  ret = false;
4684
1
    }
4685
4686
46
  return ret;
4687
46
}
coff-z8k.c:coff_slurp_line_table
Line
Count
Source
4490
176
{
4491
176
  LINENO *native_lineno;
4492
176
  alent *lineno_cache;
4493
176
  unsigned int counter;
4494
176
  alent *cache_ptr;
4495
176
  bfd_vma prev_offset = 0;
4496
176
  bool ordered = true;
4497
176
  unsigned int nbr_func;
4498
176
  LINENO *src;
4499
176
  bool have_func;
4500
176
  bool ret = true;
4501
176
  size_t amt;
4502
4503
176
  if (asect->lineno_count == 0)
4504
94
    return true;
4505
4506
82
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
82
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
82
             asect->lineno_count,
4510
82
             bfd_coff_linesz (abfd));
4511
82
  if (native_lineno == NULL)
4512
40
    {
4513
40
      _bfd_error_handler
4514
40
  (_("%pB: warning: line number table read failed"), abfd);
4515
40
      return false;
4516
40
    }
4517
4518
42
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
42
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
42
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
42
  cache_ptr = lineno_cache;
4532
42
  asect->lineno = lineno_cache;
4533
42
  src = native_lineno;
4534
42
  nbr_func = 0;
4535
42
  have_func = false;
4536
4537
1.58k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
1.53k
    {
4539
1.53k
      struct internal_lineno dst;
4540
4541
1.53k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
1.53k
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
1.53k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
1.53k
      if (cache_ptr->line_number == 0)
4549
254
  {
4550
254
    combined_entry_type * ent;
4551
254
    unsigned long symndx;
4552
254
    coff_symbol_type *sym;
4553
4554
254
    have_func = false;
4555
254
    symndx = dst.l_addr.l_symndx;
4556
254
    if (symndx >= obj_raw_syment_count (abfd))
4557
108
      {
4558
108
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
108
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
108
     abfd, symndx, counter);
4562
108
        cache_ptr->line_number = -1;
4563
108
        ret = false;
4564
108
        continue;
4565
108
      }
4566
4567
146
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
146
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
146
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
146
    if (sym < obj_symbols (abfd)
4584
146
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
146
    have_func = true;
4596
146
    nbr_func++;
4597
146
    cache_ptr->u.sym = (asymbol *) sym;
4598
146
    if (sym->lineno != NULL)
4599
124
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
124
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
124
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
146
    sym->lineno = cache_ptr;
4605
146
    if (sym->symbol.value < prev_offset)
4606
4
      ordered = false;
4607
146
    prev_offset = sym->symbol.value;
4608
146
  }
4609
1.28k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
869
  continue;
4613
416
      else
4614
416
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
562
      cache_ptr++;
4616
562
    }
4617
4618
42
  asect->lineno_count = cache_ptr - lineno_cache;
4619
42
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
42
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
42
  if (!ordered)
4624
4
    {
4625
      /* Sort the table.  */
4626
4
      alent **func_table;
4627
4
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
4
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
4
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
4
  {
4637
4
    alent **p = func_table;
4638
4
    unsigned int i;
4639
4640
107
    for (i = 0; i < asect->lineno_count; i++)
4641
103
      if (lineno_cache[i].line_number == 0)
4642
40
        *p++ = &lineno_cache[i];
4643
4644
4
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
4
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
4
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
4
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
4
      {
4657
4
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
44
        for (i = 0; i < nbr_func; i++)
4660
40
    {
4661
40
      coff_symbol_type *sym;
4662
40
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
40
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
40
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
40
      do
4671
103
        *n_cache_ptr++ = *old_ptr++;
4672
103
      while (old_ptr->line_number != 0);
4673
40
    }
4674
4675
4
        memcpy (lineno_cache, n_lineno_cache,
4676
4
          asect->lineno_count * sizeof (alent));
4677
4
      }
4678
0
    else
4679
0
      ret = false;
4680
4
    bfd_release (abfd, func_table);
4681
4
  }
4682
0
      else
4683
0
  ret = false;
4684
4
    }
4685
4686
42
  return ret;
4687
42
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_line_table
Unexecuted instantiation: pe-arm.c:coff_slurp_line_table
pe-i386.c:coff_slurp_line_table
Line
Count
Source
4490
39
{
4491
39
  LINENO *native_lineno;
4492
39
  alent *lineno_cache;
4493
39
  unsigned int counter;
4494
39
  alent *cache_ptr;
4495
39
  bfd_vma prev_offset = 0;
4496
39
  bool ordered = true;
4497
39
  unsigned int nbr_func;
4498
39
  LINENO *src;
4499
39
  bool have_func;
4500
39
  bool ret = true;
4501
39
  size_t amt;
4502
4503
39
  if (asect->lineno_count == 0)
4504
23
    return true;
4505
4506
16
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
16
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
16
             asect->lineno_count,
4510
16
             bfd_coff_linesz (abfd));
4511
16
  if (native_lineno == NULL)
4512
6
    {
4513
6
      _bfd_error_handler
4514
6
  (_("%pB: warning: line number table read failed"), abfd);
4515
6
      return false;
4516
6
    }
4517
4518
10
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
10
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
10
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
10
  cache_ptr = lineno_cache;
4532
10
  asect->lineno = lineno_cache;
4533
10
  src = native_lineno;
4534
10
  nbr_func = 0;
4535
10
  have_func = false;
4536
4537
192
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
182
    {
4539
182
      struct internal_lineno dst;
4540
4541
182
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
182
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
182
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
182
      if (cache_ptr->line_number == 0)
4549
60
  {
4550
60
    combined_entry_type * ent;
4551
60
    unsigned long symndx;
4552
60
    coff_symbol_type *sym;
4553
4554
60
    have_func = false;
4555
60
    symndx = dst.l_addr.l_symndx;
4556
60
    if (symndx >= obj_raw_syment_count (abfd))
4557
23
      {
4558
23
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
23
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
23
     abfd, symndx, counter);
4562
23
        cache_ptr->line_number = -1;
4563
23
        ret = false;
4564
23
        continue;
4565
23
      }
4566
4567
37
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
37
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
37
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
37
    if (sym < obj_symbols (abfd)
4584
37
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
37
    have_func = true;
4596
37
    nbr_func++;
4597
37
    cache_ptr->u.sym = (asymbol *) sym;
4598
37
    if (sym->lineno != NULL)
4599
31
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
31
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
31
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
37
    sym->lineno = cache_ptr;
4605
37
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
37
    prev_offset = sym->symbol.value;
4608
37
  }
4609
122
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
48
  continue;
4613
74
      else
4614
74
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
111
      cache_ptr++;
4616
111
    }
4617
4618
10
  asect->lineno_count = cache_ptr - lineno_cache;
4619
10
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
10
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
10
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
10
  return ret;
4687
10
}
pe-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
134
{
4491
134
  LINENO *native_lineno;
4492
134
  alent *lineno_cache;
4493
134
  unsigned int counter;
4494
134
  alent *cache_ptr;
4495
134
  bfd_vma prev_offset = 0;
4496
134
  bool ordered = true;
4497
134
  unsigned int nbr_func;
4498
134
  LINENO *src;
4499
134
  bool have_func;
4500
134
  bool ret = true;
4501
134
  size_t amt;
4502
4503
134
  if (asect->lineno_count == 0)
4504
126
    return true;
4505
4506
8
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
8
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
8
             asect->lineno_count,
4510
8
             bfd_coff_linesz (abfd));
4511
8
  if (native_lineno == NULL)
4512
5
    {
4513
5
      _bfd_error_handler
4514
5
  (_("%pB: warning: line number table read failed"), abfd);
4515
5
      return false;
4516
5
    }
4517
4518
3
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
3
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
3
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
3
  cache_ptr = lineno_cache;
4532
3
  asect->lineno = lineno_cache;
4533
3
  src = native_lineno;
4534
3
  nbr_func = 0;
4535
3
  have_func = false;
4536
4537
12
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
9
    {
4539
9
      struct internal_lineno dst;
4540
4541
9
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
9
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
9
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
9
      if (cache_ptr->line_number == 0)
4549
6
  {
4550
6
    combined_entry_type * ent;
4551
6
    unsigned long symndx;
4552
6
    coff_symbol_type *sym;
4553
4554
6
    have_func = false;
4555
6
    symndx = dst.l_addr.l_symndx;
4556
6
    if (symndx >= obj_raw_syment_count (abfd))
4557
6
      {
4558
6
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
6
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
6
     abfd, symndx, counter);
4562
6
        cache_ptr->line_number = -1;
4563
6
        ret = false;
4564
6
        continue;
4565
6
      }
4566
4567
0
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
0
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
0
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
0
    if (sym < obj_symbols (abfd)
4584
0
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
0
    have_func = true;
4596
0
    nbr_func++;
4597
0
    cache_ptr->u.sym = (asymbol *) sym;
4598
0
    if (sym->lineno != NULL)
4599
0
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
0
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
0
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
0
    sym->lineno = cache_ptr;
4605
0
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
0
    prev_offset = sym->symbol.value;
4608
0
  }
4609
3
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
3
  continue;
4613
0
      else
4614
0
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
0
      cache_ptr++;
4616
0
    }
4617
4618
3
  asect->lineno_count = cache_ptr - lineno_cache;
4619
3
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
3
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
3
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
3
  return ret;
4687
3
}
pe-sh.c:coff_slurp_line_table
Line
Count
Source
4490
54
{
4491
54
  LINENO *native_lineno;
4492
54
  alent *lineno_cache;
4493
54
  unsigned int counter;
4494
54
  alent *cache_ptr;
4495
54
  bfd_vma prev_offset = 0;
4496
54
  bool ordered = true;
4497
54
  unsigned int nbr_func;
4498
54
  LINENO *src;
4499
54
  bool have_func;
4500
54
  bool ret = true;
4501
54
  size_t amt;
4502
4503
54
  if (asect->lineno_count == 0)
4504
32
    return true;
4505
4506
22
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
22
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
22
             asect->lineno_count,
4510
22
             bfd_coff_linesz (abfd));
4511
22
  if (native_lineno == NULL)
4512
8
    {
4513
8
      _bfd_error_handler
4514
8
  (_("%pB: warning: line number table read failed"), abfd);
4515
8
      return false;
4516
8
    }
4517
4518
14
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
14
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
14
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
14
  cache_ptr = lineno_cache;
4532
14
  asect->lineno = lineno_cache;
4533
14
  src = native_lineno;
4534
14
  nbr_func = 0;
4535
14
  have_func = false;
4536
4537
389
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
375
    {
4539
375
      struct internal_lineno dst;
4540
4541
375
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
375
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
375
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
375
      if (cache_ptr->line_number == 0)
4549
206
  {
4550
206
    combined_entry_type * ent;
4551
206
    unsigned long symndx;
4552
206
    coff_symbol_type *sym;
4553
4554
206
    have_func = false;
4555
206
    symndx = dst.l_addr.l_symndx;
4556
206
    if (symndx >= obj_raw_syment_count (abfd))
4557
23
      {
4558
23
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
23
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
23
     abfd, symndx, counter);
4562
23
        cache_ptr->line_number = -1;
4563
23
        ret = false;
4564
23
        continue;
4565
23
      }
4566
4567
183
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
183
    if (! ent->is_sym)
4571
1
      {
4572
1
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1
     abfd, symndx, counter);
4576
1
        cache_ptr->line_number = -1;
4577
1
        ret = false;
4578
1
        continue;
4579
1
      }
4580
182
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
182
    if (sym < obj_symbols (abfd)
4584
182
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
182
    have_func = true;
4596
182
    nbr_func++;
4597
182
    cache_ptr->u.sym = (asymbol *) sym;
4598
182
    if (sym->lineno != NULL)
4599
171
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
171
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
171
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
182
    sym->lineno = cache_ptr;
4605
182
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
182
    prev_offset = sym->symbol.value;
4608
182
  }
4609
169
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
49
  continue;
4613
120
      else
4614
120
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
302
      cache_ptr++;
4616
302
    }
4617
4618
14
  asect->lineno_count = cache_ptr - lineno_cache;
4619
14
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
14
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
14
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
14
  return ret;
4687
14
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_line_table
Unexecuted instantiation: pei-arm.c:coff_slurp_line_table
pei-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
5
{
4491
5
  LINENO *native_lineno;
4492
5
  alent *lineno_cache;
4493
5
  unsigned int counter;
4494
5
  alent *cache_ptr;
4495
5
  bfd_vma prev_offset = 0;
4496
5
  bool ordered = true;
4497
5
  unsigned int nbr_func;
4498
5
  LINENO *src;
4499
5
  bool have_func;
4500
5
  bool ret = true;
4501
5
  size_t amt;
4502
4503
5
  if (asect->lineno_count == 0)
4504
1
    return true;
4505
4506
4
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
4
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
4
             asect->lineno_count,
4510
4
             bfd_coff_linesz (abfd));
4511
4
  if (native_lineno == NULL)
4512
1
    {
4513
1
      _bfd_error_handler
4514
1
  (_("%pB: warning: line number table read failed"), abfd);
4515
1
      return false;
4516
1
    }
4517
4518
3
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
3
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
3
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
3
  cache_ptr = lineno_cache;
4532
3
  asect->lineno = lineno_cache;
4533
3
  src = native_lineno;
4534
3
  nbr_func = 0;
4535
3
  have_func = false;
4536
4537
30
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
27
    {
4539
27
      struct internal_lineno dst;
4540
4541
27
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
27
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
27
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
27
      if (cache_ptr->line_number == 0)
4549
11
  {
4550
11
    combined_entry_type * ent;
4551
11
    unsigned long symndx;
4552
11
    coff_symbol_type *sym;
4553
4554
11
    have_func = false;
4555
11
    symndx = dst.l_addr.l_symndx;
4556
11
    if (symndx >= obj_raw_syment_count (abfd))
4557
4
      {
4558
4
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
4
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
4
     abfd, symndx, counter);
4562
4
        cache_ptr->line_number = -1;
4563
4
        ret = false;
4564
4
        continue;
4565
4
      }
4566
4567
7
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
7
    if (! ent->is_sym)
4571
0
      {
4572
0
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
0
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
0
     abfd, symndx, counter);
4576
0
        cache_ptr->line_number = -1;
4577
0
        ret = false;
4578
0
        continue;
4579
0
      }
4580
7
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
7
    if (sym < obj_symbols (abfd)
4584
7
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
7
    have_func = true;
4596
7
    nbr_func++;
4597
7
    cache_ptr->u.sym = (asymbol *) sym;
4598
7
    if (sym->lineno != NULL)
4599
4
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
4
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
4
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
7
    sym->lineno = cache_ptr;
4605
7
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
7
    prev_offset = sym->symbol.value;
4608
7
  }
4609
16
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
4
  continue;
4613
12
      else
4614
12
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
19
      cache_ptr++;
4616
19
    }
4617
4618
3
  asect->lineno_count = cache_ptr - lineno_cache;
4619
3
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
3
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
3
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
3
  return ret;
4687
3
}
pei-sh.c:coff_slurp_line_table
Line
Count
Source
4490
11
{
4491
11
  LINENO *native_lineno;
4492
11
  alent *lineno_cache;
4493
11
  unsigned int counter;
4494
11
  alent *cache_ptr;
4495
11
  bfd_vma prev_offset = 0;
4496
11
  bool ordered = true;
4497
11
  unsigned int nbr_func;
4498
11
  LINENO *src;
4499
11
  bool have_func;
4500
11
  bool ret = true;
4501
11
  size_t amt;
4502
4503
11
  if (asect->lineno_count == 0)
4504
3
    return true;
4505
4506
8
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
8
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
8
             asect->lineno_count,
4510
8
             bfd_coff_linesz (abfd));
4511
8
  if (native_lineno == NULL)
4512
1
    {
4513
1
      _bfd_error_handler
4514
1
  (_("%pB: warning: line number table read failed"), abfd);
4515
1
      return false;
4516
1
    }
4517
4518
7
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
7
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
7
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
7
  cache_ptr = lineno_cache;
4532
7
  asect->lineno = lineno_cache;
4533
7
  src = native_lineno;
4534
7
  nbr_func = 0;
4535
7
  have_func = false;
4536
4537
385
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
378
    {
4539
378
      struct internal_lineno dst;
4540
4541
378
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
378
      cache_ptr->line_number = dst.l_lnno;
4543
      /* Appease memory checkers that get all excited about
4544
   uninitialised memory when copying alents if u.offset is
4545
   larger than u.sym.  (64-bit BFD on 32-bit host.)  */
4546
378
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
378
      if (cache_ptr->line_number == 0)
4549
120
  {
4550
120
    combined_entry_type * ent;
4551
120
    unsigned long symndx;
4552
120
    coff_symbol_type *sym;
4553
4554
120
    have_func = false;
4555
120
    symndx = dst.l_addr.l_symndx;
4556
120
    if (symndx >= obj_raw_syment_count (abfd))
4557
71
      {
4558
71
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
71
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
71
     abfd, symndx, counter);
4562
71
        cache_ptr->line_number = -1;
4563
71
        ret = false;
4564
71
        continue;
4565
71
      }
4566
4567
49
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
49
    if (! ent->is_sym)
4571
4
      {
4572
4
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
4
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
4
     abfd, symndx, counter);
4576
4
        cache_ptr->line_number = -1;
4577
4
        ret = false;
4578
4
        continue;
4579
4
      }
4580
45
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
45
    if (sym < obj_symbols (abfd)
4584
45
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
45
    have_func = true;
4596
45
    nbr_func++;
4597
45
    cache_ptr->u.sym = (asymbol *) sym;
4598
45
    if (sym->lineno != NULL)
4599
39
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
39
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
39
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
45
    sym->lineno = cache_ptr;
4605
45
    if (sym->symbol.value < prev_offset)
4606
0
      ordered = false;
4607
45
    prev_offset = sym->symbol.value;
4608
45
  }
4609
258
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
238
  continue;
4613
20
      else
4614
20
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
65
      cache_ptr++;
4616
65
    }
4617
4618
7
  asect->lineno_count = cache_ptr - lineno_cache;
4619
7
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
7
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
7
  if (!ordered)
4624
0
    {
4625
      /* Sort the table.  */
4626
0
      alent **func_table;
4627
0
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
0
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
0
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
0
  {
4637
0
    alent **p = func_table;
4638
0
    unsigned int i;
4639
4640
0
    for (i = 0; i < asect->lineno_count; i++)
4641
0
      if (lineno_cache[i].line_number == 0)
4642
0
        *p++ = &lineno_cache[i];
4643
4644
0
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
0
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
0
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
0
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
0
      {
4657
0
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
0
        for (i = 0; i < nbr_func; i++)
4660
0
    {
4661
0
      coff_symbol_type *sym;
4662
0
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
0
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
0
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
0
      do
4671
0
        *n_cache_ptr++ = *old_ptr++;
4672
0
      while (old_ptr->line_number != 0);
4673
0
    }
4674
4675
0
        memcpy (lineno_cache, n_lineno_cache,
4676
0
          asect->lineno_count * sizeof (alent));
4677
0
      }
4678
0
    else
4679
0
      ret = false;
4680
0
    bfd_release (abfd, func_table);
4681
0
  }
4682
0
      else
4683
0
  ret = false;
4684
0
    }
4685
4686
7
  return ret;
4687
7
}
4688
4689
/* Slurp in the symbol table, converting it to generic form.  Note
4690
   that if coff_relocate_section is defined, the linker will read
4691
   symbols via coff_link_add_symbols, rather than via this routine.  */
4692
4693
static bool
4694
coff_slurp_symbol_table (bfd * abfd)
4695
16.1k
{
4696
16.1k
  combined_entry_type *native_symbols;
4697
16.1k
  coff_symbol_type *cached_area;
4698
16.1k
  unsigned int *table_ptr;
4699
16.1k
  unsigned int number_of_symbols = 0;
4700
16.1k
  bool ret = true;
4701
16.1k
  size_t amt;
4702
4703
16.1k
  if (obj_symbols (abfd))
4704
11.0k
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
5.11k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
4.17k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
933
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
933
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
933
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
933
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
933
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
933
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
933
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
933
  if (table_ptr == NULL)
4729
0
    return false;
4730
933
  else
4731
933
    {
4732
933
      coff_symbol_type *dst = cached_area;
4733
933
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
933
      unsigned int this_index = 0;
4735
4736
12.8k
      while (this_index < last_native_index)
4737
11.9k
  {
4738
11.9k
    combined_entry_type *src = native_symbols + this_index;
4739
11.9k
    table_ptr[this_index] = number_of_symbols;
4740
4741
11.9k
    dst->symbol.the_bfd = abfd;
4742
11.9k
    BFD_ASSERT (src->is_sym);
4743
11.9k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
11.9k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
11.9k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
11.9k
                 src->u.syment.n_scnum);
4748
11.9k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
11.9k
    dst->symbol.value = 0;
4751
11.9k
    dst->done_lineno = false;
4752
4753
11.9k
    switch (src->u.syment.n_sclass)
4754
11.9k
      {
4755
307
      case C_EXT:
4756
349
      case C_WEAKEXT:
4757
#if defined ARM
4758
0
      case C_THUMBEXT:
4759
0
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
31
      case C_HIDEXT:
4763
31
#ifndef AIX_WEAK_SUPPORT
4764
35
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
35
#ifdef C_SYSTEM
4768
373
      case C_SYSTEM: /* System Wide variable.  */
4769
373
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
285
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
286
      case C_NT_WEAK:
4775
#endif
4776
286
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
286
    {
4778
250
    case COFF_SYMBOL_GLOBAL:
4779
250
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
250
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
69
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
250
      break;
4793
4794
46
    case COFF_SYMBOL_COMMON:
4795
46
      dst->symbol.section = bfd_com_section_ptr;
4796
46
      dst->symbol.value = src->u.syment.n_value;
4797
46
      break;
4798
4799
73
    case COFF_SYMBOL_UNDEFINED:
4800
73
      dst->symbol.section = bfd_und_section_ptr;
4801
73
      dst->symbol.value = 0;
4802
73
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
7
    case COFF_SYMBOL_LOCAL:
4810
7
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
7
      if (ISFCN ((src->u.syment.n_type)))
4820
3
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
7
      break;
4822
286
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
40
        if (src->u.syment.n_numaux > 0)
4827
35
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
286
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1
    dst->symbol.flags |= BSF_WEAK;
4833
4834
286
        if (src->u.syment.n_sclass == C_SECTION
4835
286
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
376
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
30
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
50
      )
4843
46
    dst->symbol.flags |= BSF_WEAK;
4844
4845
50
        break;
4846
4847
631
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
0
      case C_THUMBSTAT:    /* Thumb static.  */
4850
0
      case C_THUMBLABEL:   /* Thumb label.  */
4851
0
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
23
      case C_DWARF:  /* A label in a dwarf section.  */
4855
28
      case C_INFO:  /* A label in a comment section.  */
4856
#endif
4857
655
      case C_LABEL:  /* Label.  */
4858
655
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
655
        else
4861
655
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
655
        if (dst->symbol.section)
4866
655
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
655
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
655
        break;
4879
4880
77
      case C_FILE: /* File name.  */
4881
77
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
96
      case C_MOS:   /* Member of structure.  */
4884
101
      case C_EOS:   /* End of structure.  */
4885
111
      case C_REGPARM: /* Register parameter.  */
4886
146
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
221
      case C_TPDEF: /* Type definition.  */
4889
234
      case C_ARG:
4890
501
      case C_AUTO: /* Automatic variable.  */
4891
513
      case C_FIELD: /* Bit field.  */
4892
528
      case C_ENTAG: /* Enumeration tag.  */
4893
574
      case C_MOE:   /* Member of enumeration.  */
4894
584
      case C_MOU:   /* Member of union.  */
4895
608
      case C_UNTAG: /* Union tag.  */
4896
626
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
322
      case C_GSYM:
4899
475
      case C_LSYM:
4900
483
      case C_PSYM:
4901
485
      case C_RSYM:
4902
488
      case C_RPSYM:
4903
491
      case C_STSYM:
4904
493
      case C_TCSYM:
4905
500
      case C_BCOMM:
4906
511
      case C_ECOML:
4907
512
      case C_ECOMM:
4908
515
      case C_DECL:
4909
519
      case C_ENTRY:
4910
523
      case C_FUN:
4911
532
      case C_ESTAT:
4912
#endif
4913
842
        dst->symbol.flags |= BSF_DEBUGGING;
4914
532
        dst->symbol.value = (src->u.syment.n_value);
4915
532
        break;
4916
4917
#ifdef RS6000COFF_C
4918
7
      case C_BINCL: /* Beginning of include file.  */
4919
10
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
10
        {
4925
10
    asection *sec;
4926
4927
10
    dst->symbol.flags = BSF_DEBUGGING;
4928
42
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
33
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
33
          && ((file_ptr) (sec->line_filepos
4931
13
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
13
        > (file_ptr) src->u.syment.n_value))
4933
1
        break;
4934
10
    if (sec == NULL)
4935
9
      dst->symbol.value = 0;
4936
1
    else
4937
1
      {
4938
1
        dst->symbol.section = sec;
4939
1
        dst->symbol.value = ((src->u.syment.n_value
4940
1
            - sec->line_filepos)
4941
1
           / bfd_coff_linesz (abfd));
4942
1
        src->fix_line = 1;
4943
1
      }
4944
10
        }
4945
10
        break;
4946
4947
22
      case C_BSTAT:
4948
22
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
22
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
22
    dst->symbol.value = 0;
4952
0
        else
4953
0
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
0
      src->u.syment.n_value
4958
0
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
0
      dst->symbol.value = src->u.syment.n_value;
4960
0
      src->fix_value = 1;
4961
0
    }
4962
22
        break;
4963
0
#endif
4964
4965
19
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
28
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
94
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
39
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
39
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
39
      dst->symbol.flags = BSF_DEBUGGING;
4977
39
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
55
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
94
        break;
4988
4989
24
      case C_STATLAB: /* Static load time label.  */
4990
24
        dst->symbol.value = src->u.syment.n_value;
4991
24
        dst->symbol.flags = BSF_GLOBAL;
4992
24
        break;
4993
4994
8.39k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
8.39k
        if (src->u.syment.n_type == 0
4998
8.39k
      && src->u.syment.n_value == 0
4999
8.39k
      && src->u.syment.n_scnum == 0)
5000
7.47k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
89
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
89
#endif
5006
        /* Fall through.  */
5007
927
      case C_EXTDEF: /* External definition.  */
5008
937
      case C_ULABEL: /* Undefined label.  */
5009
944
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
614
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
621
      case C_ALIAS: /* Duplicate tag.  */
5016
621
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
31
      case C_UEXT: /* Tentative external definition.  */
5020
#endif
5021
966
      case C_EXTLAB: /* External load time label.  */
5022
2.44k
      default:
5023
2.44k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
2.44k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
2.44k
     abfd, src->u.syment.n_sclass,
5027
2.44k
     dst->symbol.section->name, dst->symbol.name);
5028
2.44k
        ret = false;
5029
        /* Fall through.  */
5030
2.45k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
2.45k
        dst->symbol.flags = BSF_DEBUGGING;
5034
2.45k
        dst->symbol.value = (src->u.syment.n_value);
5035
2.45k
        break;
5036
11.9k
      }
5037
5038
11.9k
    dst->native = src;
5039
11.9k
    dst->symbol.udata.i = 0;
5040
11.9k
    dst->lineno = NULL;
5041
5042
11.9k
    this_index += (src->u.syment.n_numaux) + 1;
5043
11.9k
    dst++;
5044
11.9k
    number_of_symbols++;
5045
11.9k
  }
5046
933
    }
5047
5048
933
  obj_symbols (abfd) = cached_area;
5049
933
  obj_raw_syments (abfd) = native_symbols;
5050
5051
933
  abfd->symcount = number_of_symbols;
5052
933
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
933
  {
5055
933
    asection *p;
5056
5057
933
    p = abfd->sections;
5058
2.59k
    while (p)
5059
2.34k
      {
5060
2.34k
  if (! coff_slurp_line_table (abfd, p))
5061
678
    return false;
5062
1.66k
  p = p->next;
5063
1.66k
      }
5064
933
  }
5065
5066
255
  return ret;
5067
933
}
pei-i386.c:coff_slurp_symbol_table
Line
Count
Source
4695
28
{
4696
28
  combined_entry_type *native_symbols;
4697
28
  coff_symbol_type *cached_area;
4698
28
  unsigned int *table_ptr;
4699
28
  unsigned int number_of_symbols = 0;
4700
28
  bool ret = true;
4701
28
  size_t amt;
4702
4703
28
  if (obj_symbols (abfd))
4704
6
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
22
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
11
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
11
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
11
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
11
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
11
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
11
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
11
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
11
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
11
  if (table_ptr == NULL)
4729
0
    return false;
4730
11
  else
4731
11
    {
4732
11
      coff_symbol_type *dst = cached_area;
4733
11
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
11
      unsigned int this_index = 0;
4735
4736
83
      while (this_index < last_native_index)
4737
72
  {
4738
72
    combined_entry_type *src = native_symbols + this_index;
4739
72
    table_ptr[this_index] = number_of_symbols;
4740
4741
72
    dst->symbol.the_bfd = abfd;
4742
72
    BFD_ASSERT (src->is_sym);
4743
72
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
72
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
72
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
72
                 src->u.syment.n_scnum);
4748
72
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
72
    dst->symbol.value = 0;
4751
72
    dst->done_lineno = false;
4752
4753
72
    switch (src->u.syment.n_sclass)
4754
72
      {
4755
0
      case C_EXT:
4756
4
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
4
#ifdef C_SYSTEM
4768
4
      case C_SYSTEM: /* System Wide variable.  */
4769
4
#endif
4770
4
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
4
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
4
      case C_NT_WEAK:
4775
4
#endif
4776
4
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4
    {
4778
2
    case COFF_SYMBOL_GLOBAL:
4779
2
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
2
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
1
    case COFF_SYMBOL_UNDEFINED:
4800
1
      dst->symbol.section = bfd_und_section_ptr;
4801
1
      dst->symbol.value = 0;
4802
1
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
4
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
4
#ifdef COFF_WITH_PE
4831
4
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
4
        if (src->u.syment.n_sclass == C_SECTION
4835
4
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
4
#endif
4838
4
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
4
      )
4843
4
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
7
      case C_FILE: /* File name.  */
4881
7
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
7
      case C_MOS:   /* Member of structure.  */
4884
7
      case C_EOS:   /* End of structure.  */
4885
7
      case C_REGPARM: /* Register parameter.  */
4886
8
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
8
      case C_TPDEF: /* Type definition.  */
4889
8
      case C_ARG:
4890
10
      case C_AUTO: /* Automatic variable.  */
4891
10
      case C_FIELD: /* Bit field.  */
4892
10
      case C_ENTAG: /* Enumeration tag.  */
4893
10
      case C_MOE:   /* Member of enumeration.  */
4894
10
      case C_MOU:   /* Member of union.  */
4895
10
      case C_UNTAG: /* Union tag.  */
4896
10
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
10
        dst->symbol.flags |= BSF_DEBUGGING;
4914
10
        dst->symbol.value = (src->u.syment.n_value);
4915
10
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
0
      case C_EFCN: /* Physical end of function.  */
4968
0
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
0
        dst->symbol.value = src->u.syment.n_value;
4972
0
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
0
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
0
      dst->symbol.flags = BSF_DEBUGGING;
4977
0
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
0
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
54
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
54
        if (src->u.syment.n_type == 0
4998
54
      && src->u.syment.n_value == 0
4999
54
      && src->u.syment.n_scnum == 0)
5000
23
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
31
      case C_EXTDEF: /* External definition.  */
5008
31
      case C_ULABEL: /* Undefined label.  */
5009
31
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
31
      case C_EXTLAB: /* External load time label.  */
5022
35
      default:
5023
35
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
35
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
35
     abfd, src->u.syment.n_sclass,
5027
35
     dst->symbol.section->name, dst->symbol.name);
5028
35
        ret = false;
5029
        /* Fall through.  */
5030
35
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
35
        dst->symbol.flags = BSF_DEBUGGING;
5034
35
        dst->symbol.value = (src->u.syment.n_value);
5035
35
        break;
5036
72
      }
5037
5038
72
    dst->native = src;
5039
72
    dst->symbol.udata.i = 0;
5040
72
    dst->lineno = NULL;
5041
5042
72
    this_index += (src->u.syment.n_numaux) + 1;
5043
72
    dst++;
5044
72
    number_of_symbols++;
5045
72
  }
5046
11
    }
5047
5048
11
  obj_symbols (abfd) = cached_area;
5049
11
  obj_raw_syments (abfd) = native_symbols;
5050
5051
11
  abfd->symcount = number_of_symbols;
5052
11
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
11
  {
5055
11
    asection *p;
5056
5057
11
    p = abfd->sections;
5058
23
    while (p)
5059
20
      {
5060
20
  if (! coff_slurp_line_table (abfd, p))
5061
8
    return false;
5062
12
  p = p->next;
5063
12
      }
5064
11
  }
5065
5066
3
  return ret;
5067
11
}
pe-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
71
{
4696
71
  combined_entry_type *native_symbols;
4697
71
  coff_symbol_type *cached_area;
4698
71
  unsigned int *table_ptr;
4699
71
  unsigned int number_of_symbols = 0;
4700
71
  bool ret = true;
4701
71
  size_t amt;
4702
4703
71
  if (obj_symbols (abfd))
4704
5
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
66
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
39
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
27
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
27
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
27
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
27
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
27
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
27
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
27
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
27
  if (table_ptr == NULL)
4729
0
    return false;
4730
27
  else
4731
27
    {
4732
27
      coff_symbol_type *dst = cached_area;
4733
27
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
27
      unsigned int this_index = 0;
4735
4736
285
      while (this_index < last_native_index)
4737
258
  {
4738
258
    combined_entry_type *src = native_symbols + this_index;
4739
258
    table_ptr[this_index] = number_of_symbols;
4740
4741
258
    dst->symbol.the_bfd = abfd;
4742
258
    BFD_ASSERT (src->is_sym);
4743
258
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
258
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
258
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
258
                 src->u.syment.n_scnum);
4748
258
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
258
    dst->symbol.value = 0;
4751
258
    dst->done_lineno = false;
4752
4753
258
    switch (src->u.syment.n_sclass)
4754
258
      {
4755
3
      case C_EXT:
4756
3
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
3
#ifdef C_SYSTEM
4768
4
      case C_SYSTEM: /* System Wide variable.  */
4769
4
#endif
4770
4
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
4
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
4
      case C_NT_WEAK:
4775
4
#endif
4776
4
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4
    {
4778
0
    case COFF_SYMBOL_GLOBAL:
4779
0
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
0
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
0
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
0
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
0
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
4
    case COFF_SYMBOL_UNDEFINED:
4800
4
      dst->symbol.section = bfd_und_section_ptr;
4801
4
      dst->symbol.value = 0;
4802
4
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
4
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
4
#ifdef COFF_WITH_PE
4831
4
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
4
        if (src->u.syment.n_sclass == C_SECTION
4835
4
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
4
#endif
4838
4
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
4
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4
        break;
4846
4847
4
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
5
      case C_LABEL:  /* Label.  */
4858
5
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
5
        else
4861
5
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
5
        if (dst->symbol.section)
4866
5
    {
4867
5
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
5
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
5
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
5
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
2
      case C_MOS:   /* Member of structure.  */
4884
2
      case C_EOS:   /* End of structure.  */
4885
2
      case C_REGPARM: /* Register parameter.  */
4886
2
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
6
      case C_TPDEF: /* Type definition.  */
4889
6
      case C_ARG:
4890
8
      case C_AUTO: /* Automatic variable.  */
4891
8
      case C_FIELD: /* Bit field.  */
4892
8
      case C_ENTAG: /* Enumeration tag.  */
4893
9
      case C_MOE:   /* Member of enumeration.  */
4894
9
      case C_MOU:   /* Member of union.  */
4895
11
      case C_UNTAG: /* Union tag.  */
4896
12
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
12
        dst->symbol.flags |= BSF_DEBUGGING;
4914
12
        dst->symbol.value = (src->u.syment.n_value);
4915
12
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
1
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
7
      case C_EFCN: /* Physical end of function.  */
4968
7
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
7
        dst->symbol.value = src->u.syment.n_value;
4972
7
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
7
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
7
      dst->symbol.flags = BSF_DEBUGGING;
4977
7
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
7
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
219
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
219
        if (src->u.syment.n_type == 0
4998
219
      && src->u.syment.n_value == 0
4999
219
      && src->u.syment.n_scnum == 0)
5000
155
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
64
      case C_EXTDEF: /* External definition.  */
5008
64
      case C_ULABEL: /* Undefined label.  */
5009
64
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
64
      case C_EXTLAB: /* External load time label.  */
5022
75
      default:
5023
75
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
75
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
75
     abfd, src->u.syment.n_sclass,
5027
75
     dst->symbol.section->name, dst->symbol.name);
5028
75
        ret = false;
5029
        /* Fall through.  */
5030
75
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
75
        dst->symbol.flags = BSF_DEBUGGING;
5034
75
        dst->symbol.value = (src->u.syment.n_value);
5035
75
        break;
5036
258
      }
5037
5038
258
    dst->native = src;
5039
258
    dst->symbol.udata.i = 0;
5040
258
    dst->lineno = NULL;
5041
5042
258
    this_index += (src->u.syment.n_numaux) + 1;
5043
258
    dst++;
5044
258
    number_of_symbols++;
5045
258
  }
5046
27
    }
5047
5048
27
  obj_symbols (abfd) = cached_area;
5049
27
  obj_raw_syments (abfd) = native_symbols;
5050
5051
27
  abfd->symcount = number_of_symbols;
5052
27
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
27
  {
5055
27
    asection *p;
5056
5057
27
    p = abfd->sections;
5058
110
    while (p)
5059
100
      {
5060
100
  if (! coff_slurp_line_table (abfd, p))
5061
17
    return false;
5062
83
  p = p->next;
5063
83
      }
5064
27
  }
5065
5066
10
  return ret;
5067
27
}
pei-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
49
{
4696
49
  combined_entry_type *native_symbols;
4697
49
  coff_symbol_type *cached_area;
4698
49
  unsigned int *table_ptr;
4699
49
  unsigned int number_of_symbols = 0;
4700
49
  bool ret = true;
4701
49
  size_t amt;
4702
4703
49
  if (obj_symbols (abfd))
4704
8
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
41
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
13
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
28
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
28
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
28
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
28
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
28
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
28
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
28
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
28
  if (table_ptr == NULL)
4729
0
    return false;
4730
28
  else
4731
28
    {
4732
28
      coff_symbol_type *dst = cached_area;
4733
28
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
28
      unsigned int this_index = 0;
4735
4736
1.04k
      while (this_index < last_native_index)
4737
1.01k
  {
4738
1.01k
    combined_entry_type *src = native_symbols + this_index;
4739
1.01k
    table_ptr[this_index] = number_of_symbols;
4740
4741
1.01k
    dst->symbol.the_bfd = abfd;
4742
1.01k
    BFD_ASSERT (src->is_sym);
4743
1.01k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
1.01k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
1.01k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
1.01k
                 src->u.syment.n_scnum);
4748
1.01k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
1.01k
    dst->symbol.value = 0;
4751
1.01k
    dst->done_lineno = false;
4752
4753
1.01k
    switch (src->u.syment.n_sclass)
4754
1.01k
      {
4755
220
      case C_EXT:
4756
220
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
220
#ifdef C_SYSTEM
4768
220
      case C_SYSTEM: /* System Wide variable.  */
4769
220
#endif
4770
220
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
221
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
221
      case C_NT_WEAK:
4775
221
#endif
4776
221
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
221
    {
4778
178
    case COFF_SYMBOL_GLOBAL:
4779
178
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
178
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
178
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
178
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
52
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
178
      break;
4793
4794
2
    case COFF_SYMBOL_COMMON:
4795
2
      dst->symbol.section = bfd_com_section_ptr;
4796
2
      dst->symbol.value = src->u.syment.n_value;
4797
2
      break;
4798
4799
41
    case COFF_SYMBOL_UNDEFINED:
4800
41
      dst->symbol.section = bfd_und_section_ptr;
4801
41
      dst->symbol.value = 0;
4802
41
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
221
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
221
#ifdef COFF_WITH_PE
4831
221
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
221
        if (src->u.syment.n_sclass == C_SECTION
4835
221
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
221
#endif
4838
221
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
221
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
221
        break;
4846
4847
573
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
573
      case C_LABEL:  /* Label.  */
4858
573
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
573
        else
4861
573
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
573
        if (dst->symbol.section)
4866
573
    {
4867
573
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
573
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
573
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
573
        break;
4879
4880
54
      case C_FILE: /* File name.  */
4881
54
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
54
      case C_MOS:   /* Member of structure.  */
4884
54
      case C_EOS:   /* End of structure.  */
4885
54
      case C_REGPARM: /* Register parameter.  */
4886
54
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
54
      case C_TPDEF: /* Type definition.  */
4889
54
      case C_ARG:
4890
54
      case C_AUTO: /* Automatic variable.  */
4891
54
      case C_FIELD: /* Bit field.  */
4892
56
      case C_ENTAG: /* Enumeration tag.  */
4893
56
      case C_MOE:   /* Member of enumeration.  */
4894
56
      case C_MOU:   /* Member of union.  */
4895
56
      case C_UNTAG: /* Union tag.  */
4896
56
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
56
        dst->symbol.flags |= BSF_DEBUGGING;
4914
56
        dst->symbol.value = (src->u.syment.n_value);
4915
56
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
0
      case C_EFCN: /* Physical end of function.  */
4968
0
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
0
        dst->symbol.value = src->u.syment.n_value;
4972
0
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
0
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
0
      dst->symbol.flags = BSF_DEBUGGING;
4977
0
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
0
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
165
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
165
        if (src->u.syment.n_type == 0
4998
165
      && src->u.syment.n_value == 0
4999
165
      && src->u.syment.n_scnum == 0)
5000
89
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
76
      case C_EXTDEF: /* External definition.  */
5008
76
      case C_ULABEL: /* Undefined label.  */
5009
76
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
76
      case C_EXTLAB: /* External load time label.  */
5022
76
      default:
5023
76
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
76
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
76
     abfd, src->u.syment.n_sclass,
5027
76
     dst->symbol.section->name, dst->symbol.name);
5028
76
        ret = false;
5029
        /* Fall through.  */
5030
76
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
76
        dst->symbol.flags = BSF_DEBUGGING;
5034
76
        dst->symbol.value = (src->u.syment.n_value);
5035
76
        break;
5036
1.01k
      }
5037
5038
1.01k
    dst->native = src;
5039
1.01k
    dst->symbol.udata.i = 0;
5040
1.01k
    dst->lineno = NULL;
5041
5042
1.01k
    this_index += (src->u.syment.n_numaux) + 1;
5043
1.01k
    dst++;
5044
1.01k
    number_of_symbols++;
5045
1.01k
  }
5046
28
    }
5047
5048
28
  obj_symbols (abfd) = cached_area;
5049
28
  obj_raw_syments (abfd) = native_symbols;
5050
5051
28
  abfd->symcount = number_of_symbols;
5052
28
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
28
  {
5055
28
    asection *p;
5056
5057
28
    p = abfd->sections;
5058
102
    while (p)
5059
98
      {
5060
98
  if (! coff_slurp_line_table (abfd, p))
5061
24
    return false;
5062
74
  p = p->next;
5063
74
      }
5064
28
  }
5065
5066
4
  return ret;
5067
28
}
coff-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
924
{
4696
924
  combined_entry_type *native_symbols;
4697
924
  coff_symbol_type *cached_area;
4698
924
  unsigned int *table_ptr;
4699
924
  unsigned int number_of_symbols = 0;
4700
924
  bool ret = true;
4701
924
  size_t amt;
4702
4703
924
  if (obj_symbols (abfd))
4704
265
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
659
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
570
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
89
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
89
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
89
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
89
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
89
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
89
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
89
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
89
  if (table_ptr == NULL)
4729
0
    return false;
4730
89
  else
4731
89
    {
4732
89
      coff_symbol_type *dst = cached_area;
4733
89
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
89
      unsigned int this_index = 0;
4735
4736
512
      while (this_index < last_native_index)
4737
423
  {
4738
423
    combined_entry_type *src = native_symbols + this_index;
4739
423
    table_ptr[this_index] = number_of_symbols;
4740
4741
423
    dst->symbol.the_bfd = abfd;
4742
423
    BFD_ASSERT (src->is_sym);
4743
423
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
423
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
423
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
423
                 src->u.syment.n_scnum);
4748
423
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
423
    dst->symbol.value = 0;
4751
423
    dst->done_lineno = false;
4752
4753
423
    switch (src->u.syment.n_sclass)
4754
423
      {
4755
6
      case C_EXT:
4756
7
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
7
#ifdef C_SYSTEM
4768
12
      case C_SYSTEM: /* System Wide variable.  */
4769
12
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
12
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
12
    {
4778
3
    case COFF_SYMBOL_GLOBAL:
4779
3
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
3
      dst->symbol.value = (src->u.syment.n_value
4786
3
               - dst->symbol.section->vma);
4787
3
#endif
4788
3
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
3
      break;
4793
4794
2
    case COFF_SYMBOL_COMMON:
4795
2
      dst->symbol.section = bfd_com_section_ptr;
4796
2
      dst->symbol.value = src->u.syment.n_value;
4797
2
      break;
4798
4799
7
    case COFF_SYMBOL_UNDEFINED:
4800
7
      dst->symbol.section = bfd_und_section_ptr;
4801
7
      dst->symbol.value = 0;
4802
7
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
12
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
12
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
12
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
12
        break;
4846
4847
7
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
8
      case C_LABEL:  /* Label.  */
4858
8
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
8
        else
4861
8
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
8
        if (dst->symbol.section)
4866
8
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
8
      dst->symbol.value = (src->u.syment.n_value
4873
8
               - dst->symbol.section->vma);
4874
8
#endif
4875
8
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
8
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
4
      case C_MOS:   /* Member of structure.  */
4884
4
      case C_EOS:   /* End of structure.  */
4885
4
      case C_REGPARM: /* Register parameter.  */
4886
5
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
50
      case C_TPDEF: /* Type definition.  */
4889
52
      case C_ARG:
4890
58
      case C_AUTO: /* Automatic variable.  */
4891
66
      case C_FIELD: /* Bit field.  */
4892
67
      case C_ENTAG: /* Enumeration tag.  */
4893
68
      case C_MOE:   /* Member of enumeration.  */
4894
68
      case C_MOU:   /* Member of union.  */
4895
76
      case C_UNTAG: /* Union tag.  */
4896
76
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
76
        dst->symbol.flags |= BSF_DEBUGGING;
4914
76
        dst->symbol.value = (src->u.syment.n_value);
4915
76
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
1
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
7
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
7
        dst->symbol.flags = BSF_LOCAL;
4984
7
        dst->symbol.value = (src->u.syment.n_value
4985
7
           - dst->symbol.section->vma);
4986
7
#endif
4987
7
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
294
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
294
        if (src->u.syment.n_type == 0
4998
294
      && src->u.syment.n_value == 0
4999
294
      && src->u.syment.n_scnum == 0)
5000
186
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
108
      case C_EXTDEF: /* External definition.  */
5008
108
      case C_ULABEL: /* Undefined label.  */
5009
108
      case C_USTATIC: /* Undefined static.  */
5010
108
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
108
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
108
      case C_ALIAS: /* Duplicate tag.  */
5016
108
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
109
      case C_EXTLAB: /* External load time label.  */
5022
133
      default:
5023
133
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
133
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
133
     abfd, src->u.syment.n_sclass,
5027
133
     dst->symbol.section->name, dst->symbol.name);
5028
133
        ret = false;
5029
        /* Fall through.  */
5030
134
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
134
        dst->symbol.flags = BSF_DEBUGGING;
5034
134
        dst->symbol.value = (src->u.syment.n_value);
5035
134
        break;
5036
423
      }
5037
5038
423
    dst->native = src;
5039
423
    dst->symbol.udata.i = 0;
5040
423
    dst->lineno = NULL;
5041
5042
423
    this_index += (src->u.syment.n_numaux) + 1;
5043
423
    dst++;
5044
423
    number_of_symbols++;
5045
423
  }
5046
89
    }
5047
5048
89
  obj_symbols (abfd) = cached_area;
5049
89
  obj_raw_syments (abfd) = native_symbols;
5050
5051
89
  abfd->symcount = number_of_symbols;
5052
89
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
89
  {
5055
89
    asection *p;
5056
5057
89
    p = abfd->sections;
5058
363
    while (p)
5059
352
      {
5060
352
  if (! coff_slurp_line_table (abfd, p))
5061
78
    return false;
5062
274
  p = p->next;
5063
274
      }
5064
89
  }
5065
5066
11
  return ret;
5067
89
}
coff64-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4695
180
{
4696
180
  combined_entry_type *native_symbols;
4697
180
  coff_symbol_type *cached_area;
4698
180
  unsigned int *table_ptr;
4699
180
  unsigned int number_of_symbols = 0;
4700
180
  bool ret = true;
4701
180
  size_t amt;
4702
4703
180
  if (obj_symbols (abfd))
4704
50
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
130
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
76
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
54
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
54
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
54
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
54
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
54
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
54
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
54
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
54
  if (table_ptr == NULL)
4729
0
    return false;
4730
54
  else
4731
54
    {
4732
54
      coff_symbol_type *dst = cached_area;
4733
54
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
54
      unsigned int this_index = 0;
4735
4736
207
      while (this_index < last_native_index)
4737
153
  {
4738
153
    combined_entry_type *src = native_symbols + this_index;
4739
153
    table_ptr[this_index] = number_of_symbols;
4740
4741
153
    dst->symbol.the_bfd = abfd;
4742
153
    BFD_ASSERT (src->is_sym);
4743
153
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
153
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
153
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
153
                 src->u.syment.n_scnum);
4748
153
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
153
    dst->symbol.value = 0;
4751
153
    dst->done_lineno = false;
4752
4753
153
    switch (src->u.syment.n_sclass)
4754
153
      {
4755
2
      case C_EXT:
4756
3
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
3
#ifdef RS6000COFF_C
4762
3
      case C_HIDEXT:
4763
3
#ifndef AIX_WEAK_SUPPORT
4764
3
      case C_AIX_WEAKEXT:
4765
3
#endif
4766
3
#endif
4767
3
#ifdef C_SYSTEM
4768
3
      case C_SYSTEM: /* System Wide variable.  */
4769
3
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
3
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
3
    {
4778
1
    case COFF_SYMBOL_GLOBAL:
4779
1
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
1
      dst->symbol.value = (src->u.syment.n_value
4786
1
               - dst->symbol.section->vma);
4787
1
#endif
4788
1
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
1
    case COFF_SYMBOL_UNDEFINED:
4800
1
      dst->symbol.section = bfd_und_section_ptr;
4801
1
      dst->symbol.value = 0;
4802
1
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
3
    }
4823
4824
3
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
3
        if (src->u.syment.n_numaux > 0)
4827
0
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
3
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
3
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
3
#ifdef RS6000COFF_C
4840
3
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
3
#endif
4842
3
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
3
        break;
4846
4847
2
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
2
#ifdef RS6000COFF_C
4854
4
      case C_DWARF:  /* A label in a dwarf section.  */
4855
4
      case C_INFO:  /* A label in a comment section.  */
4856
4
#endif
4857
4
      case C_LABEL:  /* Label.  */
4858
4
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
4
        else
4861
4
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
4
        if (dst->symbol.section)
4866
4
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
4
      dst->symbol.value = (src->u.syment.n_value
4873
4
               - dst->symbol.section->vma);
4874
4
#endif
4875
4
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
4
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
1
      case C_AUTO: /* Automatic variable.  */
4891
1
      case C_FIELD: /* Bit field.  */
4892
1
      case C_ENTAG: /* Enumeration tag.  */
4893
2
      case C_MOE:   /* Member of enumeration.  */
4894
2
      case C_MOU:   /* Member of union.  */
4895
2
      case C_UNTAG: /* Union tag.  */
4896
2
      case C_STRTAG: /* Structure tag.  */
4897
2
#ifdef RS6000COFF_C
4898
2
      case C_GSYM:
4899
2
      case C_LSYM:
4900
2
      case C_PSYM:
4901
2
      case C_RSYM:
4902
2
      case C_RPSYM:
4903
2
      case C_STSYM:
4904
2
      case C_TCSYM:
4905
2
      case C_BCOMM:
4906
3
      case C_ECOML:
4907
3
      case C_ECOMM:
4908
3
      case C_DECL:
4909
3
      case C_ENTRY:
4910
3
      case C_FUN:
4911
3
      case C_ESTAT:
4912
3
#endif
4913
3
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3
        dst->symbol.value = (src->u.syment.n_value);
4915
3
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
0
      case C_BINCL: /* Beginning of include file.  */
4919
0
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
0
        {
4925
0
    asection *sec;
4926
4927
0
    dst->symbol.flags = BSF_DEBUGGING;
4928
0
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
0
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
0
          && ((file_ptr) (sec->line_filepos
4931
0
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
0
        > (file_ptr) src->u.syment.n_value))
4933
0
        break;
4934
0
    if (sec == NULL)
4935
0
      dst->symbol.value = 0;
4936
0
    else
4937
0
      {
4938
0
        dst->symbol.section = sec;
4939
0
        dst->symbol.value = ((src->u.syment.n_value
4940
0
            - sec->line_filepos)
4941
0
           / bfd_coff_linesz (abfd));
4942
0
        src->fix_line = 1;
4943
0
      }
4944
0
        }
4945
0
        break;
4946
4947
0
      case C_BSTAT:
4948
0
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
0
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
0
    dst->symbol.value = 0;
4952
0
        else
4953
0
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
0
      src->u.syment.n_value
4958
0
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
0
      dst->symbol.value = src->u.syment.n_value;
4960
0
      src->fix_value = 1;
4961
0
    }
4962
0
        break;
4963
0
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
3
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
3
        dst->symbol.flags = BSF_LOCAL;
4984
3
        dst->symbol.value = (src->u.syment.n_value
4985
3
           - dst->symbol.section->vma);
4986
3
#endif
4987
3
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
138
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
138
        if (src->u.syment.n_type == 0
4998
138
      && src->u.syment.n_value == 0
4999
138
      && src->u.syment.n_scnum == 0)
5000
102
    break;
5001
36
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
36
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
36
#endif
5006
        /* Fall through.  */
5007
36
      case C_EXTDEF: /* External definition.  */
5008
36
      case C_ULABEL: /* Undefined label.  */
5009
36
      case C_USTATIC: /* Undefined static.  */
5010
36
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
36
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
36
      case C_ALIAS: /* Duplicate tag.  */
5016
36
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
36
      case C_EXTLAB: /* External load time label.  */
5022
38
      default:
5023
38
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
38
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
38
     abfd, src->u.syment.n_sclass,
5027
38
     dst->symbol.section->name, dst->symbol.name);
5028
38
        ret = false;
5029
        /* Fall through.  */
5030
38
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
38
        dst->symbol.flags = BSF_DEBUGGING;
5034
38
        dst->symbol.value = (src->u.syment.n_value);
5035
38
        break;
5036
153
      }
5037
5038
153
    dst->native = src;
5039
153
    dst->symbol.udata.i = 0;
5040
153
    dst->lineno = NULL;
5041
5042
153
    this_index += (src->u.syment.n_numaux) + 1;
5043
153
    dst++;
5044
153
    number_of_symbols++;
5045
153
  }
5046
54
    }
5047
5048
54
  obj_symbols (abfd) = cached_area;
5049
54
  obj_raw_syments (abfd) = native_symbols;
5050
5051
54
  abfd->symcount = number_of_symbols;
5052
54
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
54
  {
5055
54
    asection *p;
5056
5057
54
    p = abfd->sections;
5058
78
    while (p)
5059
72
      {
5060
72
  if (! coff_slurp_line_table (abfd, p))
5061
48
    return false;
5062
24
  p = p->next;
5063
24
      }
5064
54
  }
5065
5066
6
  return ret;
5067
54
}
pe-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
943
{
4696
943
  combined_entry_type *native_symbols;
4697
943
  coff_symbol_type *cached_area;
4698
943
  unsigned int *table_ptr;
4699
943
  unsigned int number_of_symbols = 0;
4700
943
  bool ret = true;
4701
943
  size_t amt;
4702
4703
943
  if (obj_symbols (abfd))
4704
9
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
934
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
888
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
46
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
46
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
46
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
46
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
46
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
46
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
46
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
46
  if (table_ptr == NULL)
4729
0
    return false;
4730
46
  else
4731
46
    {
4732
46
      coff_symbol_type *dst = cached_area;
4733
46
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
46
      unsigned int this_index = 0;
4735
4736
102
      while (this_index < last_native_index)
4737
56
  {
4738
56
    combined_entry_type *src = native_symbols + this_index;
4739
56
    table_ptr[this_index] = number_of_symbols;
4740
4741
56
    dst->symbol.the_bfd = abfd;
4742
56
    BFD_ASSERT (src->is_sym);
4743
56
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
56
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
56
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
56
                 src->u.syment.n_scnum);
4748
56
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
56
    dst->symbol.value = 0;
4751
56
    dst->done_lineno = false;
4752
4753
56
    switch (src->u.syment.n_sclass)
4754
56
      {
4755
1
      case C_EXT:
4756
1
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
1
#ifdef C_SYSTEM
4768
1
      case C_SYSTEM: /* System Wide variable.  */
4769
1
#endif
4770
1
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
1
      case C_NT_WEAK:
4775
1
#endif
4776
1
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1
    {
4778
0
    case COFF_SYMBOL_GLOBAL:
4779
0
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
0
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
0
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
0
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
0
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
1
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
1
#ifdef COFF_WITH_PE
4831
1
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
1
        if (src->u.syment.n_sclass == C_SECTION
4835
1
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
1
#endif
4838
1
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
1
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
1
      case C_REGPARM: /* Register parameter.  */
4886
2
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2
      case C_TPDEF: /* Type definition.  */
4889
2
      case C_ARG:
4890
3
      case C_AUTO: /* Automatic variable.  */
4891
3
      case C_FIELD: /* Bit field.  */
4892
3
      case C_ENTAG: /* Enumeration tag.  */
4893
4
      case C_MOE:   /* Member of enumeration.  */
4894
4
      case C_MOU:   /* Member of union.  */
4895
4
      case C_UNTAG: /* Union tag.  */
4896
4
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
4
        dst->symbol.flags |= BSF_DEBUGGING;
4914
4
        dst->symbol.value = (src->u.syment.n_value);
4915
4
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1
      case C_EFCN: /* Physical end of function.  */
4968
1
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1
        dst->symbol.value = src->u.syment.n_value;
4972
1
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1
      dst->symbol.flags = BSF_DEBUGGING;
4977
1
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
1
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
46
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
46
        if (src->u.syment.n_type == 0
4998
46
      && src->u.syment.n_value == 0
4999
46
      && src->u.syment.n_scnum == 0)
5000
23
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
23
      case C_EXTDEF: /* External definition.  */
5008
23
      case C_ULABEL: /* Undefined label.  */
5009
23
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
23
      case C_EXTLAB: /* External load time label.  */
5022
26
      default:
5023
26
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
26
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
26
     abfd, src->u.syment.n_sclass,
5027
26
     dst->symbol.section->name, dst->symbol.name);
5028
26
        ret = false;
5029
        /* Fall through.  */
5030
26
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
26
        dst->symbol.flags = BSF_DEBUGGING;
5034
26
        dst->symbol.value = (src->u.syment.n_value);
5035
26
        break;
5036
56
      }
5037
5038
56
    dst->native = src;
5039
56
    dst->symbol.udata.i = 0;
5040
56
    dst->lineno = NULL;
5041
5042
56
    this_index += (src->u.syment.n_numaux) + 1;
5043
56
    dst++;
5044
56
    number_of_symbols++;
5045
56
  }
5046
46
    }
5047
5048
46
  obj_symbols (abfd) = cached_area;
5049
46
  obj_raw_syments (abfd) = native_symbols;
5050
5051
46
  abfd->symcount = number_of_symbols;
5052
46
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
46
  {
5055
46
    asection *p;
5056
5057
46
    p = abfd->sections;
5058
138
    while (p)
5059
123
      {
5060
123
  if (! coff_slurp_line_table (abfd, p))
5061
31
    return false;
5062
92
  p = p->next;
5063
92
      }
5064
46
  }
5065
5066
15
  return ret;
5067
46
}
pei-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
83
{
4696
83
  combined_entry_type *native_symbols;
4697
83
  coff_symbol_type *cached_area;
4698
83
  unsigned int *table_ptr;
4699
83
  unsigned int number_of_symbols = 0;
4700
83
  bool ret = true;
4701
83
  size_t amt;
4702
4703
83
  if (obj_symbols (abfd))
4704
13
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
70
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
46
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
24
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
24
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
24
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
24
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
24
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
24
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
24
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
24
  if (table_ptr == NULL)
4729
0
    return false;
4730
24
  else
4731
24
    {
4732
24
      coff_symbol_type *dst = cached_area;
4733
24
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
24
      unsigned int this_index = 0;
4735
4736
65
      while (this_index < last_native_index)
4737
41
  {
4738
41
    combined_entry_type *src = native_symbols + this_index;
4739
41
    table_ptr[this_index] = number_of_symbols;
4740
4741
41
    dst->symbol.the_bfd = abfd;
4742
41
    BFD_ASSERT (src->is_sym);
4743
41
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
41
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
41
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
41
                 src->u.syment.n_scnum);
4748
41
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
41
    dst->symbol.value = 0;
4751
41
    dst->done_lineno = false;
4752
4753
41
    switch (src->u.syment.n_sclass)
4754
41
      {
4755
5
      case C_EXT:
4756
9
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
9
#ifdef C_SYSTEM
4768
9
      case C_SYSTEM: /* System Wide variable.  */
4769
9
#endif
4770
9
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
9
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
9
      case C_NT_WEAK:
4775
9
#endif
4776
9
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
9
    {
4778
2
    case COFF_SYMBOL_GLOBAL:
4779
2
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
2
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2
      break;
4793
4794
7
    case COFF_SYMBOL_COMMON:
4795
7
      dst->symbol.section = bfd_com_section_ptr;
4796
7
      dst->symbol.value = src->u.syment.n_value;
4797
7
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
9
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
9
#ifdef COFF_WITH_PE
4831
9
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
9
        if (src->u.syment.n_sclass == C_SECTION
4835
9
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
9
#endif
4838
9
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
9
      )
4843
4
    dst->symbol.flags |= BSF_WEAK;
4844
4845
9
        break;
4846
4847
10
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
10
      case C_LABEL:  /* Label.  */
4858
10
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
10
        else
4861
10
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
10
        if (dst->symbol.section)
4866
10
    {
4867
10
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
10
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
10
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
10
        break;
4879
4880
2
      case C_FILE: /* File name.  */
4881
2
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
2
      case C_MOS:   /* Member of structure.  */
4884
2
      case C_EOS:   /* End of structure.  */
4885
2
      case C_REGPARM: /* Register parameter.  */
4886
2
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2
      case C_TPDEF: /* Type definition.  */
4889
2
      case C_ARG:
4890
3
      case C_AUTO: /* Automatic variable.  */
4891
3
      case C_FIELD: /* Bit field.  */
4892
3
      case C_ENTAG: /* Enumeration tag.  */
4893
3
      case C_MOE:   /* Member of enumeration.  */
4894
3
      case C_MOU:   /* Member of union.  */
4895
3
      case C_UNTAG: /* Union tag.  */
4896
3
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
3
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3
        dst->symbol.value = (src->u.syment.n_value);
4915
3
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
4
      case C_EFCN: /* Physical end of function.  */
4968
4
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
4
        dst->symbol.value = src->u.syment.n_value;
4972
4
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
4
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
4
      dst->symbol.flags = BSF_DEBUGGING;
4977
4
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
4
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
8
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
8
        if (src->u.syment.n_type == 0
4998
8
      && src->u.syment.n_value == 0
4999
8
      && src->u.syment.n_scnum == 0)
5000
3
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
6
      case C_EXTDEF: /* External definition.  */
5008
6
      case C_ULABEL: /* Undefined label.  */
5009
6
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
6
      case C_EXTLAB: /* External load time label.  */
5022
11
      default:
5023
11
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
11
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
11
     abfd, src->u.syment.n_sclass,
5027
11
     dst->symbol.section->name, dst->symbol.name);
5028
11
        ret = false;
5029
        /* Fall through.  */
5030
11
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
11
        dst->symbol.flags = BSF_DEBUGGING;
5034
11
        dst->symbol.value = (src->u.syment.n_value);
5035
11
        break;
5036
41
      }
5037
5038
41
    dst->native = src;
5039
41
    dst->symbol.udata.i = 0;
5040
41
    dst->lineno = NULL;
5041
5042
41
    this_index += (src->u.syment.n_numaux) + 1;
5043
41
    dst++;
5044
41
    number_of_symbols++;
5045
41
  }
5046
24
    }
5047
5048
24
  obj_symbols (abfd) = cached_area;
5049
24
  obj_raw_syments (abfd) = native_symbols;
5050
5051
24
  abfd->symcount = number_of_symbols;
5052
24
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
24
  {
5055
24
    asection *p;
5056
5057
24
    p = abfd->sections;
5058
60
    while (p)
5059
46
      {
5060
46
  if (! coff_slurp_line_table (abfd, p))
5061
10
    return false;
5062
36
  p = p->next;
5063
36
      }
5064
24
  }
5065
5066
14
  return ret;
5067
24
}
pei-ia64.c:coff_slurp_symbol_table
Line
Count
Source
4695
77
{
4696
77
  combined_entry_type *native_symbols;
4697
77
  coff_symbol_type *cached_area;
4698
77
  unsigned int *table_ptr;
4699
77
  unsigned int number_of_symbols = 0;
4700
77
  bool ret = true;
4701
77
  size_t amt;
4702
4703
77
  if (obj_symbols (abfd))
4704
3
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
74
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
56
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
18
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
18
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
18
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
18
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
18
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
18
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
18
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
18
  if (table_ptr == NULL)
4729
0
    return false;
4730
18
  else
4731
18
    {
4732
18
      coff_symbol_type *dst = cached_area;
4733
18
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
18
      unsigned int this_index = 0;
4735
4736
412
      while (this_index < last_native_index)
4737
394
  {
4738
394
    combined_entry_type *src = native_symbols + this_index;
4739
394
    table_ptr[this_index] = number_of_symbols;
4740
4741
394
    dst->symbol.the_bfd = abfd;
4742
394
    BFD_ASSERT (src->is_sym);
4743
394
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
394
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
394
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
394
                 src->u.syment.n_scnum);
4748
394
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
394
    dst->symbol.value = 0;
4751
394
    dst->done_lineno = false;
4752
4753
394
    switch (src->u.syment.n_sclass)
4754
394
      {
4755
0
      case C_EXT:
4756
6
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
6
#ifdef C_SYSTEM
4768
6
      case C_SYSTEM: /* System Wide variable.  */
4769
6
#endif
4770
6
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
6
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
6
      case C_NT_WEAK:
4775
6
#endif
4776
6
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6
    {
4778
5
    case COFF_SYMBOL_GLOBAL:
4779
5
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
5
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
5
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
5
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
5
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
5
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
1
    case COFF_SYMBOL_UNDEFINED:
4800
1
      dst->symbol.section = bfd_und_section_ptr;
4801
1
      dst->symbol.value = 0;
4802
1
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
6
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
6
#ifdef COFF_WITH_PE
4831
6
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
6
        if (src->u.syment.n_sclass == C_SECTION
4835
6
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
6
#endif
4838
6
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
6
      )
4843
6
    dst->symbol.flags |= BSF_WEAK;
4844
4845
6
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
1
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
1
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1
      case C_TPDEF: /* Type definition.  */
4889
1
      case C_ARG:
4890
2
      case C_AUTO: /* Automatic variable.  */
4891
2
      case C_FIELD: /* Bit field.  */
4892
2
      case C_ENTAG: /* Enumeration tag.  */
4893
3
      case C_MOE:   /* Member of enumeration.  */
4894
6
      case C_MOU:   /* Member of union.  */
4895
6
      case C_UNTAG: /* Union tag.  */
4896
7
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
7
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7
        dst->symbol.value = (src->u.syment.n_value);
4915
7
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2
      case C_EFCN: /* Physical end of function.  */
4968
2
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
2
        dst->symbol.value = src->u.syment.n_value;
4972
2
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
2
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
2
      dst->symbol.flags = BSF_DEBUGGING;
4977
2
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
2
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
368
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
368
        if (src->u.syment.n_type == 0
4998
368
      && src->u.syment.n_value == 0
4999
368
      && src->u.syment.n_scnum == 0)
5000
314
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
54
      case C_EXTDEF: /* External definition.  */
5008
54
      case C_ULABEL: /* Undefined label.  */
5009
54
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
54
      case C_EXTLAB: /* External load time label.  */
5022
64
      default:
5023
64
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
64
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
64
     abfd, src->u.syment.n_sclass,
5027
64
     dst->symbol.section->name, dst->symbol.name);
5028
64
        ret = false;
5029
        /* Fall through.  */
5030
64
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
64
        dst->symbol.flags = BSF_DEBUGGING;
5034
64
        dst->symbol.value = (src->u.syment.n_value);
5035
64
        break;
5036
394
      }
5037
5038
394
    dst->native = src;
5039
394
    dst->symbol.udata.i = 0;
5040
394
    dst->lineno = NULL;
5041
5042
394
    this_index += (src->u.syment.n_numaux) + 1;
5043
394
    dst++;
5044
394
    number_of_symbols++;
5045
394
  }
5046
18
    }
5047
5048
18
  obj_symbols (abfd) = cached_area;
5049
18
  obj_raw_syments (abfd) = native_symbols;
5050
5051
18
  abfd->symcount = number_of_symbols;
5052
18
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
18
  {
5055
18
    asection *p;
5056
5057
18
    p = abfd->sections;
5058
142
    while (p)
5059
137
      {
5060
137
  if (! coff_slurp_line_table (abfd, p))
5061
13
    return false;
5062
124
  p = p->next;
5063
124
      }
5064
18
  }
5065
5066
5
  return ret;
5067
18
}
pei-loongarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
47
{
4696
47
  combined_entry_type *native_symbols;
4697
47
  coff_symbol_type *cached_area;
4698
47
  unsigned int *table_ptr;
4699
47
  unsigned int number_of_symbols = 0;
4700
47
  bool ret = true;
4701
47
  size_t amt;
4702
4703
47
  if (obj_symbols (abfd))
4704
15
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
32
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
15
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
17
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
17
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
17
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
17
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
17
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
17
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
17
  if (table_ptr == NULL)
4729
0
    return false;
4730
17
  else
4731
17
    {
4732
17
      coff_symbol_type *dst = cached_area;
4733
17
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
17
      unsigned int this_index = 0;
4735
4736
72
      while (this_index < last_native_index)
4737
55
  {
4738
55
    combined_entry_type *src = native_symbols + this_index;
4739
55
    table_ptr[this_index] = number_of_symbols;
4740
4741
55
    dst->symbol.the_bfd = abfd;
4742
55
    BFD_ASSERT (src->is_sym);
4743
55
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
55
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
55
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
55
                 src->u.syment.n_scnum);
4748
55
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
55
    dst->symbol.value = 0;
4751
55
    dst->done_lineno = false;
4752
4753
55
    switch (src->u.syment.n_sclass)
4754
55
      {
4755
3
      case C_EXT:
4756
3
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
3
#ifdef C_SYSTEM
4768
3
      case C_SYSTEM: /* System Wide variable.  */
4769
3
#endif
4770
3
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
3
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
3
      case C_NT_WEAK:
4775
3
#endif
4776
3
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
3
    {
4778
0
    case COFF_SYMBOL_GLOBAL:
4779
0
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
0
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
0
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
0
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
0
      break;
4793
4794
3
    case COFF_SYMBOL_COMMON:
4795
3
      dst->symbol.section = bfd_com_section_ptr;
4796
3
      dst->symbol.value = src->u.syment.n_value;
4797
3
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
3
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
3
#ifdef COFF_WITH_PE
4831
3
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
3
        if (src->u.syment.n_sclass == C_SECTION
4835
3
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
3
#endif
4838
3
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
3
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
3
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
1
      case C_FILE: /* File name.  */
4881
1
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
1
      case C_REGPARM: /* Register parameter.  */
4886
1
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1
      case C_TPDEF: /* Type definition.  */
4889
1
      case C_ARG:
4890
3
      case C_AUTO: /* Automatic variable.  */
4891
4
      case C_FIELD: /* Bit field.  */
4892
4
      case C_ENTAG: /* Enumeration tag.  */
4893
4
      case C_MOE:   /* Member of enumeration.  */
4894
4
      case C_MOU:   /* Member of union.  */
4895
4
      case C_UNTAG: /* Union tag.  */
4896
4
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
4
        dst->symbol.flags |= BSF_DEBUGGING;
4914
4
        dst->symbol.value = (src->u.syment.n_value);
4915
4
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
8
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
8
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
12
      case C_EFCN: /* Physical end of function.  */
4968
12
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
12
        dst->symbol.value = src->u.syment.n_value;
4972
12
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
12
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
12
      dst->symbol.flags = BSF_DEBUGGING;
4977
12
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
12
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
30
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
30
        if (src->u.syment.n_type == 0
4998
30
      && src->u.syment.n_value == 0
4999
30
      && src->u.syment.n_scnum == 0)
5000
12
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
18
      case C_EXTDEF: /* External definition.  */
5008
18
      case C_ULABEL: /* Undefined label.  */
5009
18
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
18
      case C_EXTLAB: /* External load time label.  */
5022
24
      default:
5023
24
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
24
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
24
     abfd, src->u.syment.n_sclass,
5027
24
     dst->symbol.section->name, dst->symbol.name);
5028
24
        ret = false;
5029
        /* Fall through.  */
5030
24
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
24
        dst->symbol.flags = BSF_DEBUGGING;
5034
24
        dst->symbol.value = (src->u.syment.n_value);
5035
24
        break;
5036
55
      }
5037
5038
55
    dst->native = src;
5039
55
    dst->symbol.udata.i = 0;
5040
55
    dst->lineno = NULL;
5041
5042
55
    this_index += (src->u.syment.n_numaux) + 1;
5043
55
    dst++;
5044
55
    number_of_symbols++;
5045
55
  }
5046
17
    }
5047
5048
17
  obj_symbols (abfd) = cached_area;
5049
17
  obj_raw_syments (abfd) = native_symbols;
5050
5051
17
  abfd->symcount = number_of_symbols;
5052
17
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
17
  {
5055
17
    asection *p;
5056
5057
17
    p = abfd->sections;
5058
21
    while (p)
5059
17
      {
5060
17
  if (! coff_slurp_line_table (abfd, p))
5061
13
    return false;
5062
4
  p = p->next;
5063
4
      }
5064
17
  }
5065
5066
4
  return ret;
5067
17
}
Unexecuted instantiation: cf-i386lynx.c:coff_slurp_symbol_table
Unexecuted instantiation: coff-go32.c:coff_slurp_symbol_table
Unexecuted instantiation: coff-i386.c:coff_slurp_symbol_table
coff-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4695
190
{
4696
190
  combined_entry_type *native_symbols;
4697
190
  coff_symbol_type *cached_area;
4698
190
  unsigned int *table_ptr;
4699
190
  unsigned int number_of_symbols = 0;
4700
190
  bool ret = true;
4701
190
  size_t amt;
4702
4703
190
  if (obj_symbols (abfd))
4704
50
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
140
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
75
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
65
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
65
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
65
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
65
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
65
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
65
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
65
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
65
  if (table_ptr == NULL)
4729
0
    return false;
4730
65
  else
4731
65
    {
4732
65
      coff_symbol_type *dst = cached_area;
4733
65
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
65
      unsigned int this_index = 0;
4735
4736
7.35k
      while (this_index < last_native_index)
4737
7.29k
  {
4738
7.29k
    combined_entry_type *src = native_symbols + this_index;
4739
7.29k
    table_ptr[this_index] = number_of_symbols;
4740
4741
7.29k
    dst->symbol.the_bfd = abfd;
4742
7.29k
    BFD_ASSERT (src->is_sym);
4743
7.29k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
7.29k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
7.29k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
7.29k
                 src->u.syment.n_scnum);
4748
7.29k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
7.29k
    dst->symbol.value = 0;
4751
7.29k
    dst->done_lineno = false;
4752
4753
7.29k
    switch (src->u.syment.n_sclass)
4754
7.29k
      {
4755
12
      case C_EXT:
4756
21
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
21
#ifdef RS6000COFF_C
4762
28
      case C_HIDEXT:
4763
28
#ifndef AIX_WEAK_SUPPORT
4764
32
      case C_AIX_WEAKEXT:
4765
32
#endif
4766
32
#endif
4767
32
#ifdef C_SYSTEM
4768
37
      case C_SYSTEM: /* System Wide variable.  */
4769
37
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
37
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
37
    {
4778
29
    case COFF_SYMBOL_GLOBAL:
4779
29
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
29
      dst->symbol.value = (src->u.syment.n_value
4786
29
               - dst->symbol.section->vma);
4787
29
#endif
4788
29
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
7
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
29
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
7
    case COFF_SYMBOL_LOCAL:
4810
7
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
7
      dst->symbol.value = (src->u.syment.n_value
4817
7
               - dst->symbol.section->vma);
4818
7
#endif
4819
7
      if (ISFCN ((src->u.syment.n_type)))
4820
3
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
7
      break;
4822
37
    }
4823
4824
37
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
37
        if (src->u.syment.n_numaux > 0)
4827
35
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
37
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
37
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
37
#ifdef RS6000COFF_C
4840
37
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
37
#endif
4842
37
      )
4843
13
    dst->symbol.flags |= BSF_WEAK;
4844
4845
37
        break;
4846
4847
10
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
10
#ifdef RS6000COFF_C
4854
19
      case C_DWARF:  /* A label in a dwarf section.  */
4855
24
      case C_INFO:  /* A label in a comment section.  */
4856
24
#endif
4857
28
      case C_LABEL:  /* Label.  */
4858
28
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
28
        else
4861
28
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
28
        if (dst->symbol.section)
4866
28
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
28
      dst->symbol.value = (src->u.syment.n_value
4873
28
               - dst->symbol.section->vma);
4874
28
#endif
4875
28
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
28
        break;
4879
4880
2
      case C_FILE: /* File name.  */
4881
2
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
10
      case C_MOS:   /* Member of structure.  */
4884
15
      case C_EOS:   /* End of structure.  */
4885
21
      case C_REGPARM: /* Register parameter.  */
4886
40
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
47
      case C_TPDEF: /* Type definition.  */
4889
55
      case C_ARG:
4890
274
      case C_AUTO: /* Automatic variable.  */
4891
276
      case C_FIELD: /* Bit field.  */
4892
285
      case C_ENTAG: /* Enumeration tag.  */
4893
293
      case C_MOE:   /* Member of enumeration.  */
4894
299
      case C_MOU:   /* Member of union.  */
4895
306
      case C_UNTAG: /* Union tag.  */
4896
314
      case C_STRTAG: /* Structure tag.  */
4897
314
#ifdef RS6000COFF_C
4898
320
      case C_GSYM:
4899
473
      case C_LSYM:
4900
481
      case C_PSYM:
4901
483
      case C_RSYM:
4902
486
      case C_RPSYM:
4903
489
      case C_STSYM:
4904
491
      case C_TCSYM:
4905
498
      case C_BCOMM:
4906
508
      case C_ECOML:
4907
509
      case C_ECOMM:
4908
512
      case C_DECL:
4909
516
      case C_ENTRY:
4910
520
      case C_FUN:
4911
529
      case C_ESTAT:
4912
529
#endif
4913
529
        dst->symbol.flags |= BSF_DEBUGGING;
4914
529
        dst->symbol.value = (src->u.syment.n_value);
4915
529
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
7
      case C_BINCL: /* Beginning of include file.  */
4919
10
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
10
        {
4925
10
    asection *sec;
4926
4927
10
    dst->symbol.flags = BSF_DEBUGGING;
4928
42
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
33
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
33
          && ((file_ptr) (sec->line_filepos
4931
13
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
13
        > (file_ptr) src->u.syment.n_value))
4933
1
        break;
4934
10
    if (sec == NULL)
4935
9
      dst->symbol.value = 0;
4936
1
    else
4937
1
      {
4938
1
        dst->symbol.section = sec;
4939
1
        dst->symbol.value = ((src->u.syment.n_value
4940
1
            - sec->line_filepos)
4941
1
           / bfd_coff_linesz (abfd));
4942
1
        src->fix_line = 1;
4943
1
      }
4944
10
        }
4945
10
        break;
4946
4947
22
      case C_BSTAT:
4948
22
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
22
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
22
    dst->symbol.value = 0;
4952
0
        else
4953
0
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
0
      src->u.syment.n_value
4958
0
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
0
      dst->symbol.value = src->u.syment.n_value;
4960
0
      src->fix_value = 1;
4961
0
    }
4962
22
        break;
4963
0
#endif
4964
4965
6
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
11
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
19
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
19
        dst->symbol.flags = BSF_LOCAL;
4984
19
        dst->symbol.value = (src->u.syment.n_value
4985
19
           - dst->symbol.section->vma);
4986
19
#endif
4987
19
        break;
4988
4989
5
      case C_STATLAB: /* Static load time label.  */
4990
5
        dst->symbol.value = src->u.syment.n_value;
4991
5
        dst->symbol.flags = BSF_GLOBAL;
4992
5
        break;
4993
4994
5.27k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
5.27k
        if (src->u.syment.n_type == 0
4998
5.27k
      && src->u.syment.n_value == 0
4999
5.27k
      && src->u.syment.n_scnum == 0)
5000
5.22k
    break;
5001
53
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
53
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
0
    break;
5005
53
#endif
5006
        /* Fall through.  */
5007
58
      case C_EXTDEF: /* External definition.  */
5008
60
      case C_ULABEL: /* Undefined label.  */
5009
66
      case C_USTATIC: /* Undefined static.  */
5010
66
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
70
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
77
      case C_ALIAS: /* Duplicate tag.  */
5016
77
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
85
      case C_EXTLAB: /* External load time label.  */
5022
1.40k
      default:
5023
1.40k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
1.40k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
1.40k
     abfd, src->u.syment.n_sclass,
5027
1.40k
     dst->symbol.section->name, dst->symbol.name);
5028
1.40k
        ret = false;
5029
        /* Fall through.  */
5030
1.41k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
1.41k
        dst->symbol.flags = BSF_DEBUGGING;
5034
1.41k
        dst->symbol.value = (src->u.syment.n_value);
5035
1.41k
        break;
5036
7.29k
      }
5037
5038
7.29k
    dst->native = src;
5039
7.29k
    dst->symbol.udata.i = 0;
5040
7.29k
    dst->lineno = NULL;
5041
5042
7.29k
    this_index += (src->u.syment.n_numaux) + 1;
5043
7.29k
    dst++;
5044
7.29k
    number_of_symbols++;
5045
7.29k
  }
5046
65
    }
5047
5048
65
  obj_symbols (abfd) = cached_area;
5049
65
  obj_raw_syments (abfd) = native_symbols;
5050
5051
65
  abfd->symcount = number_of_symbols;
5052
65
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
65
  {
5055
65
    asection *p;
5056
5057
65
    p = abfd->sections;
5058
142
    while (p)
5059
119
      {
5060
119
  if (! coff_slurp_line_table (abfd, p))
5061
42
    return false;
5062
77
  p = p->next;
5063
77
      }
5064
65
  }
5065
5066
23
  return ret;
5067
65
}
coff-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.02k
{
4696
1.02k
  combined_entry_type *native_symbols;
4697
1.02k
  coff_symbol_type *cached_area;
4698
1.02k
  unsigned int *table_ptr;
4699
1.02k
  unsigned int number_of_symbols = 0;
4700
1.02k
  bool ret = true;
4701
1.02k
  size_t amt;
4702
4703
1.02k
  if (obj_symbols (abfd))
4704
608
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
421
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
352
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
69
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
69
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
69
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
69
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
69
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
69
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
69
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
69
  if (table_ptr == NULL)
4729
0
    return false;
4730
69
  else
4731
69
    {
4732
69
      coff_symbol_type *dst = cached_area;
4733
69
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
69
      unsigned int this_index = 0;
4735
4736
500
      while (this_index < last_native_index)
4737
431
  {
4738
431
    combined_entry_type *src = native_symbols + this_index;
4739
431
    table_ptr[this_index] = number_of_symbols;
4740
4741
431
    dst->symbol.the_bfd = abfd;
4742
431
    BFD_ASSERT (src->is_sym);
4743
431
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
431
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
431
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
431
                 src->u.syment.n_scnum);
4748
431
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
431
    dst->symbol.value = 0;
4751
431
    dst->done_lineno = false;
4752
4753
431
    switch (src->u.syment.n_sclass)
4754
431
      {
4755
8
      case C_EXT:
4756
8
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
8
#ifdef C_SYSTEM
4768
8
      case C_SYSTEM: /* System Wide variable.  */
4769
8
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
8
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
8
    {
4778
2
    case COFF_SYMBOL_GLOBAL:
4779
2
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
2
      dst->symbol.value = (src->u.syment.n_value
4786
2
               - dst->symbol.section->vma);
4787
2
#endif
4788
2
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
5
    case COFF_SYMBOL_UNDEFINED:
4800
5
      dst->symbol.section = bfd_und_section_ptr;
4801
5
      dst->symbol.value = 0;
4802
5
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
8
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
8
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
8
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
8
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
1
      dst->symbol.value = (src->u.syment.n_value
4873
1
               - dst->symbol.section->vma);
4874
1
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
5
      case C_AUTO: /* Automatic variable.  */
4891
5
      case C_FIELD: /* Bit field.  */
4892
5
      case C_ENTAG: /* Enumeration tag.  */
4893
6
      case C_MOE:   /* Member of enumeration.  */
4894
6
      case C_MOU:   /* Member of union.  */
4895
6
      case C_UNTAG: /* Union tag.  */
4896
8
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
8
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8
        dst->symbol.value = (src->u.syment.n_value);
4915
8
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
2
        dst->symbol.flags = BSF_LOCAL;
4984
2
        dst->symbol.value = (src->u.syment.n_value
4985
2
           - dst->symbol.section->vma);
4986
2
#endif
4987
2
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
377
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
377
        if (src->u.syment.n_type == 0
4998
377
      && src->u.syment.n_value == 0
4999
377
      && src->u.syment.n_scnum == 0)
5000
267
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
110
      case C_EXTDEF: /* External definition.  */
5008
110
      case C_ULABEL: /* Undefined label.  */
5009
110
      case C_USTATIC: /* Undefined static.  */
5010
110
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
110
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
110
      case C_ALIAS: /* Duplicate tag.  */
5016
110
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
110
      case C_EXTLAB: /* External load time label.  */
5022
144
      default:
5023
144
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
144
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
144
     abfd, src->u.syment.n_sclass,
5027
144
     dst->symbol.section->name, dst->symbol.name);
5028
144
        ret = false;
5029
        /* Fall through.  */
5030
145
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
145
        dst->symbol.flags = BSF_DEBUGGING;
5034
145
        dst->symbol.value = (src->u.syment.n_value);
5035
145
        break;
5036
431
      }
5037
5038
431
    dst->native = src;
5039
431
    dst->symbol.udata.i = 0;
5040
431
    dst->lineno = NULL;
5041
5042
431
    this_index += (src->u.syment.n_numaux) + 1;
5043
431
    dst++;
5044
431
    number_of_symbols++;
5045
431
  }
5046
69
    }
5047
5048
69
  obj_symbols (abfd) = cached_area;
5049
69
  obj_raw_syments (abfd) = native_symbols;
5050
5051
69
  abfd->symcount = number_of_symbols;
5052
69
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
69
  {
5055
69
    asection *p;
5056
5057
69
    p = abfd->sections;
5058
363
    while (p)
5059
351
      {
5060
351
  if (! coff_slurp_line_table (abfd, p))
5061
57
    return false;
5062
294
  p = p->next;
5063
294
      }
5064
69
  }
5065
5066
12
  return ret;
5067
69
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_symbol_table
coff-tic30.c:coff_slurp_symbol_table
Line
Count
Source
4695
10.2k
{
4696
10.2k
  combined_entry_type *native_symbols;
4697
10.2k
  coff_symbol_type *cached_area;
4698
10.2k
  unsigned int *table_ptr;
4699
10.2k
  unsigned int number_of_symbols = 0;
4700
10.2k
  bool ret = true;
4701
10.2k
  size_t amt;
4702
4703
10.2k
  if (obj_symbols (abfd))
4704
9.40k
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
875
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
728
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
147
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
147
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
147
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
147
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
147
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
147
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
147
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
147
  if (table_ptr == NULL)
4729
0
    return false;
4730
147
  else
4731
147
    {
4732
147
      coff_symbol_type *dst = cached_area;
4733
147
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
147
      unsigned int this_index = 0;
4735
4736
807
      while (this_index < last_native_index)
4737
660
  {
4738
660
    combined_entry_type *src = native_symbols + this_index;
4739
660
    table_ptr[this_index] = number_of_symbols;
4740
4741
660
    dst->symbol.the_bfd = abfd;
4742
660
    BFD_ASSERT (src->is_sym);
4743
660
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
660
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
660
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
660
                 src->u.syment.n_scnum);
4748
660
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
660
    dst->symbol.value = 0;
4751
660
    dst->done_lineno = false;
4752
4753
660
    switch (src->u.syment.n_sclass)
4754
660
      {
4755
5
      case C_EXT:
4756
6
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
6
#ifdef C_SYSTEM
4768
6
      case C_SYSTEM: /* System Wide variable.  */
4769
6
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
6
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6
    {
4778
4
    case COFF_SYMBOL_GLOBAL:
4779
4
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
4
      dst->symbol.value = (src->u.syment.n_value
4786
4
               - dst->symbol.section->vma);
4787
4
#endif
4788
4
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
4
      break;
4793
4794
2
    case COFF_SYMBOL_COMMON:
4795
2
      dst->symbol.section = bfd_com_section_ptr;
4796
2
      dst->symbol.value = src->u.syment.n_value;
4797
2
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
6
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
6
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
6
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
6
        break;
4846
4847
12
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
13
      case C_LABEL:  /* Label.  */
4858
13
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
13
        else
4861
13
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
13
        if (dst->symbol.section)
4866
13
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
13
      dst->symbol.value = (src->u.syment.n_value
4873
13
               - dst->symbol.section->vma);
4874
13
#endif
4875
13
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
13
        break;
4879
4880
2
      case C_FILE: /* File name.  */
4881
2
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
2
      case C_MOS:   /* Member of structure.  */
4884
2
      case C_EOS:   /* End of structure.  */
4885
2
      case C_REGPARM: /* Register parameter.  */
4886
2
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
16
      case C_TPDEF: /* Type definition.  */
4889
17
      case C_ARG:
4890
18
      case C_AUTO: /* Automatic variable.  */
4891
18
      case C_FIELD: /* Bit field.  */
4892
18
      case C_ENTAG: /* Enumeration tag.  */
4893
19
      case C_MOE:   /* Member of enumeration.  */
4894
19
      case C_MOU:   /* Member of union.  */
4895
20
      case C_UNTAG: /* Union tag.  */
4896
21
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
21
        dst->symbol.flags |= BSF_DEBUGGING;
4914
21
        dst->symbol.value = (src->u.syment.n_value);
4915
21
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
1
        dst->symbol.flags = BSF_LOCAL;
4984
1
        dst->symbol.value = (src->u.syment.n_value
4985
1
           - dst->symbol.section->vma);
4986
1
#endif
4987
1
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
605
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
605
        if (src->u.syment.n_type == 0
4998
605
      && src->u.syment.n_value == 0
4999
605
      && src->u.syment.n_scnum == 0)
5000
570
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
35
      case C_EXTDEF: /* External definition.  */
5008
35
      case C_ULABEL: /* Undefined label.  */
5009
36
      case C_USTATIC: /* Undefined static.  */
5010
36
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
36
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
36
      case C_ALIAS: /* Duplicate tag.  */
5016
36
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
36
      case C_EXTLAB: /* External load time label.  */
5022
48
      default:
5023
48
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
48
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
48
     abfd, src->u.syment.n_sclass,
5027
48
     dst->symbol.section->name, dst->symbol.name);
5028
48
        ret = false;
5029
        /* Fall through.  */
5030
48
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
48
        dst->symbol.flags = BSF_DEBUGGING;
5034
48
        dst->symbol.value = (src->u.syment.n_value);
5035
48
        break;
5036
660
      }
5037
5038
660
    dst->native = src;
5039
660
    dst->symbol.udata.i = 0;
5040
660
    dst->lineno = NULL;
5041
5042
660
    this_index += (src->u.syment.n_numaux) + 1;
5043
660
    dst++;
5044
660
    number_of_symbols++;
5045
660
  }
5046
147
    }
5047
5048
147
  obj_symbols (abfd) = cached_area;
5049
147
  obj_raw_syments (abfd) = native_symbols;
5050
5051
147
  abfd->symcount = number_of_symbols;
5052
147
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
147
  {
5055
147
    asection *p;
5056
5057
147
    p = abfd->sections;
5058
240
    while (p)
5059
234
      {
5060
234
  if (! coff_slurp_line_table (abfd, p))
5061
141
    return false;
5062
93
  p = p->next;
5063
93
      }
5064
147
  }
5065
5066
6
  return ret;
5067
147
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_symbol_table
coff-tic54x.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.09k
{
4696
1.09k
  combined_entry_type *native_symbols;
4697
1.09k
  coff_symbol_type *cached_area;
4698
1.09k
  unsigned int *table_ptr;
4699
1.09k
  unsigned int number_of_symbols = 0;
4700
1.09k
  bool ret = true;
4701
1.09k
  size_t amt;
4702
4703
1.09k
  if (obj_symbols (abfd))
4704
205
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
888
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
821
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
67
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
67
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
67
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
67
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
67
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
67
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
67
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
67
  if (table_ptr == NULL)
4729
0
    return false;
4730
67
  else
4731
67
    {
4732
67
      coff_symbol_type *dst = cached_area;
4733
67
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
67
      unsigned int this_index = 0;
4735
4736
137
      while (this_index < last_native_index)
4737
70
  {
4738
70
    combined_entry_type *src = native_symbols + this_index;
4739
70
    table_ptr[this_index] = number_of_symbols;
4740
4741
70
    dst->symbol.the_bfd = abfd;
4742
70
    BFD_ASSERT (src->is_sym);
4743
70
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
70
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
70
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
70
                 src->u.syment.n_scnum);
4748
70
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
70
    dst->symbol.value = 0;
4751
70
    dst->done_lineno = false;
4752
4753
70
    switch (src->u.syment.n_sclass)
4754
70
      {
4755
4
      case C_EXT:
4756
4
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
4
#ifdef C_SYSTEM
4768
4
      case C_SYSTEM: /* System Wide variable.  */
4769
4
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
4
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4
    {
4778
0
    case COFF_SYMBOL_GLOBAL:
4779
0
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
0
      dst->symbol.value = (src->u.syment.n_value
4786
0
               - dst->symbol.section->vma);
4787
0
#endif
4788
0
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
0
      break;
4793
4794
4
    case COFF_SYMBOL_COMMON:
4795
4
      dst->symbol.section = bfd_com_section_ptr;
4796
4
      dst->symbol.value = src->u.syment.n_value;
4797
4
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
4
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
4
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
4
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4
        break;
4846
4847
4
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
4
      case C_LABEL:  /* Label.  */
4858
4
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
4
        else
4861
4
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
4
        if (dst->symbol.section)
4866
4
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
4
      dst->symbol.value = (src->u.syment.n_value
4873
4
               - dst->symbol.section->vma);
4874
4
#endif
4875
4
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
4
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
1
      case C_REGPARM: /* Register parameter.  */
4886
1
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1
      case C_TPDEF: /* Type definition.  */
4889
1
      case C_ARG:
4890
3
      case C_AUTO: /* Automatic variable.  */
4891
3
      case C_FIELD: /* Bit field.  */
4892
3
      case C_ENTAG: /* Enumeration tag.  */
4893
7
      case C_MOE:   /* Member of enumeration.  */
4894
7
      case C_MOU:   /* Member of union.  */
4895
7
      case C_UNTAG: /* Union tag.  */
4896
8
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
8
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8
        dst->symbol.value = (src->u.syment.n_value);
4915
8
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
9
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
9
        dst->symbol.flags = BSF_LOCAL;
4984
9
        dst->symbol.value = (src->u.syment.n_value
4985
9
           - dst->symbol.section->vma);
4986
9
#endif
4987
9
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
40
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
40
        if (src->u.syment.n_type == 0
4998
40
      && src->u.syment.n_value == 0
4999
40
      && src->u.syment.n_scnum == 0)
5000
9
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
31
      case C_EXTDEF: /* External definition.  */
5008
31
      case C_ULABEL: /* Undefined label.  */
5009
31
      case C_USTATIC: /* Undefined static.  */
5010
31
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
31
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
31
      case C_ALIAS: /* Duplicate tag.  */
5016
31
#endif
5017
        /* New storage classes for TI COFF.  */
5018
31
#ifdef TICOFF
5019
31
      case C_UEXT: /* Tentative external definition.  */
5020
31
#endif
5021
32
      case C_EXTLAB: /* External load time label.  */
5022
35
      default:
5023
35
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
35
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
35
     abfd, src->u.syment.n_sclass,
5027
35
     dst->symbol.section->name, dst->symbol.name);
5028
35
        ret = false;
5029
        /* Fall through.  */
5030
36
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
36
        dst->symbol.flags = BSF_DEBUGGING;
5034
36
        dst->symbol.value = (src->u.syment.n_value);
5035
36
        break;
5036
70
      }
5037
5038
70
    dst->native = src;
5039
70
    dst->symbol.udata.i = 0;
5040
70
    dst->lineno = NULL;
5041
5042
70
    this_index += (src->u.syment.n_numaux) + 1;
5043
70
    dst++;
5044
70
    number_of_symbols++;
5045
70
  }
5046
67
    }
5047
5048
67
  obj_symbols (abfd) = cached_area;
5049
67
  obj_raw_syments (abfd) = native_symbols;
5050
5051
67
  abfd->symcount = number_of_symbols;
5052
67
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
67
  {
5055
67
    asection *p;
5056
5057
67
    p = abfd->sections;
5058
132
    while (p)
5059
117
      {
5060
117
  if (! coff_slurp_line_table (abfd, p))
5061
52
    return false;
5062
65
  p = p->next;
5063
65
      }
5064
67
  }
5065
5066
15
  return ret;
5067
67
}
coff-z80.c:coff_slurp_symbol_table
Line
Count
Source
4695
272
{
4696
272
  combined_entry_type *native_symbols;
4697
272
  coff_symbol_type *cached_area;
4698
272
  unsigned int *table_ptr;
4699
272
  unsigned int number_of_symbols = 0;
4700
272
  bool ret = true;
4701
272
  size_t amt;
4702
4703
272
  if (obj_symbols (abfd))
4704
52
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
220
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
150
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
70
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
70
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
70
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
70
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
70
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
70
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
70
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
70
  if (table_ptr == NULL)
4729
0
    return false;
4730
70
  else
4731
70
    {
4732
70
      coff_symbol_type *dst = cached_area;
4733
70
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
70
      unsigned int this_index = 0;
4735
4736
423
      while (this_index < last_native_index)
4737
353
  {
4738
353
    combined_entry_type *src = native_symbols + this_index;
4739
353
    table_ptr[this_index] = number_of_symbols;
4740
4741
353
    dst->symbol.the_bfd = abfd;
4742
353
    BFD_ASSERT (src->is_sym);
4743
353
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
353
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
353
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
353
                 src->u.syment.n_scnum);
4748
353
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
353
    dst->symbol.value = 0;
4751
353
    dst->done_lineno = false;
4752
4753
353
    switch (src->u.syment.n_sclass)
4754
353
      {
4755
6
      case C_EXT:
4756
6
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
6
#ifdef C_SYSTEM
4768
7
      case C_SYSTEM: /* System Wide variable.  */
4769
7
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
7
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
7
    {
4778
1
    case COFF_SYMBOL_GLOBAL:
4779
1
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
1
      dst->symbol.value = (src->u.syment.n_value
4786
1
               - dst->symbol.section->vma);
4787
1
#endif
4788
1
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
1
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1
      break;
4793
4794
4
    case COFF_SYMBOL_COMMON:
4795
4
      dst->symbol.section = bfd_com_section_ptr;
4796
4
      dst->symbol.value = src->u.syment.n_value;
4797
4
      break;
4798
4799
2
    case COFF_SYMBOL_UNDEFINED:
4800
2
      dst->symbol.section = bfd_und_section_ptr;
4801
2
      dst->symbol.value = 0;
4802
2
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
7
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
7
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
7
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
7
        break;
4846
4847
3
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
4
      case C_LABEL:  /* Label.  */
4858
4
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
4
        else
4861
4
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
4
        if (dst->symbol.section)
4866
4
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
4
      dst->symbol.value = (src->u.syment.n_value
4873
4
               - dst->symbol.section->vma);
4874
4
#endif
4875
4
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
4
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
3
      case C_REGPARM: /* Register parameter.  */
4886
5
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
9
      case C_TPDEF: /* Type definition.  */
4889
10
      case C_ARG:
4890
23
      case C_AUTO: /* Automatic variable.  */
4891
23
      case C_FIELD: /* Bit field.  */
4892
26
      case C_ENTAG: /* Enumeration tag.  */
4893
48
      case C_MOE:   /* Member of enumeration.  */
4894
48
      case C_MOU:   /* Member of union.  */
4895
49
      case C_UNTAG: /* Union tag.  */
4896
49
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
49
        dst->symbol.flags |= BSF_DEBUGGING;
4914
49
        dst->symbol.value = (src->u.syment.n_value);
4915
49
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
3
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
10
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
10
        dst->symbol.flags = BSF_LOCAL;
4984
10
        dst->symbol.value = (src->u.syment.n_value
4985
10
           - dst->symbol.section->vma);
4986
10
#endif
4987
10
        break;
4988
4989
3
      case C_STATLAB: /* Static load time label.  */
4990
3
        dst->symbol.value = src->u.syment.n_value;
4991
3
        dst->symbol.flags = BSF_GLOBAL;
4992
3
        break;
4993
4994
258
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
258
        if (src->u.syment.n_type == 0
4998
258
      && src->u.syment.n_value == 0
4999
258
      && src->u.syment.n_scnum == 0)
5000
118
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
141
      case C_EXTDEF: /* External definition.  */
5008
144
      case C_ULABEL: /* Undefined label.  */
5009
144
      case C_USTATIC: /* Undefined static.  */
5010
144
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
144
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
144
      case C_ALIAS: /* Duplicate tag.  */
5016
144
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
145
      case C_EXTLAB: /* External load time label.  */
5022
162
      default:
5023
162
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
162
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
162
     abfd, src->u.syment.n_sclass,
5027
162
     dst->symbol.section->name, dst->symbol.name);
5028
162
        ret = false;
5029
        /* Fall through.  */
5030
162
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
162
        dst->symbol.flags = BSF_DEBUGGING;
5034
162
        dst->symbol.value = (src->u.syment.n_value);
5035
162
        break;
5036
353
      }
5037
5038
353
    dst->native = src;
5039
353
    dst->symbol.udata.i = 0;
5040
353
    dst->lineno = NULL;
5041
5042
353
    this_index += (src->u.syment.n_numaux) + 1;
5043
353
    dst++;
5044
353
    number_of_symbols++;
5045
353
  }
5046
70
    }
5047
5048
70
  obj_symbols (abfd) = cached_area;
5049
70
  obj_raw_syments (abfd) = native_symbols;
5050
5051
70
  abfd->symcount = number_of_symbols;
5052
70
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
70
  {
5055
70
    asection *p;
5056
5057
70
    p = abfd->sections;
5058
165
    while (p)
5059
135
      {
5060
135
  if (! coff_slurp_line_table (abfd, p))
5061
40
    return false;
5062
95
  p = p->next;
5063
95
      }
5064
70
  }
5065
5066
30
  return ret;
5067
70
}
coff-z8k.c:coff_slurp_symbol_table
Line
Count
Source
4695
514
{
4696
514
  combined_entry_type *native_symbols;
4697
514
  coff_symbol_type *cached_area;
4698
514
  unsigned int *table_ptr;
4699
514
  unsigned int number_of_symbols = 0;
4700
514
  bool ret = true;
4701
514
  size_t amt;
4702
4703
514
  if (obj_symbols (abfd))
4704
161
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
353
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
263
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
90
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
90
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
90
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
90
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
90
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
90
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
90
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
90
  if (table_ptr == NULL)
4729
0
    return false;
4730
90
  else
4731
90
    {
4732
90
      coff_symbol_type *dst = cached_area;
4733
90
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
90
      unsigned int this_index = 0;
4735
4736
264
      while (this_index < last_native_index)
4737
174
  {
4738
174
    combined_entry_type *src = native_symbols + this_index;
4739
174
    table_ptr[this_index] = number_of_symbols;
4740
4741
174
    dst->symbol.the_bfd = abfd;
4742
174
    BFD_ASSERT (src->is_sym);
4743
174
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
174
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
174
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
174
                 src->u.syment.n_scnum);
4748
174
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
174
    dst->symbol.value = 0;
4751
174
    dst->done_lineno = false;
4752
4753
174
    switch (src->u.syment.n_sclass)
4754
174
      {
4755
12
      case C_EXT:
4756
13
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
13
#ifdef C_SYSTEM
4768
13
      case C_SYSTEM: /* System Wide variable.  */
4769
13
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
13
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
13
    {
4778
7
    case COFF_SYMBOL_GLOBAL:
4779
7
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
7
      dst->symbol.value = (src->u.syment.n_value
4786
7
               - dst->symbol.section->vma);
4787
7
#endif
4788
7
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
1
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
7
      break;
4793
4794
3
    case COFF_SYMBOL_COMMON:
4795
3
      dst->symbol.section = bfd_com_section_ptr;
4796
3
      dst->symbol.value = src->u.syment.n_value;
4797
3
      break;
4798
4799
3
    case COFF_SYMBOL_UNDEFINED:
4800
3
      dst->symbol.section = bfd_und_section_ptr;
4801
3
      dst->symbol.value = 0;
4802
3
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
0
      dst->symbol.value = (src->u.syment.n_value
4817
0
               - dst->symbol.section->vma);
4818
0
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
13
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
    dst->symbol.flags |= BSF_WEAK;
4833
4834
        if (src->u.syment.n_sclass == C_SECTION
4835
      && src->u.syment.n_scnum > 0)
4836
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
13
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
13
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
13
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
0
      dst->symbol.value = (src->u.syment.n_value
4873
0
               - dst->symbol.section->vma);
4874
0
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
1
      case C_FILE: /* File name.  */
4881
1
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
2
      case C_REGPARM: /* Register parameter.  */
4886
4
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
4
      case C_TPDEF: /* Type definition.  */
4889
4
      case C_ARG:
4890
5
      case C_AUTO: /* Automatic variable.  */
4891
6
      case C_FIELD: /* Bit field.  */
4892
6
      case C_ENTAG: /* Enumeration tag.  */
4893
7
      case C_MOE:   /* Member of enumeration.  */
4894
7
      case C_MOU:   /* Member of union.  */
4895
7
      case C_UNTAG: /* Union tag.  */
4896
7
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
7
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7
        dst->symbol.value = (src->u.syment.n_value);
4915
7
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
4
      case C_EFCN: /* Physical end of function.  */
4968
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
        dst->symbol.value = src->u.syment.n_value;
4972
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
      dst->symbol.flags = BSF_DEBUGGING;
4977
    }
4978
        else
4979
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
4
        dst->symbol.flags = BSF_LOCAL;
4984
4
        dst->symbol.value = (src->u.syment.n_value
4985
4
           - dst->symbol.section->vma);
4986
4
#endif
4987
4
        break;
4988
4989
11
      case C_STATLAB: /* Static load time label.  */
4990
11
        dst->symbol.value = src->u.syment.n_value;
4991
11
        dst->symbol.flags = BSF_GLOBAL;
4992
11
        break;
4993
4994
126
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
126
        if (src->u.syment.n_type == 0
4998
126
      && src->u.syment.n_value == 0
4999
126
      && src->u.syment.n_scnum == 0)
5000
52
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
74
      case C_EXTDEF: /* External definition.  */
5008
79
      case C_ULABEL: /* Undefined label.  */
5009
79
      case C_USTATIC: /* Undefined static.  */
5010
79
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
79
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
79
      case C_ALIAS: /* Duplicate tag.  */
5016
79
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
79
      case C_EXTLAB: /* External load time label.  */
5022
85
      default:
5023
85
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
85
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
85
     abfd, src->u.syment.n_sclass,
5027
85
     dst->symbol.section->name, dst->symbol.name);
5028
85
        ret = false;
5029
        /* Fall through.  */
5030
87
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
87
        dst->symbol.flags = BSF_DEBUGGING;
5034
87
        dst->symbol.value = (src->u.syment.n_value);
5035
87
        break;
5036
174
      }
5037
5038
174
    dst->native = src;
5039
174
    dst->symbol.udata.i = 0;
5040
174
    dst->lineno = NULL;
5041
5042
174
    this_index += (src->u.syment.n_numaux) + 1;
5043
174
    dst++;
5044
174
    number_of_symbols++;
5045
174
  }
5046
90
    }
5047
5048
90
  obj_symbols (abfd) = cached_area;
5049
90
  obj_raw_syments (abfd) = native_symbols;
5050
5051
90
  abfd->symcount = number_of_symbols;
5052
90
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
90
  {
5055
90
    asection *p;
5056
5057
90
    p = abfd->sections;
5058
207
    while (p)
5059
176
      {
5060
176
  if (! coff_slurp_line_table (abfd, p))
5061
59
    return false;
5062
117
  p = p->next;
5063
117
      }
5064
90
  }
5065
5066
31
  return ret;
5067
90
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_symbol_table
Unexecuted instantiation: pe-arm.c:coff_slurp_symbol_table
pe-i386.c:coff_slurp_symbol_table
Line
Count
Source
4695
89
{
4696
89
  combined_entry_type *native_symbols;
4697
89
  coff_symbol_type *cached_area;
4698
89
  unsigned int *table_ptr;
4699
89
  unsigned int number_of_symbols = 0;
4700
89
  bool ret = true;
4701
89
  size_t amt;
4702
4703
89
  if (obj_symbols (abfd))
4704
40
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
49
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
11
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
38
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
38
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
38
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
38
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
38
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
38
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
38
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
38
  if (table_ptr == NULL)
4729
0
    return false;
4730
38
  else
4731
38
    {
4732
38
      coff_symbol_type *dst = cached_area;
4733
38
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
38
      unsigned int this_index = 0;
4735
4736
76
      while (this_index < last_native_index)
4737
38
  {
4738
38
    combined_entry_type *src = native_symbols + this_index;
4739
38
    table_ptr[this_index] = number_of_symbols;
4740
4741
38
    dst->symbol.the_bfd = abfd;
4742
38
    BFD_ASSERT (src->is_sym);
4743
38
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
38
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
38
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
38
                 src->u.syment.n_scnum);
4748
38
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
38
    dst->symbol.value = 0;
4751
38
    dst->done_lineno = false;
4752
4753
38
    switch (src->u.syment.n_sclass)
4754
38
      {
4755
2
      case C_EXT:
4756
3
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
3
#ifdef C_SYSTEM
4768
4
      case C_SYSTEM: /* System Wide variable.  */
4769
4
#endif
4770
4
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
4
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
4
      case C_NT_WEAK:
4775
4
#endif
4776
4
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4
    {
4778
1
    case COFF_SYMBOL_GLOBAL:
4779
1
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
1
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
2
    case COFF_SYMBOL_UNDEFINED:
4800
2
      dst->symbol.section = bfd_und_section_ptr;
4801
2
      dst->symbol.value = 0;
4802
2
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
4
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
4
#ifdef COFF_WITH_PE
4831
4
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
4
        if (src->u.syment.n_sclass == C_SECTION
4835
4
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
4
#endif
4838
4
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
4
      )
4843
1
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1
      case C_MOS:   /* Member of structure.  */
4884
1
      case C_EOS:   /* End of structure.  */
4885
1
      case C_REGPARM: /* Register parameter.  */
4886
2
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2
      case C_TPDEF: /* Type definition.  */
4889
3
      case C_ARG:
4890
5
      case C_AUTO: /* Automatic variable.  */
4891
5
      case C_FIELD: /* Bit field.  */
4892
5
      case C_ENTAG: /* Enumeration tag.  */
4893
7
      case C_MOE:   /* Member of enumeration.  */
4894
7
      case C_MOU:   /* Member of union.  */
4895
7
      case C_UNTAG: /* Union tag.  */
4896
7
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
7
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7
        dst->symbol.value = (src->u.syment.n_value);
4915
7
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
3
      case C_EFCN: /* Physical end of function.  */
4968
3
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
3
        dst->symbol.value = src->u.syment.n_value;
4972
3
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
3
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
3
      dst->symbol.flags = BSF_DEBUGGING;
4977
3
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
3
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
23
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
23
        if (src->u.syment.n_type == 0
4998
23
      && src->u.syment.n_value == 0
4999
23
      && src->u.syment.n_scnum == 0)
5000
11
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
12
      case C_EXTDEF: /* External definition.  */
5008
12
      case C_ULABEL: /* Undefined label.  */
5009
12
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
12
      case C_EXTLAB: /* External load time label.  */
5022
13
      default:
5023
13
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
13
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
13
     abfd, src->u.syment.n_sclass,
5027
13
     dst->symbol.section->name, dst->symbol.name);
5028
13
        ret = false;
5029
        /* Fall through.  */
5030
13
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
13
        dst->symbol.flags = BSF_DEBUGGING;
5034
13
        dst->symbol.value = (src->u.syment.n_value);
5035
13
        break;
5036
38
      }
5037
5038
38
    dst->native = src;
5039
38
    dst->symbol.udata.i = 0;
5040
38
    dst->lineno = NULL;
5041
5042
38
    this_index += (src->u.syment.n_numaux) + 1;
5043
38
    dst++;
5044
38
    number_of_symbols++;
5045
38
  }
5046
38
    }
5047
5048
38
  obj_symbols (abfd) = cached_area;
5049
38
  obj_raw_syments (abfd) = native_symbols;
5050
5051
38
  abfd->symcount = number_of_symbols;
5052
38
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
38
  {
5055
38
    asection *p;
5056
5057
38
    p = abfd->sections;
5058
64
    while (p)
5059
39
      {
5060
39
  if (! coff_slurp_line_table (abfd, p))
5061
13
    return false;
5062
26
  p = p->next;
5063
26
      }
5064
38
  }
5065
5066
25
  return ret;
5067
38
}
pe-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
72
{
4696
72
  combined_entry_type *native_symbols;
4697
72
  coff_symbol_type *cached_area;
4698
72
  unsigned int *table_ptr;
4699
72
  unsigned int number_of_symbols = 0;
4700
72
  bool ret = true;
4701
72
  size_t amt;
4702
4703
72
  if (obj_symbols (abfd))
4704
11
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
61
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
35
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
26
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
26
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
26
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
26
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
26
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
26
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
26
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
26
  if (table_ptr == NULL)
4729
0
    return false;
4730
26
  else
4731
26
    {
4732
26
      coff_symbol_type *dst = cached_area;
4733
26
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
26
      unsigned int this_index = 0;
4735
4736
85
      while (this_index < last_native_index)
4737
59
  {
4738
59
    combined_entry_type *src = native_symbols + this_index;
4739
59
    table_ptr[this_index] = number_of_symbols;
4740
4741
59
    dst->symbol.the_bfd = abfd;
4742
59
    BFD_ASSERT (src->is_sym);
4743
59
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
59
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
59
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
59
                 src->u.syment.n_scnum);
4748
59
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
59
    dst->symbol.value = 0;
4751
59
    dst->done_lineno = false;
4752
4753
59
    switch (src->u.syment.n_sclass)
4754
59
      {
4755
0
      case C_EXT:
4756
8
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
8
#ifdef C_SYSTEM
4768
8
      case C_SYSTEM: /* System Wide variable.  */
4769
8
#endif
4770
8
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
8
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
8
      case C_NT_WEAK:
4775
8
#endif
4776
8
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
8
    {
4778
8
    case COFF_SYMBOL_GLOBAL:
4779
8
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
8
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
8
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
8
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
3
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
8
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
8
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
8
#ifdef COFF_WITH_PE
4831
8
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
8
        if (src->u.syment.n_sclass == C_SECTION
4835
8
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
8
#endif
4838
8
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
8
      )
4843
8
    dst->symbol.flags |= BSF_WEAK;
4844
4845
8
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
1
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
6
      case C_FILE: /* File name.  */
4881
6
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
6
      case C_MOS:   /* Member of structure.  */
4884
6
      case C_EOS:   /* End of structure.  */
4885
6
      case C_REGPARM: /* Register parameter.  */
4886
12
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
13
      case C_TPDEF: /* Type definition.  */
4889
13
      case C_ARG:
4890
15
      case C_AUTO: /* Automatic variable.  */
4891
15
      case C_FIELD: /* Bit field.  */
4892
15
      case C_ENTAG: /* Enumeration tag.  */
4893
16
      case C_MOE:   /* Member of enumeration.  */
4894
17
      case C_MOU:   /* Member of union.  */
4895
21
      case C_UNTAG: /* Union tag.  */
4896
21
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
21
        dst->symbol.flags |= BSF_DEBUGGING;
4914
21
        dst->symbol.value = (src->u.syment.n_value);
4915
21
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
2
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
2
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
3
      case C_EFCN: /* Physical end of function.  */
4968
3
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
3
        dst->symbol.value = src->u.syment.n_value;
4972
3
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
3
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
3
      dst->symbol.flags = BSF_DEBUGGING;
4977
3
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
3
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
17
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
17
        if (src->u.syment.n_type == 0
4998
17
      && src->u.syment.n_value == 0
4999
17
      && src->u.syment.n_scnum == 0)
5000
5
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
13
      case C_EXTDEF: /* External definition.  */
5008
13
      case C_ULABEL: /* Undefined label.  */
5009
13
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
13
      case C_EXTLAB: /* External load time label.  */
5022
20
      default:
5023
20
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
20
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
20
     abfd, src->u.syment.n_sclass,
5027
20
     dst->symbol.section->name, dst->symbol.name);
5028
20
        ret = false;
5029
        /* Fall through.  */
5030
21
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
21
        dst->symbol.flags = BSF_DEBUGGING;
5034
21
        dst->symbol.value = (src->u.syment.n_value);
5035
21
        break;
5036
59
      }
5037
5038
59
    dst->native = src;
5039
59
    dst->symbol.udata.i = 0;
5040
59
    dst->lineno = NULL;
5041
5042
59
    this_index += (src->u.syment.n_numaux) + 1;
5043
59
    dst++;
5044
59
    number_of_symbols++;
5045
59
  }
5046
26
    }
5047
5048
26
  obj_symbols (abfd) = cached_area;
5049
26
  obj_raw_syments (abfd) = native_symbols;
5050
5051
26
  abfd->symcount = number_of_symbols;
5052
26
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
26
  {
5055
26
    asection *p;
5056
5057
26
    p = abfd->sections;
5058
153
    while (p)
5059
134
      {
5060
134
  if (! coff_slurp_line_table (abfd, p))
5061
7
    return false;
5062
127
  p = p->next;
5063
127
      }
5064
26
  }
5065
5066
19
  return ret;
5067
26
}
pe-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
62
{
4696
62
  combined_entry_type *native_symbols;
4697
62
  coff_symbol_type *cached_area;
4698
62
  unsigned int *table_ptr;
4699
62
  unsigned int number_of_symbols = 0;
4700
62
  bool ret = true;
4701
62
  size_t amt;
4702
4703
62
  if (obj_symbols (abfd))
4704
16
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
46
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
16
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
30
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
30
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
30
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
30
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
30
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
30
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
30
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
30
  if (table_ptr == NULL)
4729
0
    return false;
4730
30
  else
4731
30
    {
4732
30
      coff_symbol_type *dst = cached_area;
4733
30
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
30
      unsigned int this_index = 0;
4735
4736
369
      while (this_index < last_native_index)
4737
339
  {
4738
339
    combined_entry_type *src = native_symbols + this_index;
4739
339
    table_ptr[this_index] = number_of_symbols;
4740
4741
339
    dst->symbol.the_bfd = abfd;
4742
339
    BFD_ASSERT (src->is_sym);
4743
339
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
339
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
339
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
339
                 src->u.syment.n_scnum);
4748
339
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
339
    dst->symbol.value = 0;
4751
339
    dst->done_lineno = false;
4752
4753
339
    switch (src->u.syment.n_sclass)
4754
339
      {
4755
1
      case C_EXT:
4756
1
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
1
#ifdef C_SYSTEM
4768
1
      case C_SYSTEM: /* System Wide variable.  */
4769
1
#endif
4770
1
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2
      case C_NT_WEAK:
4775
2
#endif
4776
2
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2
    {
4778
1
    case COFF_SYMBOL_GLOBAL:
4779
1
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
1
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1
      break;
4793
4794
1
    case COFF_SYMBOL_COMMON:
4795
1
      dst->symbol.section = bfd_com_section_ptr;
4796
1
      dst->symbol.value = src->u.syment.n_value;
4797
1
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
2
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
2
#ifdef COFF_WITH_PE
4831
2
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2
        if (src->u.syment.n_sclass == C_SECTION
4835
2
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2
#endif
4838
2
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
2
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2
        break;
4846
4847
1
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
1
      case C_LABEL:  /* Label.  */
4858
1
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1
        else
4861
1
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
1
        if (dst->symbol.section)
4866
1
    {
4867
1
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
1
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1
        break;
4879
4880
2
      case C_FILE: /* File name.  */
4881
2
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
3
      case C_MOS:   /* Member of structure.  */
4884
3
      case C_EOS:   /* End of structure.  */
4885
4
      case C_REGPARM: /* Register parameter.  */
4886
5
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
5
      case C_TPDEF: /* Type definition.  */
4889
5
      case C_ARG:
4890
6
      case C_AUTO: /* Automatic variable.  */
4891
6
      case C_FIELD: /* Bit field.  */
4892
6
      case C_ENTAG: /* Enumeration tag.  */
4893
7
      case C_MOE:   /* Member of enumeration.  */
4894
7
      case C_MOU:   /* Member of union.  */
4895
8
      case C_UNTAG: /* Union tag.  */
4896
8
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
8
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8
        dst->symbol.value = (src->u.syment.n_value);
4915
8
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
1
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
4
      case C_EFCN: /* Physical end of function.  */
4968
4
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
4
        dst->symbol.value = src->u.syment.n_value;
4972
4
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
4
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
4
      dst->symbol.flags = BSF_DEBUGGING;
4977
4
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
4
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
317
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
317
        if (src->u.syment.n_type == 0
4998
317
      && src->u.syment.n_value == 0
4999
317
      && src->u.syment.n_scnum == 0)
5000
292
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
25
      case C_EXTDEF: /* External definition.  */
5008
25
      case C_ULABEL: /* Undefined label.  */
5009
25
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
25
      case C_EXTLAB: /* External load time label.  */
5022
32
      default:
5023
32
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
32
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
32
     abfd, src->u.syment.n_sclass,
5027
32
     dst->symbol.section->name, dst->symbol.name);
5028
32
        ret = false;
5029
        /* Fall through.  */
5030
32
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
32
        dst->symbol.flags = BSF_DEBUGGING;
5034
32
        dst->symbol.value = (src->u.syment.n_value);
5035
32
        break;
5036
339
      }
5037
5038
339
    dst->native = src;
5039
339
    dst->symbol.udata.i = 0;
5040
339
    dst->lineno = NULL;
5041
5042
339
    this_index += (src->u.syment.n_numaux) + 1;
5043
339
    dst++;
5044
339
    number_of_symbols++;
5045
339
  }
5046
30
    }
5047
5048
30
  obj_symbols (abfd) = cached_area;
5049
30
  obj_raw_syments (abfd) = native_symbols;
5050
5051
30
  abfd->symcount = number_of_symbols;
5052
30
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
30
  {
5055
30
    asection *p;
5056
5057
30
    p = abfd->sections;
5058
70
    while (p)
5059
54
      {
5060
54
  if (! coff_slurp_line_table (abfd, p))
5061
14
    return false;
5062
40
  p = p->next;
5063
40
      }
5064
30
  }
5065
5066
16
  return ret;
5067
30
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_symbol_table
pei-arm.c:coff_slurp_symbol_table
Line
Count
Source
4695
1
{
4696
1
  combined_entry_type *native_symbols;
4697
1
  coff_symbol_type *cached_area;
4698
1
  unsigned int *table_ptr;
4699
1
  unsigned int number_of_symbols = 0;
4700
1
  bool ret = true;
4701
1
  size_t amt;
4702
4703
1
  if (obj_symbols (abfd))
4704
0
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
1
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
0
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
0
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
0
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
0
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
0
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
0
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
0
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
0
  if (table_ptr == NULL)
4729
0
    return false;
4730
0
  else
4731
0
    {
4732
0
      coff_symbol_type *dst = cached_area;
4733
0
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
0
      unsigned int this_index = 0;
4735
4736
0
      while (this_index < last_native_index)
4737
0
  {
4738
0
    combined_entry_type *src = native_symbols + this_index;
4739
0
    table_ptr[this_index] = number_of_symbols;
4740
4741
0
    dst->symbol.the_bfd = abfd;
4742
0
    BFD_ASSERT (src->is_sym);
4743
0
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
0
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
0
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
0
                 src->u.syment.n_scnum);
4748
0
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
0
    dst->symbol.value = 0;
4751
0
    dst->done_lineno = false;
4752
4753
0
    switch (src->u.syment.n_sclass)
4754
0
      {
4755
0
      case C_EXT:
4756
0
      case C_WEAKEXT:
4757
0
#if defined ARM
4758
0
      case C_THUMBEXT:
4759
0
      case C_THUMBEXTFUNC:
4760
0
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
0
#ifdef C_SYSTEM
4768
0
      case C_SYSTEM: /* System Wide variable.  */
4769
0
#endif
4770
0
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
0
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
0
      case C_NT_WEAK:
4775
0
#endif
4776
0
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
0
    {
4778
0
    case COFF_SYMBOL_GLOBAL:
4779
0
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
0
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
0
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
0
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
0
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
0
    case COFF_SYMBOL_UNDEFINED:
4800
0
      dst->symbol.section = bfd_und_section_ptr;
4801
0
      dst->symbol.value = 0;
4802
0
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
0
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
0
#ifdef COFF_WITH_PE
4831
0
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
0
        if (src->u.syment.n_sclass == C_SECTION
4835
0
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
0
#endif
4838
0
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
0
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
0
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
0
#if defined ARM
4849
0
      case C_THUMBSTAT:    /* Thumb static.  */
4850
0
      case C_THUMBLABEL:   /* Thumb label.  */
4851
0
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
0
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
0
      case C_AUTO: /* Automatic variable.  */
4891
0
      case C_FIELD: /* Bit field.  */
4892
0
      case C_ENTAG: /* Enumeration tag.  */
4893
0
      case C_MOE:   /* Member of enumeration.  */
4894
0
      case C_MOU:   /* Member of union.  */
4895
0
      case C_UNTAG: /* Union tag.  */
4896
0
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
0
        dst->symbol.flags |= BSF_DEBUGGING;
4914
0
        dst->symbol.value = (src->u.syment.n_value);
4915
0
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
0
      case C_EFCN: /* Physical end of function.  */
4968
0
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
0
        dst->symbol.value = src->u.syment.n_value;
4972
0
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
0
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
0
      dst->symbol.flags = BSF_DEBUGGING;
4977
0
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
0
        break;
4988
4989
0
      case C_STATLAB: /* Static load time label.  */
4990
0
        dst->symbol.value = src->u.syment.n_value;
4991
0
        dst->symbol.flags = BSF_GLOBAL;
4992
0
        break;
4993
4994
0
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
0
        if (src->u.syment.n_type == 0
4998
0
      && src->u.syment.n_value == 0
4999
0
      && src->u.syment.n_scnum == 0)
5000
0
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
0
      case C_EXTDEF: /* External definition.  */
5008
0
      case C_ULABEL: /* Undefined label.  */
5009
0
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
0
      case C_EXTLAB: /* External load time label.  */
5022
0
      default:
5023
0
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
0
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
0
     abfd, src->u.syment.n_sclass,
5027
0
     dst->symbol.section->name, dst->symbol.name);
5028
0
        ret = false;
5029
        /* Fall through.  */
5030
0
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
0
        dst->symbol.flags = BSF_DEBUGGING;
5034
0
        dst->symbol.value = (src->u.syment.n_value);
5035
0
        break;
5036
0
      }
5037
5038
0
    dst->native = src;
5039
0
    dst->symbol.udata.i = 0;
5040
0
    dst->lineno = NULL;
5041
5042
0
    this_index += (src->u.syment.n_numaux) + 1;
5043
0
    dst++;
5044
0
    number_of_symbols++;
5045
0
  }
5046
0
    }
5047
5048
0
  obj_symbols (abfd) = cached_area;
5049
0
  obj_raw_syments (abfd) = native_symbols;
5050
5051
0
  abfd->symcount = number_of_symbols;
5052
0
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
0
  {
5055
0
    asection *p;
5056
5057
0
    p = abfd->sections;
5058
0
    while (p)
5059
0
      {
5060
0
  if (! coff_slurp_line_table (abfd, p))
5061
0
    return false;
5062
0
  p = p->next;
5063
0
      }
5064
0
  }
5065
5066
0
  return ret;
5067
0
}
pei-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
15
{
4696
15
  combined_entry_type *native_symbols;
4697
15
  coff_symbol_type *cached_area;
4698
15
  unsigned int *table_ptr;
4699
15
  unsigned int number_of_symbols = 0;
4700
15
  bool ret = true;
4701
15
  size_t amt;
4702
4703
15
  if (obj_symbols (abfd))
4704
2
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
13
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
7
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
6
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
6
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
6
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
6
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
6
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
6
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
6
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
6
  if (table_ptr == NULL)
4729
0
    return false;
4730
6
  else
4731
6
    {
4732
6
      coff_symbol_type *dst = cached_area;
4733
6
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
6
      unsigned int this_index = 0;
4735
4736
35
      while (this_index < last_native_index)
4737
29
  {
4738
29
    combined_entry_type *src = native_symbols + this_index;
4739
29
    table_ptr[this_index] = number_of_symbols;
4740
4741
29
    dst->symbol.the_bfd = abfd;
4742
29
    BFD_ASSERT (src->is_sym);
4743
29
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
29
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
29
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
29
                 src->u.syment.n_scnum);
4748
29
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
29
    dst->symbol.value = 0;
4751
29
    dst->done_lineno = false;
4752
4753
29
    switch (src->u.syment.n_sclass)
4754
29
      {
4755
5
      case C_EXT:
4756
5
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
5
#ifdef C_SYSTEM
4768
5
      case C_SYSTEM: /* System Wide variable.  */
4769
5
#endif
4770
5
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
6
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
6
      case C_NT_WEAK:
4775
6
#endif
4776
6
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6
    {
4778
2
    case COFF_SYMBOL_GLOBAL:
4779
2
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
2
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2
      break;
4793
4794
0
    case COFF_SYMBOL_COMMON:
4795
0
      dst->symbol.section = bfd_com_section_ptr;
4796
0
      dst->symbol.value = src->u.syment.n_value;
4797
0
      break;
4798
4799
4
    case COFF_SYMBOL_UNDEFINED:
4800
4
      dst->symbol.section = bfd_und_section_ptr;
4801
4
      dst->symbol.value = 0;
4802
4
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
6
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
6
#ifdef COFF_WITH_PE
4831
6
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
6
        if (src->u.syment.n_sclass == C_SECTION
4835
6
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
6
#endif
4838
6
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
6
      )
4843
0
    dst->symbol.flags |= BSF_WEAK;
4844
4845
6
        break;
4846
4847
0
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
0
      case C_LABEL:  /* Label.  */
4858
0
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
0
        else
4861
0
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
0
        if (dst->symbol.section)
4866
0
    {
4867
0
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
0
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
0
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
0
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
2
      case C_AUTO: /* Automatic variable.  */
4891
2
      case C_FIELD: /* Bit field.  */
4892
2
      case C_ENTAG: /* Enumeration tag.  */
4893
2
      case C_MOE:   /* Member of enumeration.  */
4894
2
      case C_MOU:   /* Member of union.  */
4895
2
      case C_UNTAG: /* Union tag.  */
4896
6
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
6
        dst->symbol.flags |= BSF_DEBUGGING;
4914
6
        dst->symbol.value = (src->u.syment.n_value);
4915
6
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1
      case C_EFCN: /* Physical end of function.  */
4968
1
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1
        dst->symbol.value = src->u.syment.n_value;
4972
1
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1
      dst->symbol.flags = BSF_DEBUGGING;
4977
1
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
1
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
13
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
13
        if (src->u.syment.n_type == 0
4998
13
      && src->u.syment.n_value == 0
4999
13
      && src->u.syment.n_scnum == 0)
5000
7
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
6
      case C_EXTDEF: /* External definition.  */
5008
6
      case C_ULABEL: /* Undefined label.  */
5009
6
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
6
      case C_EXTLAB: /* External load time label.  */
5022
8
      default:
5023
8
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
8
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
8
     abfd, src->u.syment.n_sclass,
5027
8
     dst->symbol.section->name, dst->symbol.name);
5028
8
        ret = false;
5029
        /* Fall through.  */
5030
8
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
8
        dst->symbol.flags = BSF_DEBUGGING;
5034
8
        dst->symbol.value = (src->u.syment.n_value);
5035
8
        break;
5036
29
      }
5037
5038
29
    dst->native = src;
5039
29
    dst->symbol.udata.i = 0;
5040
29
    dst->lineno = NULL;
5041
5042
29
    this_index += (src->u.syment.n_numaux) + 1;
5043
29
    dst++;
5044
29
    number_of_symbols++;
5045
29
  }
5046
6
    }
5047
5048
6
  obj_symbols (abfd) = cached_area;
5049
6
  obj_raw_syments (abfd) = native_symbols;
5050
5051
6
  abfd->symcount = number_of_symbols;
5052
6
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
6
  {
5055
6
    asection *p;
5056
5057
6
    p = abfd->sections;
5058
8
    while (p)
5059
5
      {
5060
5
  if (! coff_slurp_line_table (abfd, p))
5061
3
    return false;
5062
2
  p = p->next;
5063
2
      }
5064
6
  }
5065
5066
3
  return ret;
5067
6
}
pei-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
130
{
4696
130
  combined_entry_type *native_symbols;
4697
130
  coff_symbol_type *cached_area;
4698
130
  unsigned int *table_ptr;
4699
130
  unsigned int number_of_symbols = 0;
4700
130
  bool ret = true;
4701
130
  size_t amt;
4702
4703
130
  if (obj_symbols (abfd))
4704
113
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
17
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
6
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
11
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
11
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
11
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
11
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
11
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
11
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
11
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
11
  if (table_ptr == NULL)
4729
0
    return false;
4730
11
  else
4731
11
    {
4732
11
      coff_symbol_type *dst = cached_area;
4733
11
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
11
      unsigned int this_index = 0;
4735
4736
54
      while (this_index < last_native_index)
4737
43
  {
4738
43
    combined_entry_type *src = native_symbols + this_index;
4739
43
    table_ptr[this_index] = number_of_symbols;
4740
4741
43
    dst->symbol.the_bfd = abfd;
4742
43
    BFD_ASSERT (src->is_sym);
4743
43
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
43
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
43
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
43
                 src->u.syment.n_scnum);
4748
43
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
43
    dst->symbol.value = 0;
4751
43
    dst->done_lineno = false;
4752
4753
43
    switch (src->u.syment.n_sclass)
4754
43
      {
4755
12
      case C_EXT:
4756
18
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
18
#ifdef C_SYSTEM
4768
18
      case C_SYSTEM: /* System Wide variable.  */
4769
18
#endif
4770
18
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
18
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
18
      case C_NT_WEAK:
4775
18
#endif
4776
18
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
18
    {
4778
4
    case COFF_SYMBOL_GLOBAL:
4779
4
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
4
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
4
      dst->symbol.value = src->u.syment.n_value;
4784
#else
4785
      dst->symbol.value = (src->u.syment.n_value
4786
               - dst->symbol.section->vma);
4787
#endif
4788
4
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
4
      break;
4793
4794
12
    case COFF_SYMBOL_COMMON:
4795
12
      dst->symbol.section = bfd_com_section_ptr;
4796
12
      dst->symbol.value = src->u.syment.n_value;
4797
12
      break;
4798
4799
2
    case COFF_SYMBOL_UNDEFINED:
4800
2
      dst->symbol.section = bfd_und_section_ptr;
4801
2
      dst->symbol.value = 0;
4802
2
      break;
4803
4804
0
    case COFF_SYMBOL_PE_SECTION:
4805
0
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
0
      dst->symbol.value = 0;
4807
0
      break;
4808
4809
0
    case COFF_SYMBOL_LOCAL:
4810
0
      dst->symbol.flags = BSF_LOCAL;
4811
0
#if defined COFF_WITH_PE
4812
      /* PE sets the symbol to a value relative to the
4813
         start of the section.  */
4814
0
      dst->symbol.value = src->u.syment.n_value;
4815
#else
4816
      dst->symbol.value = (src->u.syment.n_value
4817
               - dst->symbol.section->vma);
4818
#endif
4819
0
      if (ISFCN ((src->u.syment.n_type)))
4820
0
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
0
      break;
4822
18
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
        if (src->u.syment.n_numaux > 0)
4827
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
18
#ifdef COFF_WITH_PE
4831
18
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
0
    dst->symbol.flags |= BSF_WEAK;
4833
4834
18
        if (src->u.syment.n_sclass == C_SECTION
4835
18
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
18
#endif
4838
18
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
18
      )
4843
6
    dst->symbol.flags |= BSF_WEAK;
4844
4845
18
        break;
4846
4847
2
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
      case C_THUMBSTAT:    /* Thumb static.  */
4850
      case C_THUMBLABEL:   /* Thumb label.  */
4851
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
      case C_DWARF:  /* A label in a dwarf section.  */
4855
      case C_INFO:   /* A label in a comment section.  */
4856
#endif
4857
2
      case C_LABEL:  /* Label.  */
4858
2
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
2
        else
4861
2
    dst->symbol.flags = BSF_LOCAL;
4862
4863
        /* Base the value as an index from the base of the
4864
     section, if there is one.  */
4865
2
        if (dst->symbol.section)
4866
2
    {
4867
2
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
2
      dst->symbol.value = src->u.syment.n_value;
4871
#else
4872
      dst->symbol.value = (src->u.syment.n_value
4873
               - dst->symbol.section->vma);
4874
#endif
4875
2
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
2
        break;
4879
4880
0
      case C_FILE: /* File name.  */
4881
0
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
0
      case C_MOS:   /* Member of structure.  */
4884
0
      case C_EOS:   /* End of structure.  */
4885
0
      case C_REGPARM: /* Register parameter.  */
4886
0
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
0
      case C_TPDEF: /* Type definition.  */
4889
0
      case C_ARG:
4890
3
      case C_AUTO: /* Automatic variable.  */
4891
3
      case C_FIELD: /* Bit field.  */
4892
3
      case C_ENTAG: /* Enumeration tag.  */
4893
3
      case C_MOE:   /* Member of enumeration.  */
4894
3
      case C_MOU:   /* Member of union.  */
4895
3
      case C_UNTAG: /* Union tag.  */
4896
3
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
3
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3
        dst->symbol.value = (src->u.syment.n_value);
4915
3
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
0
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
0
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2
      case C_EFCN: /* Physical end of function.  */
4968
2
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
2
        dst->symbol.value = src->u.syment.n_value;
4972
2
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
2
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
2
      dst->symbol.flags = BSF_DEBUGGING;
4977
2
    }
4978
0
        else
4979
0
    dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
4980
#else
4981
        /* Base the value as an index from the base of the
4982
     section.  */
4983
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
2
        break;
4988
4989
1
      case C_STATLAB: /* Static load time label.  */
4990
1
        dst->symbol.value = src->u.syment.n_value;
4991
1
        dst->symbol.flags = BSF_GLOBAL;
4992
1
        break;
4993
4994
15
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
15
        if (src->u.syment.n_type == 0
4998
15
      && src->u.syment.n_value == 0
4999
15
      && src->u.syment.n_scnum == 0)
5000
9
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
6
      case C_EXTDEF: /* External definition.  */
5008
6
      case C_ULABEL: /* Undefined label.  */
5009
6
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
6
      case C_EXTLAB: /* External load time label.  */
5022
8
      default:
5023
8
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
8
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
8
     abfd, src->u.syment.n_sclass,
5027
8
     dst->symbol.section->name, dst->symbol.name);
5028
8
        ret = false;
5029
        /* Fall through.  */
5030
8
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
8
        dst->symbol.flags = BSF_DEBUGGING;
5034
8
        dst->symbol.value = (src->u.syment.n_value);
5035
8
        break;
5036
43
      }
5037
5038
43
    dst->native = src;
5039
43
    dst->symbol.udata.i = 0;
5040
43
    dst->lineno = NULL;
5041
5042
43
    this_index += (src->u.syment.n_numaux) + 1;
5043
43
    dst++;
5044
43
    number_of_symbols++;
5045
43
  }
5046
11
    }
5047
5048
11
  obj_symbols (abfd) = cached_area;
5049
11
  obj_raw_syments (abfd) = native_symbols;
5050
5051
11
  abfd->symcount = number_of_symbols;
5052
11
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
11
  {
5055
11
    asection *p;
5056
5057
11
    p = abfd->sections;
5058
14
    while (p)
5059
11
      {
5060
11
  if (! coff_slurp_line_table (abfd, p))
5061
8
    return false;
5062
3
  p = p->next;
5063
3
      }
5064
11
  }
5065
5066
3
  return ret;
5067
11
}
5068
5069
/* Classify a COFF symbol.  A couple of targets have globally visible
5070
   symbols which are not class C_EXT, and this handles those.  It also
5071
   recognizes some special PE cases.  */
5072
5073
static enum coff_symbol_classification
5074
coff_classify_symbol (bfd *abfd,
5075
          struct internal_syment *syment)
5076
376
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
376
  switch (syment->n_sclass)
5080
376
    {
5081
307
    case C_EXT:
5082
349
    case C_WEAKEXT:
5083
#ifdef ARM
5084
0
    case C_THUMBEXT:
5085
0
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
31
    case C_HIDEXT:
5089
31
#ifndef AIX_WEAK_SUPPORT
5090
35
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
35
#ifdef C_SYSTEM
5094
373
    case C_SYSTEM:
5095
373
#endif
5096
#ifdef COFF_WITH_PE
5097
284
    case C_NT_WEAK:
5098
#endif
5099
374
      if (syment->n_scnum == 0)
5100
117
  {
5101
117
    if (syment->n_value == 0)
5102
71
      return COFF_SYMBOL_UNDEFINED;
5103
46
    else
5104
46
      return COFF_SYMBOL_COMMON;
5105
117
  }
5106
#ifdef RS6000COFF_C
5107
37
      if (syment->n_sclass == C_HIDEXT)
5108
7
  return COFF_SYMBOL_LOCAL;
5109
30
#endif
5110
250
      return COFF_SYMBOL_GLOBAL;
5111
5112
2
    default:
5113
2
      break;
5114
376
    }
5115
5116
#ifdef COFF_WITH_PE
5117
2
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
2
  if (syment->n_sclass == C_SECTION)
5147
2
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
2
      syment->n_value = 0;
5152
2
      if (syment->n_scnum == 0)
5153
2
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
2
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
2
}
pei-i386.c:coff_classify_symbol
Line
Count
Source
5076
4
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4
  switch (syment->n_sclass)
5080
4
    {
5081
0
    case C_EXT:
5082
4
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
4
#ifdef C_SYSTEM
5094
4
    case C_SYSTEM:
5095
4
#endif
5096
4
#ifdef COFF_WITH_PE
5097
4
    case C_NT_WEAK:
5098
4
#endif
5099
4
      if (syment->n_scnum == 0)
5100
2
  {
5101
2
    if (syment->n_value == 0)
5102
1
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
2
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
4
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pe-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
4
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4
  switch (syment->n_sclass)
5080
4
    {
5081
3
    case C_EXT:
5082
3
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
3
#ifdef C_SYSTEM
5094
4
    case C_SYSTEM:
5095
4
#endif
5096
4
#ifdef COFF_WITH_PE
5097
4
    case C_NT_WEAK:
5098
4
#endif
5099
4
      if (syment->n_scnum == 0)
5100
4
  {
5101
4
    if (syment->n_value == 0)
5102
4
      return COFF_SYMBOL_UNDEFINED;
5103
0
    else
5104
0
      return COFF_SYMBOL_COMMON;
5105
4
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
0
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
4
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
221
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
221
  switch (syment->n_sclass)
5080
221
    {
5081
220
    case C_EXT:
5082
220
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
220
#ifdef C_SYSTEM
5094
220
    case C_SYSTEM:
5095
220
#endif
5096
220
#ifdef COFF_WITH_PE
5097
220
    case C_NT_WEAK:
5098
220
#endif
5099
220
      if (syment->n_scnum == 0)
5100
42
  {
5101
42
    if (syment->n_value == 0)
5102
40
      return COFF_SYMBOL_UNDEFINED;
5103
2
    else
5104
2
      return COFF_SYMBOL_COMMON;
5105
42
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
178
      return COFF_SYMBOL_GLOBAL;
5111
5112
1
    default:
5113
1
      break;
5114
221
    }
5115
5116
1
#ifdef COFF_WITH_PE
5117
1
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
1
  if (syment->n_sclass == C_SECTION)
5147
1
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
1
      syment->n_value = 0;
5152
1
      if (syment->n_scnum == 0)
5153
1
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
1
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
1
}
coff-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
12
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
12
  switch (syment->n_sclass)
5080
12
    {
5081
6
    case C_EXT:
5082
7
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
7
#ifdef C_SYSTEM
5094
12
    case C_SYSTEM:
5095
12
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
12
      if (syment->n_scnum == 0)
5100
9
  {
5101
9
    if (syment->n_value == 0)
5102
7
      return COFF_SYMBOL_UNDEFINED;
5103
2
    else
5104
2
      return COFF_SYMBOL_COMMON;
5105
9
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
3
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
12
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
12
}
coff64-rs6000.c:coff_classify_symbol
Line
Count
Source
5076
3
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3
  switch (syment->n_sclass)
5080
3
    {
5081
2
    case C_EXT:
5082
3
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
3
#ifdef RS6000COFF_C
5088
3
    case C_HIDEXT:
5089
3
#ifndef AIX_WEAK_SUPPORT
5090
3
    case C_AIX_WEAKEXT:
5091
3
#endif
5092
3
#endif
5093
3
#ifdef C_SYSTEM
5094
3
    case C_SYSTEM:
5095
3
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
3
      if (syment->n_scnum == 0)
5100
2
  {
5101
2
    if (syment->n_value == 0)
5102
1
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
2
  }
5106
1
#ifdef RS6000COFF_C
5107
1
      if (syment->n_sclass == C_HIDEXT)
5108
0
  return COFF_SYMBOL_LOCAL;
5109
1
#endif
5110
1
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
3
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
3
}
pe-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
1
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1
  switch (syment->n_sclass)
5080
1
    {
5081
1
    case C_EXT:
5082
1
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
1
#ifdef C_SYSTEM
5094
1
    case C_SYSTEM:
5095
1
#endif
5096
1
#ifdef COFF_WITH_PE
5097
1
    case C_NT_WEAK:
5098
1
#endif
5099
1
      if (syment->n_scnum == 0)
5100
1
  {
5101
1
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
1
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
0
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
1
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
9
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
9
  switch (syment->n_sclass)
5080
9
    {
5081
5
    case C_EXT:
5082
9
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
9
#ifdef C_SYSTEM
5094
9
    case C_SYSTEM:
5095
9
#endif
5096
9
#ifdef COFF_WITH_PE
5097
9
    case C_NT_WEAK:
5098
9
#endif
5099
9
      if (syment->n_scnum == 0)
5100
7
  {
5101
7
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
7
    else
5104
7
      return COFF_SYMBOL_COMMON;
5105
7
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
9
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-ia64.c:coff_classify_symbol
Line
Count
Source
5076
6
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
6
  switch (syment->n_sclass)
5080
6
    {
5081
0
    case C_EXT:
5082
6
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
6
#ifdef C_SYSTEM
5094
6
    case C_SYSTEM:
5095
6
#endif
5096
6
#ifdef COFF_WITH_PE
5097
6
    case C_NT_WEAK:
5098
6
#endif
5099
6
      if (syment->n_scnum == 0)
5100
1
  {
5101
1
    if (syment->n_value == 0)
5102
1
      return COFF_SYMBOL_UNDEFINED;
5103
0
    else
5104
0
      return COFF_SYMBOL_COMMON;
5105
1
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
5
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
6
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pei-loongarch64.c:coff_classify_symbol
Line
Count
Source
5076
3
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3
  switch (syment->n_sclass)
5080
3
    {
5081
3
    case C_EXT:
5082
3
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
3
#ifdef C_SYSTEM
5094
3
    case C_SYSTEM:
5095
3
#endif
5096
3
#ifdef COFF_WITH_PE
5097
3
    case C_NT_WEAK:
5098
3
#endif
5099
3
      if (syment->n_scnum == 0)
5100
3
  {
5101
3
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
3
    else
5104
3
      return COFF_SYMBOL_COMMON;
5105
3
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
0
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
3
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
Unexecuted instantiation: cf-i386lynx.c:coff_classify_symbol
Unexecuted instantiation: coff-go32.c:coff_classify_symbol
Unexecuted instantiation: coff-i386.c:coff_classify_symbol
coff-rs6000.c:coff_classify_symbol
Line
Count
Source
5076
37
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
37
  switch (syment->n_sclass)
5080
37
    {
5081
12
    case C_EXT:
5082
21
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
21
#ifdef RS6000COFF_C
5088
28
    case C_HIDEXT:
5089
28
#ifndef AIX_WEAK_SUPPORT
5090
32
    case C_AIX_WEAKEXT:
5091
32
#endif
5092
32
#endif
5093
32
#ifdef C_SYSTEM
5094
37
    case C_SYSTEM:
5095
37
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
37
      if (syment->n_scnum == 0)
5100
1
  {
5101
1
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
1
  }
5106
36
#ifdef RS6000COFF_C
5107
36
      if (syment->n_sclass == C_HIDEXT)
5108
7
  return COFF_SYMBOL_LOCAL;
5109
29
#endif
5110
29
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
37
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
37
}
coff-sh.c:coff_classify_symbol
Line
Count
Source
5076
8
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
8
  switch (syment->n_sclass)
5080
8
    {
5081
8
    case C_EXT:
5082
8
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
8
#ifdef C_SYSTEM
5094
8
    case C_SYSTEM:
5095
8
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
8
      if (syment->n_scnum == 0)
5100
6
  {
5101
6
    if (syment->n_value == 0)
5102
5
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
6
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
8
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
8
}
Unexecuted instantiation: coff-stgo32.c:coff_classify_symbol
coff-tic30.c:coff_classify_symbol
Line
Count
Source
5076
6
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
6
  switch (syment->n_sclass)
5080
6
    {
5081
5
    case C_EXT:
5082
6
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
6
#ifdef C_SYSTEM
5094
6
    case C_SYSTEM:
5095
6
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
6
      if (syment->n_scnum == 0)
5100
2
  {
5101
2
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
2
    else
5104
2
      return COFF_SYMBOL_COMMON;
5105
2
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
4
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
6
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
6
}
Unexecuted instantiation: coff-tic4x.c:coff_classify_symbol
coff-tic54x.c:coff_classify_symbol
Line
Count
Source
5076
4
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4
  switch (syment->n_sclass)
5080
4
    {
5081
4
    case C_EXT:
5082
4
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
4
#ifdef C_SYSTEM
5094
4
    case C_SYSTEM:
5095
4
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
4
      if (syment->n_scnum == 0)
5100
4
  {
5101
4
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
4
    else
5104
4
      return COFF_SYMBOL_COMMON;
5105
4
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
0
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
4
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
4
}
coff-z80.c:coff_classify_symbol
Line
Count
Source
5076
7
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
7
  switch (syment->n_sclass)
5080
7
    {
5081
6
    case C_EXT:
5082
6
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
6
#ifdef C_SYSTEM
5094
7
    case C_SYSTEM:
5095
7
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
7
      if (syment->n_scnum == 0)
5100
6
  {
5101
6
    if (syment->n_value == 0)
5102
2
      return COFF_SYMBOL_UNDEFINED;
5103
4
    else
5104
4
      return COFF_SYMBOL_COMMON;
5105
6
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
7
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
7
}
coff-z8k.c:coff_classify_symbol
Line
Count
Source
5076
13
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
13
  switch (syment->n_sclass)
5080
13
    {
5081
12
    case C_EXT:
5082
13
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
13
#ifdef C_SYSTEM
5094
13
    case C_SYSTEM:
5095
13
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
13
      if (syment->n_scnum == 0)
5100
6
  {
5101
6
    if (syment->n_value == 0)
5102
3
      return COFF_SYMBOL_UNDEFINED;
5103
3
    else
5104
3
      return COFF_SYMBOL_COMMON;
5105
6
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
7
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
13
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
13
}
Unexecuted instantiation: pe-arm-wince.c:coff_classify_symbol
Unexecuted instantiation: pe-arm.c:coff_classify_symbol
pe-i386.c:coff_classify_symbol
Line
Count
Source
5076
4
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4
  switch (syment->n_sclass)
5080
4
    {
5081
2
    case C_EXT:
5082
3
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
3
#ifdef C_SYSTEM
5094
4
    case C_SYSTEM:
5095
4
#endif
5096
4
#ifdef COFF_WITH_PE
5097
4
    case C_NT_WEAK:
5098
4
#endif
5099
4
      if (syment->n_scnum == 0)
5100
3
  {
5101
3
    if (syment->n_value == 0)
5102
2
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
3
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
4
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pe-mcore.c:coff_classify_symbol
Line
Count
Source
5076
8
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
8
  switch (syment->n_sclass)
5080
8
    {
5081
0
    case C_EXT:
5082
8
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
8
#ifdef C_SYSTEM
5094
8
    case C_SYSTEM:
5095
8
#endif
5096
8
#ifdef COFF_WITH_PE
5097
8
    case C_NT_WEAK:
5098
8
#endif
5099
8
      if (syment->n_scnum == 0)
5100
0
  {
5101
0
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
0
    else
5104
0
      return COFF_SYMBOL_COMMON;
5105
0
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
8
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
8
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
pe-sh.c:coff_classify_symbol
Line
Count
Source
5076
2
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2
  switch (syment->n_sclass)
5080
2
    {
5081
1
    case C_EXT:
5082
1
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
1
#ifdef C_SYSTEM
5094
1
    case C_SYSTEM:
5095
1
#endif
5096
1
#ifdef COFF_WITH_PE
5097
2
    case C_NT_WEAK:
5098
2
#endif
5099
2
      if (syment->n_scnum == 0)
5100
1
  {
5101
1
    if (syment->n_value == 0)
5102
0
      return COFF_SYMBOL_UNDEFINED;
5103
1
    else
5104
1
      return COFF_SYMBOL_COMMON;
5105
1
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
2
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
Unexecuted instantiation: pei-arm-wince.c:coff_classify_symbol
Unexecuted instantiation: pei-arm.c:coff_classify_symbol
pei-mcore.c:coff_classify_symbol
Line
Count
Source
5076
6
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
6
  switch (syment->n_sclass)
5080
6
    {
5081
5
    case C_EXT:
5082
5
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
5
#ifdef C_SYSTEM
5094
5
    case C_SYSTEM:
5095
5
#endif
5096
5
#ifdef COFF_WITH_PE
5097
5
    case C_NT_WEAK:
5098
5
#endif
5099
5
      if (syment->n_scnum == 0)
5100
3
  {
5101
3
    if (syment->n_value == 0)
5102
3
      return COFF_SYMBOL_UNDEFINED;
5103
0
    else
5104
0
      return COFF_SYMBOL_COMMON;
5105
3
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2
      return COFF_SYMBOL_GLOBAL;
5111
5112
1
    default:
5113
1
      break;
5114
6
    }
5115
5116
1
#ifdef COFF_WITH_PE
5117
1
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
1
  if (syment->n_sclass == C_SECTION)
5147
1
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
1
      syment->n_value = 0;
5152
1
      if (syment->n_scnum == 0)
5153
1
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
1
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
1
}
pei-sh.c:coff_classify_symbol
Line
Count
Source
5076
18
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
18
  switch (syment->n_sclass)
5080
18
    {
5081
12
    case C_EXT:
5082
18
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
18
#ifdef C_SYSTEM
5094
18
    case C_SYSTEM:
5095
18
#endif
5096
18
#ifdef COFF_WITH_PE
5097
18
    case C_NT_WEAK:
5098
18
#endif
5099
18
      if (syment->n_scnum == 0)
5100
14
  {
5101
14
    if (syment->n_value == 0)
5102
2
      return COFF_SYMBOL_UNDEFINED;
5103
12
    else
5104
12
      return COFF_SYMBOL_COMMON;
5105
14
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
4
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
18
    }
5115
5116
0
#ifdef COFF_WITH_PE
5117
0
  if (syment->n_sclass == C_STAT)
5118
0
    {
5119
0
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
0
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
0
    }
5145
5146
0
  if (syment->n_sclass == C_SECTION)
5147
0
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
0
      syment->n_value = 0;
5152
0
      if (syment->n_scnum == 0)
5153
0
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
0
    }
5156
0
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
0
}
5171
5172
/*
5173
SUBSUBSECTION
5174
  Reading relocations
5175
5176
  Coff relocations are easily transformed into the internal BFD form
5177
  (@code{arelent}).
5178
5179
  Reading a coff relocation table is done in the following stages:
5180
5181
  o Read the entire coff relocation table into memory.
5182
5183
  o Process each relocation in turn; first swap it from the
5184
  external to the internal form.
5185
5186
  o Turn the symbol referenced in the relocation's symbol index
5187
  into a pointer into the canonical symbol table.
5188
  This table is the same as the one returned by a call to
5189
  @code{bfd_canonicalize_symtab}. The back end will call that
5190
  routine and save the result if a canonicalization hasn't been done.
5191
5192
  o The reloc index is turned into a pointer to a howto
5193
  structure, in a back end specific way. For instance, the 386
5194
  uses the @code{r_type} to directly produce an index
5195
  into a howto table vector.
5196
5197
  o Note that @code{arelent.addend} for COFF is often not what
5198
  most people understand as a relocation addend, but rather an
5199
  adjustment to the relocation addend stored in section contents
5200
  of relocatable object files.  The value found in section
5201
  contents may also be confusing, depending on both symbol value
5202
  and addend somewhat similar to the field value for a
5203
  final-linked object.  See @code{CALC_ADDEND}.
5204
*/
5205
5206
#ifdef COFF_WITH_PE
5207
14
#define COFF_PE_ADDEND_BIAS(ptr) 0 /* Symbol value not stored in raw data.  */
5208
#else
5209
3
#define COFF_PE_ADDEND_BIAS(ptr) ((ptr)->value)
5210
#endif
5211
5212
#ifndef CALC_ADDEND
5213
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)    \
5214
48
  {               \
5215
48
    coff_symbol_type *coffsym = NULL;       \
5216
48
                \
5217
48
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
5218
48
      coffsym = (obj_symbols (abfd)       \
5219
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
5220
48
    else if (ptr)           \
5221
48
      coffsym = coff_symbol_from (ptr);       \
5222
48
    if (coffsym != NULL            \
5223
48
  && coffsym->native->is_sym        \
5224
48
  && coffsym->native->u.syment.n_scnum == 0)   \
5225
48
      cache_ptr->addend = 0;         \
5226
48
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
5227
6
       && ptr->section != NULL)       \
5228
6
      cache_ptr->addend = - (ptr->section->vma      \
5229
0
           + COFF_PE_ADDEND_BIAS (ptr)); \
5230
6
    else              \
5231
6
      cache_ptr->addend = 0;         \
5232
48
  }
5233
#endif
5234
5235
static bool
5236
coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
5237
13.6k
{
5238
13.6k
  bfd_byte *native_relocs;
5239
13.6k
  arelent *reloc_cache;
5240
13.6k
  arelent *cache_ptr;
5241
13.6k
  unsigned int idx;
5242
13.6k
  size_t amt;
5243
5244
13.6k
  if (asect->relocation)
5245
138
    return true;
5246
13.4k
  if (asect->reloc_count == 0)
5247
180
    return true;
5248
13.2k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
13.2k
  if (!coff_slurp_symbol_table (abfd))
5251
2.44k
    return false;
5252
5253
10.8k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
10.8k
               asect->reloc_count,
5255
10.8k
               bfd_coff_relsz (abfd));
5256
10.8k
  if (native_relocs == NULL)
5257
6.87k
    return false;
5258
5259
3.97k
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
3.97k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
3.97k
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
5.87k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
5.76k
    {
5273
5.76k
      struct internal_reloc dst;
5274
5.76k
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
5.76k
      cache_ptr = reloc_cache + idx;
5280
5.76k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
5.76k
      dst.r_offset = 0;
5283
5.76k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
3.74k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
2.01k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
138
  {
5292
138
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
62
      {
5294
62
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
62
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
62
     abfd, dst.r_symndx);
5298
62
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
62
        ptr = NULL;
5300
62
      }
5301
76
    else
5302
76
      {
5303
76
        cache_ptr->sym_ptr_ptr = (symbols
5304
76
          + obj_convert (abfd)[dst.r_symndx]);
5305
76
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
76
      }
5307
138
  }
5308
1.87k
      else
5309
1.87k
  {
5310
1.87k
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
1.87k
    ptr = NULL;
5312
1.87k
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
2.01k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
2.01k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
5.76k
      if (cache_ptr->howto == NULL)
5333
3.85k
  {
5334
3.85k
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
3.85k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
3.85k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
3.85k
    bfd_set_error (bfd_error_bad_value);
5339
3.85k
    free (native_relocs);
5340
3.85k
    return false;
5341
3.85k
  }
5342
5.76k
    }
5343
5344
117
  free (native_relocs);
5345
117
  asect->relocation = reloc_cache;
5346
117
  return true;
5347
3.97k
}
pei-i386.c:coff_slurp_reloc_table
Line
Count
Source
5237
5
{
5238
5
  bfd_byte *native_relocs;
5239
5
  arelent *reloc_cache;
5240
5
  arelent *cache_ptr;
5241
5
  unsigned int idx;
5242
5
  size_t amt;
5243
5244
5
  if (asect->relocation)
5245
5
    return true;
5246
0
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pe-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
8
{
5238
8
  bfd_byte *native_relocs;
5239
8
  arelent *reloc_cache;
5240
8
  arelent *cache_ptr;
5241
8
  unsigned int idx;
5242
8
  size_t amt;
5243
5244
8
  if (asect->relocation)
5245
0
    return true;
5246
8
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
8
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
8
  if (!coff_slurp_symbol_table (abfd))
5251
6
    return false;
5252
5253
2
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
2
               asect->reloc_count,
5255
2
               bfd_coff_relsz (abfd));
5256
2
  if (native_relocs == NULL)
5257
1
    return false;
5258
5259
1
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
1
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
1
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
3
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
3
    {
5273
3
      struct internal_reloc dst;
5274
3
      void *src;
5275
3
#ifndef RELOC_PROCESSING
5276
3
      asymbol *ptr;
5277
3
#endif
5278
5279
3
      cache_ptr = reloc_cache + idx;
5280
3
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
3
      dst.r_offset = 0;
5283
3
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
3
      cache_ptr->address = dst.r_vaddr;
5289
5290
3
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
3
      else
5309
3
  {
5310
3
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
3
    ptr = NULL;
5312
3
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
3
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
3
      (void) ptr;
5324
5325
3
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
3
      RTYPE2HOWTO (cache_ptr, &dst);
5330
3
#endif  /* RELOC_PROCESSING */
5331
5332
3
      if (cache_ptr->howto == NULL)
5333
1
  {
5334
1
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
1
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
1
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
1
    bfd_set_error (bfd_error_bad_value);
5339
1
    free (native_relocs);
5340
1
    return false;
5341
1
  }
5342
3
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
1
}
pei-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
1
{
5238
1
  bfd_byte *native_relocs;
5239
1
  arelent *reloc_cache;
5240
1
  arelent *cache_ptr;
5241
1
  unsigned int idx;
5242
1
  size_t amt;
5243
5244
1
  if (asect->relocation)
5245
1
    return true;
5246
0
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
coff-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
459
{
5238
459
  bfd_byte *native_relocs;
5239
459
  arelent *reloc_cache;
5240
459
  arelent *cache_ptr;
5241
459
  unsigned int idx;
5242
459
  size_t amt;
5243
5244
459
  if (asect->relocation)
5245
0
    return true;
5246
459
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
459
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
459
  if (!coff_slurp_symbol_table (abfd))
5251
193
    return false;
5252
5253
266
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
266
               asect->reloc_count,
5255
266
               bfd_coff_relsz (abfd));
5256
266
  if (native_relocs == NULL)
5257
208
    return false;
5258
5259
58
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
58
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
58
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
197
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
183
    {
5273
183
      struct internal_reloc dst;
5274
183
      void *src;
5275
183
#ifndef RELOC_PROCESSING
5276
183
      asymbol *ptr;
5277
183
#endif
5278
5279
183
      cache_ptr = reloc_cache + idx;
5280
183
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
183
      dst.r_offset = 0;
5283
183
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
183
      cache_ptr->address = dst.r_vaddr;
5289
5290
183
      if (dst.r_symndx != -1 && symbols != NULL)
5291
6
  {
5292
6
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
3
      {
5294
3
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
3
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
3
     abfd, dst.r_symndx);
5298
3
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
3
        ptr = NULL;
5300
3
      }
5301
3
    else
5302
3
      {
5303
3
        cache_ptr->sym_ptr_ptr = (symbols
5304
3
          + obj_convert (abfd)[dst.r_symndx]);
5305
3
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
3
      }
5307
6
  }
5308
177
      else
5309
177
  {
5310
177
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
177
    ptr = NULL;
5312
177
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
183
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
183
      (void) ptr;
5324
5325
183
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
183
      RTYPE2HOWTO (cache_ptr, &dst);
5330
183
#endif  /* RELOC_PROCESSING */
5331
5332
183
      if (cache_ptr->howto == NULL)
5333
44
  {
5334
44
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
44
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
44
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
44
    bfd_set_error (bfd_error_bad_value);
5339
44
    free (native_relocs);
5340
44
    return false;
5341
44
  }
5342
183
    }
5343
5344
14
  free (native_relocs);
5345
14
  asect->relocation = reloc_cache;
5346
14
  return true;
5347
58
}
coff64-rs6000.c:coff_slurp_reloc_table
Line
Count
Source
5237
98
{
5238
98
  bfd_byte *native_relocs;
5239
98
  arelent *reloc_cache;
5240
98
  arelent *cache_ptr;
5241
98
  unsigned int idx;
5242
98
  size_t amt;
5243
5244
98
  if (asect->relocation)
5245
0
    return true;
5246
98
  if (asect->reloc_count == 0)
5247
1
    return true;
5248
97
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
97
  if (!coff_slurp_symbol_table (abfd))
5251
47
    return false;
5252
5253
50
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
50
               asect->reloc_count,
5255
50
               bfd_coff_relsz (abfd));
5256
50
  if (native_relocs == NULL)
5257
50
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pe-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
53
{
5238
53
  bfd_byte *native_relocs;
5239
53
  arelent *reloc_cache;
5240
53
  arelent *cache_ptr;
5241
53
  unsigned int idx;
5242
53
  size_t amt;
5243
5244
53
  if (asect->relocation)
5245
0
    return true;
5246
53
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
53
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
53
  if (!coff_slurp_symbol_table (abfd))
5251
34
    return false;
5252
5253
19
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
19
               asect->reloc_count,
5255
19
               bfd_coff_relsz (abfd));
5256
19
  if (native_relocs == NULL)
5257
11
    return false;
5258
5259
8
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
8
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
8
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
30
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
30
    {
5273
30
      struct internal_reloc dst;
5274
30
      void *src;
5275
30
#ifndef RELOC_PROCESSING
5276
30
      asymbol *ptr;
5277
30
#endif
5278
5279
30
      cache_ptr = reloc_cache + idx;
5280
30
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
30
      dst.r_offset = 0;
5283
30
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
30
      cache_ptr->address = dst.r_vaddr;
5289
5290
30
      if (dst.r_symndx != -1 && symbols != NULL)
5291
2
  {
5292
2
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
2
      {
5294
2
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
2
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
2
     abfd, dst.r_symndx);
5298
2
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
2
        ptr = NULL;
5300
2
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
2
  }
5308
28
      else
5309
28
  {
5310
28
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
28
    ptr = NULL;
5312
28
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
30
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
30
      (void) ptr;
5324
5325
30
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
30
      RTYPE2HOWTO (cache_ptr, &dst);
5330
30
#endif  /* RELOC_PROCESSING */
5331
5332
30
      if (cache_ptr->howto == NULL)
5333
8
  {
5334
8
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
8
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
8
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
8
    bfd_set_error (bfd_error_bad_value);
5339
8
    free (native_relocs);
5340
8
    return false;
5341
8
  }
5342
30
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
8
}
pei-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
1
{
5238
1
  bfd_byte *native_relocs;
5239
1
  arelent *reloc_cache;
5240
1
  arelent *cache_ptr;
5241
1
  unsigned int idx;
5242
1
  size_t amt;
5243
5244
1
  if (asect->relocation)
5245
1
    return true;
5246
0
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: pei-ia64.c:coff_slurp_reloc_table
pei-loongarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
11
{
5238
11
  bfd_byte *native_relocs;
5239
11
  arelent *reloc_cache;
5240
11
  arelent *cache_ptr;
5241
11
  unsigned int idx;
5242
11
  size_t amt;
5243
5244
11
  if (asect->relocation)
5245
11
    return true;
5246
0
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
Unexecuted instantiation: 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
5237
207
{
5238
207
  bfd_byte *native_relocs;
5239
207
  arelent *reloc_cache;
5240
207
  arelent *cache_ptr;
5241
207
  unsigned int idx;
5242
207
  size_t amt;
5243
5244
207
  if (asect->relocation)
5245
0
    return true;
5246
207
  if (asect->reloc_count == 0)
5247
127
    return true;
5248
80
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
80
  if (!coff_slurp_symbol_table (abfd))
5251
34
    return false;
5252
5253
46
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
46
               asect->reloc_count,
5255
46
               bfd_coff_relsz (abfd));
5256
46
  if (native_relocs == NULL)
5257
43
    return false;
5258
5259
3
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
3
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
3
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
8
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
5
    {
5273
5
      struct internal_reloc dst;
5274
5
      void *src;
5275
5
#ifndef RELOC_PROCESSING
5276
5
      asymbol *ptr;
5277
5
#endif
5278
5279
5
      cache_ptr = reloc_cache + idx;
5280
5
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
5
      dst.r_offset = 0;
5283
5
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
5
      cache_ptr->address = dst.r_vaddr;
5289
5290
5
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
5
      else
5309
5
  {
5310
5
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
5
    ptr = NULL;
5312
5
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
5
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
5
      (void) ptr;
5324
5325
5
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
5
      RTYPE2HOWTO (cache_ptr, &dst);
5330
5
#endif  /* RELOC_PROCESSING */
5331
5332
5
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
5
    }
5343
5344
3
  free (native_relocs);
5345
3
  asect->relocation = reloc_cache;
5346
3
  return true;
5347
3
}
coff-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
916
{
5238
916
  bfd_byte *native_relocs;
5239
916
  arelent *reloc_cache;
5240
916
  arelent *cache_ptr;
5241
916
  unsigned int idx;
5242
916
  size_t amt;
5243
5244
916
  if (asect->relocation)
5245
0
    return true;
5246
916
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
916
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
916
  if (!coff_slurp_symbol_table (abfd))
5251
309
    return false;
5252
5253
607
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
607
               asect->reloc_count,
5255
607
               bfd_coff_relsz (abfd));
5256
607
  if (native_relocs == NULL)
5257
435
    return false;
5258
5259
172
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
172
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
172
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
1.68k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
1.62k
    {
5273
1.62k
      struct internal_reloc dst;
5274
1.62k
      void *src;
5275
1.62k
#ifndef RELOC_PROCESSING
5276
1.62k
      asymbol *ptr;
5277
1.62k
#endif
5278
5279
1.62k
      cache_ptr = reloc_cache + idx;
5280
1.62k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
1.62k
      dst.r_offset = 0;
5283
1.62k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
1.62k
      cache_ptr->address = dst.r_vaddr;
5289
5290
1.62k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
2
  {
5292
2
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
2
      {
5294
2
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
2
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
2
     abfd, dst.r_symndx);
5298
2
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
2
        ptr = NULL;
5300
2
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
2
  }
5308
1.62k
      else
5309
1.62k
  {
5310
1.62k
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
1.62k
    ptr = NULL;
5312
1.62k
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
1.62k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
1.62k
      (void) ptr;
5324
5325
1.62k
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
1.62k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
1.62k
#endif  /* RELOC_PROCESSING */
5331
5332
1.62k
      if (cache_ptr->howto == NULL)
5333
105
  {
5334
105
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
105
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
105
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
105
    bfd_set_error (bfd_error_bad_value);
5339
105
    free (native_relocs);
5340
105
    return false;
5341
105
  }
5342
1.62k
    }
5343
5344
67
  free (native_relocs);
5345
67
  asect->relocation = reloc_cache;
5346
67
  return true;
5347
172
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_reloc_table
coff-tic30.c:coff_slurp_reloc_table
Line
Count
Source
5237
10.1k
{
5238
10.1k
  bfd_byte *native_relocs;
5239
10.1k
  arelent *reloc_cache;
5240
10.1k
  arelent *cache_ptr;
5241
10.1k
  unsigned int idx;
5242
10.1k
  size_t amt;
5243
5244
10.1k
  if (asect->relocation)
5245
0
    return true;
5246
10.1k
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
10.1k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
10.1k
  if (!coff_slurp_symbol_table (abfd))
5251
788
    return false;
5252
5253
9.40k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
9.40k
               asect->reloc_count,
5255
9.40k
               bfd_coff_relsz (abfd));
5256
9.40k
  if (native_relocs == NULL)
5257
5.82k
    return false;
5258
5259
3.58k
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
3.58k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
3.58k
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
3.61k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
3.61k
    {
5273
3.61k
      struct internal_reloc dst;
5274
3.61k
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
3.61k
      cache_ptr = reloc_cache + idx;
5280
3.61k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
3.61k
      dst.r_offset = 0;
5283
3.61k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
3.61k
#ifdef RELOC_PROCESSING
5286
3.61k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
      if (dst.r_symndx != -1 && symbols != NULL)
5291
  {
5292
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
      {
5294
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
     abfd, dst.r_symndx);
5298
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
        ptr = NULL;
5300
      }
5301
    else
5302
      {
5303
        cache_ptr->sym_ptr_ptr = (symbols
5304
          + obj_convert (abfd)[dst.r_symndx]);
5305
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
      }
5307
  }
5308
      else
5309
  {
5310
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
    ptr = NULL;
5312
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
3.61k
      if (cache_ptr->howto == NULL)
5333
3.58k
  {
5334
3.58k
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
3.58k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
3.58k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
3.58k
    bfd_set_error (bfd_error_bad_value);
5339
3.58k
    free (native_relocs);
5340
3.58k
    return false;
5341
3.58k
  }
5342
3.61k
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
3.58k
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_reloc_table
coff-tic54x.c:coff_slurp_reloc_table
Line
Count
Source
5237
988
{
5238
988
  bfd_byte *native_relocs;
5239
988
  arelent *reloc_cache;
5240
988
  arelent *cache_ptr;
5241
988
  unsigned int idx;
5242
988
  size_t amt;
5243
5244
988
  if (asect->relocation)
5245
0
    return true;
5246
988
  if (asect->reloc_count == 0)
5247
52
    return true;
5248
936
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
936
  if (!coff_slurp_symbol_table (abfd))
5251
738
    return false;
5252
5253
198
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
198
               asect->reloc_count,
5255
198
               bfd_coff_relsz (abfd));
5256
198
  if (native_relocs == NULL)
5257
155
    return false;
5258
5259
43
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
43
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
43
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
43
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
43
    {
5273
43
      struct internal_reloc dst;
5274
43
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
43
      cache_ptr = reloc_cache + idx;
5280
43
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
43
      dst.r_offset = 0;
5283
43
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
43
#ifdef RELOC_PROCESSING
5286
43
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
      if (dst.r_symndx != -1 && symbols != NULL)
5291
  {
5292
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
      {
5294
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
     abfd, dst.r_symndx);
5298
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
        ptr = NULL;
5300
      }
5301
    else
5302
      {
5303
        cache_ptr->sym_ptr_ptr = (symbols
5304
          + obj_convert (abfd)[dst.r_symndx]);
5305
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
      }
5307
  }
5308
      else
5309
  {
5310
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
    ptr = NULL;
5312
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
43
      if (cache_ptr->howto == NULL)
5333
43
  {
5334
43
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
43
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
43
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
43
    bfd_set_error (bfd_error_bad_value);
5339
43
    free (native_relocs);
5340
43
    return false;
5341
43
  }
5342
43
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
43
}
coff-z80.c:coff_slurp_reloc_table
Line
Count
Source
5237
212
{
5238
212
  bfd_byte *native_relocs;
5239
212
  arelent *reloc_cache;
5240
212
  arelent *cache_ptr;
5241
212
  unsigned int idx;
5242
212
  size_t amt;
5243
5244
212
  if (asect->relocation)
5245
0
    return true;
5246
212
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
212
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
212
  if (!coff_slurp_symbol_table (abfd))
5251
139
    return false;
5252
5253
73
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
73
               asect->reloc_count,
5255
73
               bfd_coff_relsz (abfd));
5256
73
  if (native_relocs == NULL)
5257
34
    return false;
5258
5259
39
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
39
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
39
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
74
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
46
    {
5273
46
      struct internal_reloc dst;
5274
46
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
46
      cache_ptr = reloc_cache + idx;
5280
46
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
46
      dst.r_offset = 0;
5283
46
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
46
#ifdef RELOC_PROCESSING
5286
46
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
      if (dst.r_symndx != -1 && symbols != NULL)
5291
  {
5292
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
      {
5294
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
     abfd, dst.r_symndx);
5298
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
        ptr = NULL;
5300
      }
5301
    else
5302
      {
5303
        cache_ptr->sym_ptr_ptr = (symbols
5304
          + obj_convert (abfd)[dst.r_symndx]);
5305
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
      }
5307
  }
5308
      else
5309
  {
5310
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
    ptr = NULL;
5312
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
46
      if (cache_ptr->howto == NULL)
5333
11
  {
5334
11
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
11
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
11
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
11
    bfd_set_error (bfd_error_bad_value);
5339
11
    free (native_relocs);
5340
11
    return false;
5341
11
  }
5342
46
    }
5343
5344
28
  free (native_relocs);
5345
28
  asect->relocation = reloc_cache;
5346
28
  return true;
5347
39
}
coff-z8k.c:coff_slurp_reloc_table
Line
Count
Source
5237
285
{
5238
285
  bfd_byte *native_relocs;
5239
285
  arelent *reloc_cache;
5240
285
  arelent *cache_ptr;
5241
285
  unsigned int idx;
5242
285
  size_t amt;
5243
5244
285
  if (asect->relocation)
5245
0
    return true;
5246
285
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
285
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
285
  if (!coff_slurp_symbol_table (abfd))
5251
144
    return false;
5252
5253
141
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
141
               asect->reloc_count,
5255
141
               bfd_coff_relsz (abfd));
5256
141
  if (native_relocs == NULL)
5257
104
    return false;
5258
5259
37
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
37
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
37
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
43
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
41
    {
5273
41
      struct internal_reloc dst;
5274
41
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
41
      cache_ptr = reloc_cache + idx;
5280
41
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
41
      dst.r_offset = 0;
5283
41
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
41
#ifdef RELOC_PROCESSING
5286
41
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
      if (dst.r_symndx != -1 && symbols != NULL)
5291
  {
5292
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
      {
5294
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
     abfd, dst.r_symndx);
5298
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
        ptr = NULL;
5300
      }
5301
    else
5302
      {
5303
        cache_ptr->sym_ptr_ptr = (symbols
5304
          + obj_convert (abfd)[dst.r_symndx]);
5305
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
      }
5307
  }
5308
      else
5309
  {
5310
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
    ptr = NULL;
5312
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
      (void) ptr;
5324
5325
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
41
      if (cache_ptr->howto == NULL)
5333
35
  {
5334
35
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
35
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
35
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
35
    bfd_set_error (bfd_error_bad_value);
5339
35
    free (native_relocs);
5340
35
    return false;
5341
35
  }
5342
41
    }
5343
5344
2
  free (native_relocs);
5345
2
  asect->relocation = reloc_cache;
5346
2
  return true;
5347
37
}
Unexecuted instantiation: pe-arm-wince.c:coff_slurp_reloc_table
Unexecuted instantiation: pe-arm.c:coff_slurp_reloc_table
pe-i386.c:coff_slurp_reloc_table
Line
Count
Source
5237
27
{
5238
27
  bfd_byte *native_relocs;
5239
27
  arelent *reloc_cache;
5240
27
  arelent *cache_ptr;
5241
27
  unsigned int idx;
5242
27
  size_t amt;
5243
5244
27
  if (asect->relocation)
5245
0
    return true;
5246
27
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
27
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
27
  if (!coff_slurp_symbol_table (abfd))
5251
4
    return false;
5252
5253
23
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
23
               asect->reloc_count,
5255
23
               bfd_coff_relsz (abfd));
5256
23
  if (native_relocs == NULL)
5257
4
    return false;
5258
5259
19
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
19
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
19
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
155
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
154
    {
5273
154
      struct internal_reloc dst;
5274
154
      void *src;
5275
154
#ifndef RELOC_PROCESSING
5276
154
      asymbol *ptr;
5277
154
#endif
5278
5279
154
      cache_ptr = reloc_cache + idx;
5280
154
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
154
      dst.r_offset = 0;
5283
154
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
154
      cache_ptr->address = dst.r_vaddr;
5289
5290
154
      if (dst.r_symndx != -1 && symbols != NULL)
5291
118
  {
5292
118
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
52
      {
5294
52
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
52
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
52
     abfd, dst.r_symndx);
5298
52
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
52
        ptr = NULL;
5300
52
      }
5301
66
    else
5302
66
      {
5303
66
        cache_ptr->sym_ptr_ptr = (symbols
5304
66
          + obj_convert (abfd)[dst.r_symndx]);
5305
66
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
66
      }
5307
118
  }
5308
36
      else
5309
36
  {
5310
36
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
36
    ptr = NULL;
5312
36
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
154
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
154
      (void) ptr;
5324
5325
154
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
154
      RTYPE2HOWTO (cache_ptr, &dst);
5330
154
#endif  /* RELOC_PROCESSING */
5331
5332
154
      if (cache_ptr->howto == NULL)
5333
18
  {
5334
18
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
18
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
18
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
18
    bfd_set_error (bfd_error_bad_value);
5339
18
    free (native_relocs);
5340
18
    return false;
5341
18
  }
5342
154
    }
5343
5344
1
  free (native_relocs);
5345
1
  asect->relocation = reloc_cache;
5346
1
  return true;
5347
19
}
pe-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5237
6
{
5238
6
  bfd_byte *native_relocs;
5239
6
  arelent *reloc_cache;
5240
6
  arelent *cache_ptr;
5241
6
  unsigned int idx;
5242
6
  size_t amt;
5243
5244
6
  if (asect->relocation)
5245
0
    return true;
5246
6
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
6
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
6
  if (!coff_slurp_symbol_table (abfd))
5251
4
    return false;
5252
5253
2
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
2
               asect->reloc_count,
5255
2
               bfd_coff_relsz (abfd));
5256
2
  if (native_relocs == NULL)
5257
2
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pe-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
11
{
5238
11
  bfd_byte *native_relocs;
5239
11
  arelent *reloc_cache;
5240
11
  arelent *cache_ptr;
5241
11
  unsigned int idx;
5242
11
  size_t amt;
5243
5244
11
  if (asect->relocation)
5245
0
    return true;
5246
11
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
11
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
11
  if (!coff_slurp_symbol_table (abfd))
5251
4
    return false;
5252
5253
7
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
7
               asect->reloc_count,
5255
7
               bfd_coff_relsz (abfd));
5256
7
  if (native_relocs == NULL)
5257
2
    return false;
5258
5259
5
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
5
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
5
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
21
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
19
    {
5273
19
      struct internal_reloc dst;
5274
19
      void *src;
5275
19
#ifndef RELOC_PROCESSING
5276
19
      asymbol *ptr;
5277
19
#endif
5278
5279
19
      cache_ptr = reloc_cache + idx;
5280
19
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
19
      dst.r_offset = 0;
5283
19
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
19
      cache_ptr->address = dst.r_vaddr;
5289
5290
19
      if (dst.r_symndx != -1 && symbols != NULL)
5291
10
  {
5292
10
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
3
      {
5294
3
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
3
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
3
     abfd, dst.r_symndx);
5298
3
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
3
        ptr = NULL;
5300
3
      }
5301
7
    else
5302
7
      {
5303
7
        cache_ptr->sym_ptr_ptr = (symbols
5304
7
          + obj_convert (abfd)[dst.r_symndx]);
5305
7
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
7
      }
5307
10
  }
5308
9
      else
5309
9
  {
5310
9
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
9
    ptr = NULL;
5312
9
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
19
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
19
      (void) ptr;
5324
5325
19
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
19
      RTYPE2HOWTO (cache_ptr, &dst);
5330
19
#endif  /* RELOC_PROCESSING */
5331
5332
19
      if (cache_ptr->howto == NULL)
5333
3
  {
5334
3
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
3
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
3
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
3
    bfd_set_error (bfd_error_bad_value);
5339
3
    free (native_relocs);
5340
3
    return false;
5341
3
  }
5342
19
    }
5343
5344
2
  free (native_relocs);
5345
2
  asect->relocation = reloc_cache;
5346
2
  return true;
5347
5
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-arm.c:coff_slurp_reloc_table
Unexecuted instantiation: pei-mcore.c:coff_slurp_reloc_table
pei-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
120
{
5238
120
  bfd_byte *native_relocs;
5239
120
  arelent *reloc_cache;
5240
120
  arelent *cache_ptr;
5241
120
  unsigned int idx;
5242
120
  size_t amt;
5243
5244
120
  if (asect->relocation)
5245
120
    return true;
5246
0
  if (asect->reloc_count == 0)
5247
0
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
5348
5349
#ifndef coff_rtype_to_howto
5350
#ifdef RTYPE2HOWTO
5351
5352
/* Get the howto structure for a reloc.  This is only used if the file
5353
   including this one defines coff_relocate_section to be
5354
   _bfd_coff_generic_relocate_section, so it is OK if it does not
5355
   always work.  It is the responsibility of the including file to
5356
   make sure it is reasonable if it is needed.  */
5357
5358
static reloc_howto_type *
5359
coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
5360
         asection *sec ATTRIBUTE_UNUSED,
5361
         struct internal_reloc *rel ATTRIBUTE_UNUSED,
5362
         struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
5363
         struct internal_syment *sym ATTRIBUTE_UNUSED,
5364
         bfd_vma *addendp ATTRIBUTE_UNUSED)
5365
0
{
5366
0
  arelent genrel;
5367
5368
0
  genrel.howto = NULL;
5369
0
  RTYPE2HOWTO (&genrel, rel);
5370
0
  return genrel.howto;
5371
0
}
Unexecuted instantiation: coff64-rs6000.c:coff_rtype_to_howto
Unexecuted instantiation: pei-ia64.c:coff_rtype_to_howto
Unexecuted instantiation: pei-loongarch64.c:coff_rtype_to_howto
Unexecuted instantiation: coff-rs6000.c:coff_rtype_to_howto
Unexecuted instantiation: coff-sh.c:coff_rtype_to_howto
Unexecuted instantiation: coff-tic30.c:coff_rtype_to_howto
Unexecuted instantiation: coff-z80.c:coff_rtype_to_howto
Unexecuted instantiation: coff-z8k.c:coff_rtype_to_howto
5372
5373
#else /* ! defined (RTYPE2HOWTO) */
5374
5375
#define coff_rtype_to_howto NULL
5376
5377
#endif /* ! defined (RTYPE2HOWTO) */
5378
#endif /* ! defined (coff_rtype_to_howto) */
5379
5380
/* This is stupid.  This function should be a boolean predicate.  */
5381
5382
static long
5383
coff_canonicalize_reloc (bfd * abfd,
5384
       sec_ptr section,
5385
       arelent ** relptr,
5386
       asymbol ** symbols)
5387
13.6k
{
5388
13.6k
  arelent *tblptr = section->relocation;
5389
13.6k
  unsigned int count = 0;
5390
5391
13.6k
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
13.6k
  else
5405
13.6k
    {
5406
13.6k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
13.1k
  return -1;
5408
5409
435
      tblptr = section->relocation;
5410
5411
962
      for (; count++ < section->reloc_count;)
5412
527
  *relptr++ = tblptr++;
5413
435
    }
5414
435
  *relptr = 0;
5415
435
  return section->reloc_count;
5416
13.6k
}
pei-i386.c:coff_canonicalize_reloc
Line
Count
Source
5387
5
{
5388
5
  arelent *tblptr = section->relocation;
5389
5
  unsigned int count = 0;
5390
5391
5
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
5
  else
5405
5
    {
5406
5
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
5
      tblptr = section->relocation;
5410
5411
10
      for (; count++ < section->reloc_count;)
5412
5
  *relptr++ = tblptr++;
5413
5
    }
5414
5
  *relptr = 0;
5415
5
  return section->reloc_count;
5416
5
}
pe-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
8
{
5388
8
  arelent *tblptr = section->relocation;
5389
8
  unsigned int count = 0;
5390
5391
8
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
8
  else
5405
8
    {
5406
8
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
8
  return -1;
5408
5409
0
      tblptr = section->relocation;
5410
5411
0
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
0
    }
5414
0
  *relptr = 0;
5415
0
  return section->reloc_count;
5416
8
}
pei-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
1
{
5388
1
  arelent *tblptr = section->relocation;
5389
1
  unsigned int count = 0;
5390
5391
1
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
1
  else
5405
1
    {
5406
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
2
      for (; count++ < section->reloc_count;)
5412
1
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
1
}
coff-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
459
{
5388
459
  arelent *tblptr = section->relocation;
5389
459
  unsigned int count = 0;
5390
5391
459
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
459
  else
5405
459
    {
5406
459
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
445
  return -1;
5408
5409
14
      tblptr = section->relocation;
5410
5411
87
      for (; count++ < section->reloc_count;)
5412
73
  *relptr++ = tblptr++;
5413
14
    }
5414
14
  *relptr = 0;
5415
14
  return section->reloc_count;
5416
459
}
coff64-rs6000.c:coff_canonicalize_reloc
Line
Count
Source
5387
98
{
5388
98
  arelent *tblptr = section->relocation;
5389
98
  unsigned int count = 0;
5390
5391
98
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
98
  else
5405
98
    {
5406
98
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
97
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
1
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
98
}
pe-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
53
{
5388
53
  arelent *tblptr = section->relocation;
5389
53
  unsigned int count = 0;
5390
5391
53
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
53
  else
5405
53
    {
5406
53
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
53
  return -1;
5408
5409
0
      tblptr = section->relocation;
5410
5411
0
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
0
    }
5414
0
  *relptr = 0;
5415
0
  return section->reloc_count;
5416
53
}
pei-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
1
{
5388
1
  arelent *tblptr = section->relocation;
5389
1
  unsigned int count = 0;
5390
5391
1
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
1
  else
5405
1
    {
5406
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
2
      for (; count++ < section->reloc_count;)
5412
1
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
1
}
Unexecuted instantiation: pei-ia64.c:coff_canonicalize_reloc
pei-loongarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
11
{
5388
11
  arelent *tblptr = section->relocation;
5389
11
  unsigned int count = 0;
5390
5391
11
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
11
  else
5405
11
    {
5406
11
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
11
      tblptr = section->relocation;
5410
5411
22
      for (; count++ < section->reloc_count;)
5412
11
  *relptr++ = tblptr++;
5413
11
    }
5414
11
  *relptr = 0;
5415
11
  return section->reloc_count;
5416
11
}
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
5387
207
{
5388
207
  arelent *tblptr = section->relocation;
5389
207
  unsigned int count = 0;
5390
5391
207
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
207
  else
5405
207
    {
5406
207
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
77
  return -1;
5408
5409
130
      tblptr = section->relocation;
5410
5411
135
      for (; count++ < section->reloc_count;)
5412
5
  *relptr++ = tblptr++;
5413
130
    }
5414
130
  *relptr = 0;
5415
130
  return section->reloc_count;
5416
207
}
coff-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
916
{
5388
916
  arelent *tblptr = section->relocation;
5389
916
  unsigned int count = 0;
5390
5391
916
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
916
  else
5405
916
    {
5406
916
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
849
  return -1;
5408
5409
67
      tblptr = section->relocation;
5410
5411
320
      for (; count++ < section->reloc_count;)
5412
253
  *relptr++ = tblptr++;
5413
67
    }
5414
67
  *relptr = 0;
5415
67
  return section->reloc_count;
5416
916
}
Unexecuted instantiation: coff-stgo32.c:coff_canonicalize_reloc
coff-tic30.c:coff_canonicalize_reloc
Line
Count
Source
5387
10.1k
{
5388
10.1k
  arelent *tblptr = section->relocation;
5389
10.1k
  unsigned int count = 0;
5390
5391
10.1k
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
10.1k
  else
5405
10.1k
    {
5406
10.1k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
10.1k
  return -1;
5408
5409
0
      tblptr = section->relocation;
5410
5411
0
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
0
    }
5414
0
  *relptr = 0;
5415
0
  return section->reloc_count;
5416
10.1k
}
Unexecuted instantiation: coff-tic4x.c:coff_canonicalize_reloc
coff-tic54x.c:coff_canonicalize_reloc
Line
Count
Source
5387
988
{
5388
988
  arelent *tblptr = section->relocation;
5389
988
  unsigned int count = 0;
5390
5391
988
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
988
  else
5405
988
    {
5406
988
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
936
  return -1;
5408
5409
52
      tblptr = section->relocation;
5410
5411
52
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
52
    }
5414
52
  *relptr = 0;
5415
52
  return section->reloc_count;
5416
988
}
coff-z80.c:coff_canonicalize_reloc
Line
Count
Source
5387
212
{
5388
212
  arelent *tblptr = section->relocation;
5389
212
  unsigned int count = 0;
5390
5391
212
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
212
  else
5405
212
    {
5406
212
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
184
  return -1;
5408
5409
28
      tblptr = section->relocation;
5410
5411
58
      for (; count++ < section->reloc_count;)
5412
30
  *relptr++ = tblptr++;
5413
28
    }
5414
28
  *relptr = 0;
5415
28
  return section->reloc_count;
5416
212
}
coff-z8k.c:coff_canonicalize_reloc
Line
Count
Source
5387
285
{
5388
285
  arelent *tblptr = section->relocation;
5389
285
  unsigned int count = 0;
5390
5391
285
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
285
  else
5405
285
    {
5406
285
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
283
  return -1;
5408
5409
2
      tblptr = section->relocation;
5410
5411
4
      for (; count++ < section->reloc_count;)
5412
2
  *relptr++ = tblptr++;
5413
2
    }
5414
2
  *relptr = 0;
5415
2
  return section->reloc_count;
5416
285
}
Unexecuted instantiation: pe-arm-wince.c:coff_canonicalize_reloc
Unexecuted instantiation: pe-arm.c:coff_canonicalize_reloc
pe-i386.c:coff_canonicalize_reloc
Line
Count
Source
5387
27
{
5388
27
  arelent *tblptr = section->relocation;
5389
27
  unsigned int count = 0;
5390
5391
27
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
27
  else
5405
27
    {
5406
27
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
26
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
17
      for (; count++ < section->reloc_count;)
5412
16
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
27
}
pe-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5387
6
{
5388
6
  arelent *tblptr = section->relocation;
5389
6
  unsigned int count = 0;
5390
5391
6
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
6
  else
5405
6
    {
5406
6
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
6
  return -1;
5408
5409
0
      tblptr = section->relocation;
5410
5411
0
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
0
    }
5414
0
  *relptr = 0;
5415
0
  return section->reloc_count;
5416
6
}
pe-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
11
{
5388
11
  arelent *tblptr = section->relocation;
5389
11
  unsigned int count = 0;
5390
5391
11
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
11
  else
5405
11
    {
5406
11
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
9
  return -1;
5408
5409
2
      tblptr = section->relocation;
5410
5411
12
      for (; count++ < section->reloc_count;)
5412
10
  *relptr++ = tblptr++;
5413
2
    }
5414
2
  *relptr = 0;
5415
2
  return section->reloc_count;
5416
11
}
Unexecuted instantiation: pei-arm-wince.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-arm.c:coff_canonicalize_reloc
Unexecuted instantiation: pei-mcore.c:coff_canonicalize_reloc
pei-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
120
{
5388
120
  arelent *tblptr = section->relocation;
5389
120
  unsigned int count = 0;
5390
5391
120
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
120
  else
5405
120
    {
5406
120
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
120
      tblptr = section->relocation;
5410
5411
240
      for (; count++ < section->reloc_count;)
5412
120
  *relptr++ = tblptr++;
5413
120
    }
5414
120
  *relptr = 0;
5415
120
  return section->reloc_count;
5416
120
}
5417
5418
#ifndef coff_set_reloc
5419
#define coff_set_reloc _bfd_generic_set_reloc
5420
#endif
5421
5422
#ifndef coff_reloc16_estimate
5423
#define coff_reloc16_estimate dummy_reloc16_estimate
5424
5425
static int
5426
dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
5427
      asection *input_section ATTRIBUTE_UNUSED,
5428
      arelent *reloc ATTRIBUTE_UNUSED,
5429
      unsigned int shrink ATTRIBUTE_UNUSED,
5430
      struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
5431
0
{
5432
0
  abort ();
5433
0
  return 0;
5434
0
}
Unexecuted instantiation: pei-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-x86_64.c:dummy_reloc16_estimate
Unexecuted instantiation: coff64-rs6000.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-aarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-aarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-ia64.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-loongarch64.c:dummy_reloc16_estimate
Unexecuted instantiation: cf-i386lynx.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-go32.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-rs6000.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-sh.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-stgo32.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic30.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic4x.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-tic54x.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-z80.c:dummy_reloc16_estimate
Unexecuted instantiation: coff-z8k.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-arm-wince.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-arm.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-i386.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-mcore.c:dummy_reloc16_estimate
Unexecuted instantiation: pe-sh.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-arm-wince.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-arm.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-mcore.c:dummy_reloc16_estimate
Unexecuted instantiation: pei-sh.c:dummy_reloc16_estimate
5435
5436
#endif
5437
5438
#ifndef coff_reloc16_extra_cases
5439
5440
#define coff_reloc16_extra_cases dummy_reloc16_extra_cases
5441
5442
static bool
5443
dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
5444
         struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
5445
         struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
5446
         arelent *reloc ATTRIBUTE_UNUSED,
5447
         bfd_byte *data ATTRIBUTE_UNUSED,
5448
         size_t *src_ptr ATTRIBUTE_UNUSED,
5449
         size_t *dst_ptr ATTRIBUTE_UNUSED)
5450
0
{
5451
0
  return false;
5452
0
}
Unexecuted instantiation: pei-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-x86_64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff64-rs6000.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-aarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-aarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-ia64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-loongarch64.c:dummy_reloc16_extra_cases
Unexecuted instantiation: cf-i386lynx.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-go32.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-rs6000.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-sh.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-stgo32.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic30.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic4x.c:dummy_reloc16_extra_cases
Unexecuted instantiation: coff-tic54x.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-arm-wince.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-arm.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-i386.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-mcore.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pe-sh.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-arm-wince.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-arm.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-mcore.c:dummy_reloc16_extra_cases
Unexecuted instantiation: pei-sh.c:dummy_reloc16_extra_cases
5453
#endif
5454
5455
/* If coff_relocate_section is defined, we can use the optimized COFF
5456
   backend linker.  Otherwise we must continue to use the old linker.  */
5457
5458
#ifdef coff_relocate_section
5459
5460
#ifndef coff_bfd_link_hash_table_create
5461
#define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
5462
#endif
5463
#ifndef coff_bfd_link_add_symbols
5464
#define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
5465
#endif
5466
#ifndef coff_bfd_final_link
5467
#define coff_bfd_final_link _bfd_coff_final_link
5468
#endif
5469
5470
#else /* ! defined (coff_relocate_section) */
5471
5472
#define coff_relocate_section NULL
5473
#ifndef coff_bfd_link_hash_table_create
5474
#define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
5475
#endif
5476
#ifndef coff_bfd_link_add_symbols
5477
#define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
5478
#endif
5479
#define coff_bfd_final_link _bfd_generic_final_link
5480
5481
#endif /* ! defined (coff_relocate_section) */
5482
5483
#define coff_bfd_link_just_syms      _bfd_generic_link_just_syms
5484
#define coff_bfd_copy_link_hash_symbol_type \
5485
  _bfd_generic_copy_link_hash_symbol_type
5486
#define coff_bfd_link_split_section  _bfd_generic_link_split_section
5487
5488
#define coff_bfd_link_check_relocs   _bfd_generic_link_check_relocs
5489
5490
#ifndef coff_start_final_link
5491
#define coff_start_final_link NULL
5492
#endif
5493
5494
#ifndef coff_adjust_symndx
5495
#define coff_adjust_symndx NULL
5496
#endif
5497
5498
#ifndef coff_link_add_one_symbol
5499
#define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
5500
#endif
5501
5502
#ifndef coff_link_output_has_begun
5503
5504
static bool
5505
coff_link_output_has_begun (bfd * abfd,
5506
          struct coff_final_link_info * info ATTRIBUTE_UNUSED)
5507
0
{
5508
0
  return abfd->output_has_begun;
5509
0
}
Unexecuted instantiation: pei-i386.c:coff_link_output_has_begun
Unexecuted instantiation: pe-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: coff-x86_64.c:coff_link_output_has_begun
Unexecuted instantiation: coff64-rs6000.c:coff_link_output_has_begun
Unexecuted instantiation: pe-aarch64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-aarch64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-ia64.c:coff_link_output_has_begun
Unexecuted instantiation: pei-loongarch64.c:coff_link_output_has_begun
Unexecuted instantiation: cf-i386lynx.c:coff_link_output_has_begun
Unexecuted instantiation: coff-go32.c:coff_link_output_has_begun
Unexecuted instantiation: coff-i386.c:coff_link_output_has_begun
Unexecuted instantiation: coff-rs6000.c:coff_link_output_has_begun
Unexecuted instantiation: coff-sh.c:coff_link_output_has_begun
Unexecuted instantiation: coff-stgo32.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic30.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic4x.c:coff_link_output_has_begun
Unexecuted instantiation: coff-tic54x.c:coff_link_output_has_begun
Unexecuted instantiation: coff-z80.c:coff_link_output_has_begun
Unexecuted instantiation: coff-z8k.c:coff_link_output_has_begun
Unexecuted instantiation: pe-i386.c:coff_link_output_has_begun
Unexecuted instantiation: pe-mcore.c:coff_link_output_has_begun
Unexecuted instantiation: pe-sh.c:coff_link_output_has_begun
Unexecuted instantiation: pei-mcore.c:coff_link_output_has_begun
Unexecuted instantiation: pei-sh.c:coff_link_output_has_begun
5510
#endif
5511
5512
#ifndef coff_final_link_postscript
5513
5514
static bool
5515
coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
5516
          struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
5517
0
{
5518
0
  return true;
5519
0
}
Unexecuted instantiation: coff-x86_64.c:coff_final_link_postscript
Unexecuted instantiation: coff64-rs6000.c:coff_final_link_postscript
Unexecuted instantiation: cf-i386lynx.c:coff_final_link_postscript
Unexecuted instantiation: coff-go32.c:coff_final_link_postscript
Unexecuted instantiation: coff-i386.c:coff_final_link_postscript
Unexecuted instantiation: coff-rs6000.c:coff_final_link_postscript
Unexecuted instantiation: coff-sh.c:coff_final_link_postscript
Unexecuted instantiation: coff-stgo32.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic30.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic4x.c:coff_final_link_postscript
Unexecuted instantiation: coff-tic54x.c:coff_final_link_postscript
Unexecuted instantiation: coff-z80.c:coff_final_link_postscript
Unexecuted instantiation: coff-z8k.c:coff_final_link_postscript
5520
#endif
5521
5522
#ifndef coff_SWAP_aux_in
5523
#define coff_SWAP_aux_in coff_swap_aux_in
5524
#endif
5525
#ifndef coff_SWAP_sym_in
5526
#define coff_SWAP_sym_in coff_swap_sym_in
5527
#endif
5528
#ifndef coff_SWAP_lineno_in
5529
#define coff_SWAP_lineno_in coff_swap_lineno_in
5530
#endif
5531
#ifndef coff_SWAP_aux_out
5532
#define coff_SWAP_aux_out coff_swap_aux_out
5533
#endif
5534
#ifndef coff_SWAP_sym_out
5535
#define coff_SWAP_sym_out coff_swap_sym_out
5536
#endif
5537
#ifndef coff_SWAP_lineno_out
5538
#define coff_SWAP_lineno_out coff_swap_lineno_out
5539
#endif
5540
#ifndef coff_SWAP_reloc_out
5541
#define coff_SWAP_reloc_out coff_swap_reloc_out
5542
#endif
5543
#ifndef coff_SWAP_filehdr_out
5544
#define coff_SWAP_filehdr_out coff_swap_filehdr_out
5545
#endif
5546
#ifndef coff_SWAP_aouthdr_out
5547
#define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
5548
#endif
5549
#ifndef coff_SWAP_scnhdr_out
5550
#define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
5551
#endif
5552
#ifndef coff_SWAP_reloc_in
5553
#define coff_SWAP_reloc_in coff_swap_reloc_in
5554
#endif
5555
#ifndef coff_SWAP_filehdr_in
5556
#define coff_SWAP_filehdr_in coff_swap_filehdr_in
5557
#endif
5558
#ifndef coff_SWAP_aouthdr_in
5559
#define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
5560
#endif
5561
#ifndef coff_SWAP_scnhdr_in
5562
#define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
5563
#endif
5564
5565
#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
5566
5567
static const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
5568
{
5569
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5570
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5571
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5572
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5573
  coff_SWAP_scnhdr_out,
5574
  FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5575
#ifdef COFF_LONG_FILENAMES
5576
  true,
5577
#else
5578
  false,
5579
#endif
5580
  COFF_DEFAULT_LONG_SECTION_NAMES,
5581
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5582
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5583
  true,
5584
#else
5585
  false,
5586
#endif
5587
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5588
  4,
5589
#else
5590
  2,
5591
#endif
5592
  32768,
5593
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5594
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5595
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5596
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5597
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5598
  coff_classify_symbol, coff_compute_section_file_positions,
5599
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5600
  coff_adjust_symndx, coff_link_add_one_symbol,
5601
  coff_link_output_has_begun, coff_final_link_postscript,
5602
  bfd_pe_print_pdata
5603
};
5604
5605
#ifdef TICOFF
5606
/* COFF0 differs in file/section header size and relocation entry size.  */
5607
5608
static const bfd_coff_backend_data ticoff0_swap_table =
5609
{
5610
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5611
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5612
  coff_SWAP_lineno_out, coff_swap_reloc_v0_out,
5613
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5614
  coff_SWAP_scnhdr_out,
5615
  FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
5616
#ifdef COFF_LONG_FILENAMES
5617
  true,
5618
#else
5619
  false,
5620
#endif
5621
  COFF_DEFAULT_LONG_SECTION_NAMES,
5622
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5623
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5624
  true,
5625
#else
5626
  false,
5627
#endif
5628
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5629
  4,
5630
#else
5631
  2,
5632
#endif
5633
  32768,
5634
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5635
  coff_swap_reloc_v0_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
5636
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5637
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5638
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5639
  coff_classify_symbol, coff_compute_section_file_positions,
5640
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5641
  coff_adjust_symndx, coff_link_add_one_symbol,
5642
  coff_link_output_has_begun, coff_final_link_postscript,
5643
  bfd_pe_print_pdata
5644
};
5645
#endif
5646
5647
#ifdef TICOFF
5648
/* COFF1 differs in section header size.  */
5649
5650
static const bfd_coff_backend_data ticoff1_swap_table =
5651
{
5652
  coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
5653
  coff_SWAP_aux_out, coff_SWAP_sym_out,
5654
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5655
  coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
5656
  coff_SWAP_scnhdr_out,
5657
  FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
5658
#ifdef COFF_LONG_FILENAMES
5659
  true,
5660
#else
5661
  false,
5662
#endif
5663
  COFF_DEFAULT_LONG_SECTION_NAMES,
5664
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5665
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
5666
  true,
5667
#else
5668
  false,
5669
#endif
5670
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
5671
  4,
5672
#else
5673
  2,
5674
#endif
5675
  32768,
5676
  coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5677
  coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
5678
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5679
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5680
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5681
  coff_classify_symbol, coff_compute_section_file_positions,
5682
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5683
  coff_adjust_symndx, coff_link_add_one_symbol,
5684
  coff_link_output_has_begun, coff_final_link_postscript,
5685
  bfd_pe_print_pdata  /* huh */
5686
};
5687
#endif
5688
5689
#ifdef COFF_WITH_PE_BIGOBJ
5690
/* The UID for bigobj files.  */
5691
5692
static const char header_bigobj_classid[16] =
5693
{
5694
  0xC7, 0xA1, 0xBA, 0xD1,
5695
  0xEE, 0xBA,
5696
  0xa9, 0x4b,
5697
  0xAF, 0x20,
5698
  0xFA, 0xF6, 0x6A, 0xA4, 0xDC, 0xB8
5699
};
5700
5701
/* Swap routines.  */
5702
5703
static void
5704
coff_bigobj_swap_filehdr_in (bfd * abfd, void * src, void * dst)
5705
77.3k
{
5706
77.3k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
77.3k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
77.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
77.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
77.3k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
77.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
77.3k
  filehdr_dst->f_symptr =
5714
77.3k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
77.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
77.3k
  filehdr_dst->f_opthdr = 0;
5717
77.3k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
77.3k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
77.3k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
77.3k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
77.3k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
77.3k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
77.3k
}
pe-x86_64.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
38.6k
{
5706
38.6k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
38.6k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
38.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
38.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
38.6k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
38.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
38.6k
  filehdr_dst->f_symptr =
5714
38.6k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
38.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
38.6k
  filehdr_dst->f_opthdr = 0;
5717
38.6k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
38.6k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
38.6k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
38.6k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
38.6k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
38.6k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
38.6k
}
pe-i386.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
38.6k
{
5706
38.6k
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
38.6k
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
38.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
38.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
38.6k
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
38.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
38.6k
  filehdr_dst->f_symptr =
5714
38.6k
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
38.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
38.6k
  filehdr_dst->f_opthdr = 0;
5717
38.6k
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
38.6k
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
38.6k
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
38.6k
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
38.6k
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
38.6k
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
38.6k
}
5728
5729
static unsigned int
5730
coff_bigobj_swap_filehdr_out (bfd *abfd, void * in, void * out)
5731
0
{
5732
0
  struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
5733
0
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_out =
5734
0
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) out;
5735
5736
0
  memset (filehdr_out, 0, sizeof (*filehdr_out));
5737
5738
0
  H_PUT_16 (abfd, IMAGE_FILE_MACHINE_UNKNOWN, filehdr_out->Sig1);
5739
0
  H_PUT_16 (abfd, 0xffff, filehdr_out->Sig2);
5740
0
  H_PUT_16 (abfd, 2, filehdr_out->Version);
5741
0
  memcpy (filehdr_out->ClassID, header_bigobj_classid, 16);
5742
0
  H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->Machine);
5743
0
  H_PUT_32 (abfd, filehdr_in->f_nscns, filehdr_out->NumberOfSections);
5744
0
  H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->TimeDateStamp);
5745
0
  PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
5746
0
          filehdr_out->PointerToSymbolTable);
5747
0
  H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->NumberOfSymbols);
5748
5749
0
  return bfd_coff_filhsz (abfd);
5750
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_filehdr_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_filehdr_out
5751
5752
static void
5753
coff_bigobj_swap_sym_in (bfd * abfd, void * ext1, void * in1)
5754
0
{
5755
0
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5756
0
  struct internal_syment *in = (struct internal_syment *) in1;
5757
5758
0
  if (ext->e.e_name[0] == 0)
5759
0
    {
5760
0
      in->_n._n_n._n_zeroes = 0;
5761
0
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5762
0
    }
5763
0
  else
5764
0
    {
5765
#if SYMNMLEN != E_SYMNMLEN
5766
#error we need to cope with truncating or extending SYMNMLEN
5767
#else
5768
0
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5769
0
#endif
5770
0
    }
5771
5772
0
  in->n_value = H_GET_32 (abfd, ext->e_value);
5773
0
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5774
0
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5775
0
  in->n_type = H_GET_16 (abfd, ext->e_type);
5776
0
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5777
0
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5778
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_sym_in
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_sym_in
5779
5780
static unsigned int
5781
coff_bigobj_swap_sym_out (bfd * abfd, void * inp, void * extp)
5782
0
{
5783
0
  struct internal_syment *in = (struct internal_syment *) inp;
5784
0
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) extp;
5785
5786
0
  if (in->_n._n_name[0] == 0)
5787
0
    {
5788
0
      H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
5789
0
      H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
5790
0
    }
5791
0
  else
5792
0
    {
5793
#if SYMNMLEN != E_SYMNMLEN
5794
#error we need to cope with truncating or extending SYMNMLEN
5795
#else
5796
0
      memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
5797
0
#endif
5798
0
    }
5799
5800
0
  H_PUT_32 (abfd, in->n_value, ext->e_value);
5801
0
  H_PUT_32 (abfd, in->n_scnum, ext->e_scnum);
5802
5803
0
  H_PUT_16 (abfd, in->n_type, ext->e_type);
5804
0
  H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
5805
0
  H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
5806
5807
0
  return SYMESZ_BIGOBJ;
5808
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_sym_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_sym_out
5809
5810
static void
5811
coff_bigobj_swap_aux_in (bfd *abfd,
5812
       void * ext1,
5813
       int type,
5814
       int in_class,
5815
       int indx,
5816
       int numaux,
5817
       void * in1)
5818
0
{
5819
0
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5820
0
  union internal_auxent *in = (union internal_auxent *) in1;
5821
5822
  /* Make sure that all fields in the aux structure are
5823
     initialised.  */
5824
0
  memset (in, 0, sizeof * in);
5825
0
  switch (in_class)
5826
0
    {
5827
0
    case C_FILE:
5828
0
      if (numaux > 1)
5829
0
  {
5830
0
    if (indx == 0)
5831
0
      memcpy (in->x_file.x_n.x_fname, ext->File.Name,
5832
0
        numaux * sizeof (AUXENT_BIGOBJ));
5833
0
  }
5834
0
      else
5835
0
  memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5836
0
      break;
5837
5838
0
    case C_STAT:
5839
0
    case C_LEAFSTAT:
5840
0
    case C_HIDDEN:
5841
0
      if (type == T_NULL)
5842
0
  {
5843
0
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5844
0
    in->x_scn.x_nreloc =
5845
0
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5846
0
    in->x_scn.x_nlinno =
5847
0
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5848
0
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5849
0
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5850
0
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5851
0
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5852
0
    return;
5853
0
  }
5854
0
      break;
5855
5856
0
    default:
5857
0
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5858
      /* Characteristics is ignored.  */
5859
0
      break;
5860
0
    }
5861
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_aux_in
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_aux_in
5862
5863
static unsigned int
5864
coff_bigobj_swap_aux_out (bfd * abfd,
5865
        void * inp,
5866
        int type,
5867
        int in_class,
5868
        int indx ATTRIBUTE_UNUSED,
5869
        int numaux ATTRIBUTE_UNUSED,
5870
        void * extp)
5871
0
{
5872
0
  union internal_auxent * in = (union internal_auxent *) inp;
5873
0
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) extp;
5874
5875
0
  memset (ext, 0, AUXESZ);
5876
5877
0
  switch (in_class)
5878
0
    {
5879
0
    case C_FILE:
5880
0
      memcpy (ext->File.Name, in->x_file.x_n.x_fname, sizeof (ext->File.Name));
5881
5882
0
      return AUXESZ;
5883
5884
0
    case C_STAT:
5885
0
    case C_LEAFSTAT:
5886
0
    case C_HIDDEN:
5887
0
      if (type == T_NULL)
5888
0
  {
5889
0
    H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->Section.Length);
5890
0
    H_PUT_16 (abfd, in->x_scn.x_nreloc,
5891
0
        ext->Section.NumberOfRelocations);
5892
0
    H_PUT_16 (abfd, in->x_scn.x_nlinno,
5893
0
        ext->Section.NumberOfLinenumbers);
5894
0
    H_PUT_32 (abfd, in->x_scn.x_checksum, ext->Section.Checksum);
5895
0
    H_PUT_16 (abfd, in->x_scn.x_associated & 0xffff,
5896
0
        ext->Section.Number);
5897
0
    H_PUT_16 (abfd, (in->x_scn.x_associated >> 16),
5898
0
        ext->Section.HighNumber);
5899
0
    H_PUT_8 (abfd, in->x_scn.x_comdat, ext->Section.Selection);
5900
0
    return AUXESZ;
5901
0
  }
5902
0
      break;
5903
0
    }
5904
5905
0
  H_PUT_32 (abfd, in->x_sym.x_tagndx.u32, ext->Sym.WeakDefaultSymIndex);
5906
0
  H_PUT_32 (abfd, 1, ext->Sym.WeakSearchType);
5907
5908
0
  return AUXESZ;
5909
0
}
Unexecuted instantiation: pe-x86_64.c:coff_bigobj_swap_aux_out
Unexecuted instantiation: pe-i386.c:coff_bigobj_swap_aux_out
5910
5911
static const bfd_coff_backend_data bigobj_swap_table =
5912
{
5913
  coff_bigobj_swap_aux_in, coff_bigobj_swap_sym_in, coff_SWAP_lineno_in,
5914
  coff_bigobj_swap_aux_out, coff_bigobj_swap_sym_out,
5915
  coff_SWAP_lineno_out, coff_SWAP_reloc_out,
5916
  coff_bigobj_swap_filehdr_out, coff_SWAP_aouthdr_out,
5917
  coff_SWAP_scnhdr_out,
5918
  FILHSZ_BIGOBJ, AOUTSZ, SCNHSZ, SYMESZ_BIGOBJ, AUXESZ_BIGOBJ,
5919
   RELSZ, LINESZ, FILNMLEN_BIGOBJ,
5920
  true,
5921
  COFF_DEFAULT_LONG_SECTION_NAMES,
5922
  COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
5923
  false,
5924
  2,
5925
  1U << 31,
5926
  coff_bigobj_swap_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
5927
  coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
5928
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
5929
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
5930
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
5931
  coff_classify_symbol, coff_compute_section_file_positions,
5932
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
5933
  coff_adjust_symndx, coff_link_add_one_symbol,
5934
  coff_link_output_has_begun, coff_final_link_postscript,
5935
  bfd_pe_print_pdata  /* huh */
5936
};
5937
5938
#endif /* COFF_WITH_PE_BIGOBJ */
5939
5940
#ifndef coff_close_and_cleanup
5941
#define coff_close_and_cleanup        _bfd_generic_close_and_cleanup
5942
#endif
5943
5944
#ifndef coff_bfd_free_cached_info
5945
#define coff_bfd_free_cached_info     _bfd_coff_free_cached_info
5946
#endif
5947
5948
#ifndef coff_get_section_contents
5949
#define coff_get_section_contents     _bfd_generic_get_section_contents
5950
#endif
5951
5952
#ifndef coff_bfd_copy_private_symbol_data
5953
#define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
5954
#endif
5955
5956
#ifndef coff_bfd_copy_private_header_data
5957
#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
5958
#endif
5959
5960
#ifndef coff_bfd_copy_private_section_data
5961
#define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
5962
#endif
5963
5964
#ifndef coff_bfd_copy_private_bfd_data
5965
#define coff_bfd_copy_private_bfd_data      _bfd_generic_bfd_copy_private_bfd_data
5966
#endif
5967
5968
#ifndef coff_bfd_merge_private_bfd_data
5969
#define coff_bfd_merge_private_bfd_data     _bfd_generic_bfd_merge_private_bfd_data
5970
#endif
5971
5972
#ifndef coff_bfd_set_private_flags
5973
#define coff_bfd_set_private_flags      _bfd_generic_bfd_set_private_flags
5974
#endif
5975
5976
#ifndef coff_bfd_print_private_bfd_data
5977
#define coff_bfd_print_private_bfd_data     _bfd_generic_bfd_print_private_bfd_data
5978
#endif
5979
5980
#ifndef coff_bfd_is_local_label_name
5981
#define coff_bfd_is_local_label_name      _bfd_coff_is_local_label_name
5982
#endif
5983
5984
#ifndef coff_bfd_is_target_special_symbol
5985
#define coff_bfd_is_target_special_symbol   _bfd_bool_bfd_asymbol_false
5986
#endif
5987
5988
#ifndef coff_read_minisymbols
5989
#define coff_read_minisymbols       _bfd_generic_read_minisymbols
5990
#endif
5991
5992
#ifndef coff_minisymbol_to_symbol
5993
#define coff_minisymbol_to_symbol     _bfd_generic_minisymbol_to_symbol
5994
#endif
5995
5996
/* The reloc lookup routine must be supplied by each individual COFF
5997
   backend.  */
5998
#ifndef coff_bfd_reloc_type_lookup
5999
#define coff_bfd_reloc_type_lookup      _bfd_norelocs_bfd_reloc_type_lookup
6000
#endif
6001
#ifndef coff_bfd_reloc_name_lookup
6002
#define coff_bfd_reloc_name_lookup    _bfd_norelocs_bfd_reloc_name_lookup
6003
#endif
6004
6005
#ifndef coff_bfd_get_relocated_section_contents
6006
#define coff_bfd_get_relocated_section_contents \
6007
  bfd_generic_get_relocated_section_contents
6008
#endif
6009
6010
#ifndef coff_bfd_relax_section
6011
#define coff_bfd_relax_section        bfd_generic_relax_section
6012
#endif
6013
6014
#ifndef coff_bfd_gc_sections
6015
#define coff_bfd_gc_sections        bfd_coff_gc_sections
6016
#endif
6017
6018
#ifndef coff_bfd_lookup_section_flags
6019
#define coff_bfd_lookup_section_flags     bfd_generic_lookup_section_flags
6020
#endif
6021
6022
#ifndef coff_bfd_merge_sections
6023
#define coff_bfd_merge_sections       bfd_generic_merge_sections
6024
#endif
6025
6026
#ifndef coff_bfd_is_group_section
6027
#define coff_bfd_is_group_section     bfd_generic_is_group_section
6028
#endif
6029
6030
#ifndef coff_bfd_group_name
6031
#define coff_bfd_group_name       bfd_coff_group_name
6032
#endif
6033
6034
#ifndef coff_bfd_discard_group
6035
#define coff_bfd_discard_group        bfd_generic_discard_group
6036
#endif
6037
6038
#ifndef coff_section_already_linked
6039
#define coff_section_already_linked \
6040
  _bfd_coff_section_already_linked
6041
#endif
6042
6043
#ifndef coff_bfd_define_common_symbol
6044
#define coff_bfd_define_common_symbol     bfd_generic_define_common_symbol
6045
#endif
6046
6047
#ifndef coff_bfd_link_hide_symbol
6048
#define coff_bfd_link_hide_symbol     _bfd_generic_link_hide_symbol
6049
#endif
6050
6051
#ifndef coff_bfd_define_start_stop
6052
#define coff_bfd_define_start_stop      bfd_generic_define_start_stop
6053
#endif
6054
6055
#define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
6056
const bfd_target VAR =              \
6057
{                 \
6058
  NAME ,                \
6059
  bfd_target_coff_flavour,            \
6060
  BFD_ENDIAN_BIG,   /* Data byte order is big.  */    \
6061
  BFD_ENDIAN_BIG,   /* Header byte order is big.  */  \
6062
  /* object flags */              \
6063
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6064
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6065
  /* section flags */             \
6066
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6067
  UNDER,      /* Leading symbol underscore.  */ \
6068
  '/',        /* AR_pad_char.  */     \
6069
  15,       /* AR_max_namelen.  */      \
6070
  0,        /* match priority.  */      \
6071
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6072
                  \
6073
  /* Data conversion functions.  */         \
6074
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6075
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6076
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6077
                  \
6078
  /* Header conversion functions.  */         \
6079
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6080
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6081
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6082
                  \
6083
  {       /* bfd_check_format.  */    \
6084
    _bfd_dummy_target,              \
6085
    coff_object_p,              \
6086
    bfd_generic_archive_p,            \
6087
    _bfd_dummy_target             \
6088
  },                  \
6089
  {       /* bfd_set_format.  */      \
6090
    _bfd_bool_bfd_false_error,            \
6091
    coff_mkobject,              \
6092
    _bfd_generic_mkarchive,           \
6093
    _bfd_bool_bfd_false_error           \
6094
  },                  \
6095
  {       /* bfd_write_contents.  */    \
6096
    _bfd_bool_bfd_false_error,            \
6097
    coff_write_object_contents,           \
6098
    _bfd_write_archive_contents,          \
6099
    _bfd_bool_bfd_false_error           \
6100
  },                  \
6101
                  \
6102
  BFD_JUMP_TABLE_GENERIC (coff),          \
6103
  BFD_JUMP_TABLE_COPY (coff),           \
6104
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6105
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6106
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6107
  BFD_JUMP_TABLE_RELOCS (coff),           \
6108
  BFD_JUMP_TABLE_WRITE (coff),            \
6109
  BFD_JUMP_TABLE_LINK (coff),           \
6110
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6111
                  \
6112
  ALTERNATIVE,                \
6113
                  \
6114
  SWAP_TABLE                \
6115
};
6116
6117
#define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
6118
const bfd_target VAR =              \
6119
{                 \
6120
  NAME ,                \
6121
  bfd_target_coff_flavour,            \
6122
  BFD_ENDIAN_LITTLE,    /* Data byte order is little.  */ \
6123
  BFD_ENDIAN_BIG,   /* Header byte order is big.  */  \
6124
  /* object flags */              \
6125
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6126
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6127
  /* section flags */             \
6128
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6129
  UNDER,      /* Leading symbol underscore.  */ \
6130
  '/',        /* AR_pad_char.  */     \
6131
  15,       /* AR_max_namelen.  */      \
6132
  0,        /* match priority.  */      \
6133
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6134
                  \
6135
  /* Data conversion functions.  */         \
6136
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6137
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6138
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6139
                  \
6140
  /* Header conversion functions.  */         \
6141
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,       \
6142
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,       \
6143
  bfd_getb16, bfd_getb_signed_16, bfd_putb16,       \
6144
                  \
6145
  {       /* bfd_check_format.  */    \
6146
    _bfd_dummy_target,              \
6147
    coff_object_p,              \
6148
    bfd_generic_archive_p,            \
6149
    _bfd_dummy_target             \
6150
  },                  \
6151
  {       /* bfd_set_format.  */      \
6152
    _bfd_bool_bfd_false_error,            \
6153
    coff_mkobject,              \
6154
    _bfd_generic_mkarchive,           \
6155
    _bfd_bool_bfd_false_error           \
6156
  },                  \
6157
  {       /* bfd_write_contents.  */    \
6158
    _bfd_bool_bfd_false_error,            \
6159
    coff_write_object_contents,           \
6160
    _bfd_write_archive_contents,          \
6161
    _bfd_bool_bfd_false_error           \
6162
  },                  \
6163
                  \
6164
  BFD_JUMP_TABLE_GENERIC (coff),          \
6165
  BFD_JUMP_TABLE_COPY (coff),           \
6166
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6167
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6168
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6169
  BFD_JUMP_TABLE_RELOCS (coff),           \
6170
  BFD_JUMP_TABLE_WRITE (coff),            \
6171
  BFD_JUMP_TABLE_LINK (coff),           \
6172
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6173
                  \
6174
  ALTERNATIVE,                \
6175
                  \
6176
  SWAP_TABLE                \
6177
};
6178
6179
#define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)  \
6180
const bfd_target VAR =              \
6181
{                 \
6182
  NAME ,                \
6183
  bfd_target_coff_flavour,            \
6184
  BFD_ENDIAN_LITTLE,    /* Data byte order is little.  */ \
6185
  BFD_ENDIAN_LITTLE,    /* Header byte order is little.  */ \
6186
  /* object flags */            \
6187
  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG |      \
6188
   HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS),      \
6189
  /* section flags */           \
6190
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
6191
  UNDER,      /* Leading symbol underscore.  */ \
6192
  '/',        /* AR_pad_char.  */     \
6193
  15,       /* AR_max_namelen.  */      \
6194
  0,        /* match priority.  */      \
6195
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */ \
6196
                  \
6197
  /* Data conversion functions.  */         \
6198
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,       \
6199
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,       \
6200
  bfd_getl16, bfd_getl_signed_16, bfd_putl16,       \
6201
  /* Header conversion functions.  */         \
6202
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,       \
6203
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,       \
6204
  bfd_getl16, bfd_getl_signed_16, bfd_putl16,       \
6205
                  \
6206
  {       /* bfd_check_format.  */    \
6207
    _bfd_dummy_target,              \
6208
    coff_object_p,              \
6209
    bfd_generic_archive_p,            \
6210
    _bfd_dummy_target             \
6211
  },                  \
6212
  {       /* bfd_set_format.  */      \
6213
    _bfd_bool_bfd_false_error,            \
6214
    coff_mkobject,              \
6215
    _bfd_generic_mkarchive,           \
6216
    _bfd_bool_bfd_false_error           \
6217
  },                  \
6218
  {       /* bfd_write_contents.  */    \
6219
    _bfd_bool_bfd_false_error,            \
6220
    coff_write_object_contents,           \
6221
    _bfd_write_archive_contents,          \
6222
    _bfd_bool_bfd_false_error           \
6223
  },                  \
6224
                  \
6225
  BFD_JUMP_TABLE_GENERIC (coff),          \
6226
  BFD_JUMP_TABLE_COPY (coff),           \
6227
  BFD_JUMP_TABLE_CORE (_bfd_nocore),          \
6228
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),       \
6229
  BFD_JUMP_TABLE_SYMBOLS (coff),          \
6230
  BFD_JUMP_TABLE_RELOCS (coff),           \
6231
  BFD_JUMP_TABLE_WRITE (coff),            \
6232
  BFD_JUMP_TABLE_LINK (coff),           \
6233
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),        \
6234
                  \
6235
  ALTERNATIVE,                \
6236
                  \
6237
  SWAP_TABLE                \
6238
};