Coverage Report

Created: 2023-08-28 06:31

/src/binutils-gdb/bfd/coffcode.h
Line
Count
Source (jump to first uncovered line)
1
/* Support for the generic parts of most COFF variants, for BFD.
2
   Copyright (C) 1990-2023 Free Software Foundation, Inc.
3
   Written by Cygnus Support.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
/* Most of this hacked by  Steve Chamberlain,
23
      sac@cygnus.com.  */
24
/*
25
SECTION
26
  coff backends
27
28
  BFD supports a number of different flavours of coff format.
29
  The major differences between formats are the sizes and
30
  alignments of fields in structures on disk, and the occasional
31
  extra field.
32
33
  Coff in all its varieties is implemented with a few common
34
  files and a number of implementation specific files. For
35
  example, the i386 coff format is implemented in the file
36
  @file{coff-i386.c}.  This file @code{#include}s
37
  @file{coff/i386.h} which defines the external structure of the
38
  coff format for the i386, and @file{coff/internal.h} which
39
  defines the internal structure. @file{coff-i386.c} also
40
  defines the relocations used by the i386 coff format
41
  @xref{Relocations}.
42
43
SUBSECTION
44
  Porting to a new version of coff
45
46
  The recommended method is to select from the existing
47
  implementations the version of coff which is most like the one
48
  you want to use.  For example, we'll say that i386 coff is
49
  the one you select, and that your coff flavour is called foo.
50
  Copy @file{i386coff.c} to @file{foocoff.c}, copy
51
  @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
52
  and add the lines to @file{targets.c} and @file{Makefile.in}
53
  so that your new back end is used. Alter the shapes of the
54
  structures in @file{../include/coff/foo.h} so that they match
55
  what you need. You will probably also have to add
56
  @code{#ifdef}s to the code in @file{coff/internal.h} and
57
  @file{coffcode.h} if your version of coff is too wild.
58
59
  You can verify that your new BFD backend works quite simply by
60
  building @file{objdump} from the @file{binutils} directory,
61
  and making sure that its version of what's going on and your
62
  host system's idea (assuming it has the pretty standard coff
63
  dump utility, usually called @code{att-dump} or just
64
  @code{dump}) are the same.  Then clean up your code, and send
65
  what you've done to Cygnus. Then your stuff will be in the
66
  next release, and you won't have to keep integrating it.
67
68
SUBSECTION
69
  How the coff backend works
70
71
SUBSUBSECTION
72
  File layout
73
74
  The Coff backend is split into generic routines that are
75
  applicable to any Coff target and routines that are specific
76
  to a particular target.  The target-specific routines are
77
  further split into ones which are basically the same for all
78
  Coff targets except that they use the external symbol format
79
  or use different values for certain constants.
80
81
  The generic routines are in @file{coffgen.c}.  These routines
82
  work for any Coff target.  They use some hooks into the target
83
  specific code; the hooks are in a @code{bfd_coff_backend_data}
84
  structure, one of which exists for each target.
85
86
  The essentially similar target-specific routines are in
87
  @file{coffcode.h}.  This header file includes executable C code.
88
  The various Coff targets first include the appropriate Coff
89
  header file, make any special defines that are needed, and
90
  then include @file{coffcode.h}.
91
92
  Some of the Coff targets then also have additional routines in
93
  the target source file itself.
94
95
SUBSUBSECTION
96
  Coff long section names
97
98
  In the standard Coff object format, section names are limited to
99
  the eight bytes available in the @code{s_name} field of the
100
  @code{SCNHDR} section header structure.  The format requires the
101
  field to be NUL-padded, but not necessarily NUL-terminated, so
102
  the longest section names permitted are a full eight characters.
103
104
  The Microsoft PE variants of the Coff object file format add
105
  an extension to support the use of long section names.  This
106
  extension is defined in section 4 of the Microsoft PE/COFF
107
  specification (rev 8.1).  If a section name is too long to fit
108
  into the section header's @code{s_name} field, it is instead
109
  placed into the string table, and the @code{s_name} field is
110
  filled with a slash ("/") followed by the ASCII decimal
111
  representation of the offset of the full name relative to the
112
  string table base.
113
114
  Note that this implies that the extension can only be used in object
115
  files, as executables do not contain a string table.  The standard
116
  specifies that long section names from objects emitted into executable
117
  images are to be truncated.
118
119
  However, as a GNU extension, BFD can generate executable images
120
  that contain a string table and long section names.  This
121
  would appear to be technically valid, as the standard only says
122
  that Coff debugging information is deprecated, not forbidden,
123
  and in practice it works, although some tools that parse PE files
124
  expecting the MS standard format may become confused; @file{PEview} is
125
  one known example.
126
127
  The functionality is supported in BFD by code implemented under
128
  the control of the macro @code{COFF_LONG_SECTION_NAMES}.  If not
129
  defined, the format does not support long section names in any way.
130
  If defined, it is used to initialise a flag,
131
  @code{_bfd_coff_long_section_names}, and a hook function pointer,
132
  @code{_bfd_coff_set_long_section_names}, in the Coff backend data
133
  structure.  The flag controls the generation of long section names
134
  in output BFDs at runtime; if it is false, as it will be by default
135
  when generating an executable image, long section names are truncated;
136
  if true, the long section names extension is employed.  The hook
137
  points to a function that allows the value of a copy of the flag
138
  in coff object tdata to be altered at runtime, on formats that
139
  support long section names at all; on other formats it points
140
  to a stub that returns an error indication.
141
142
  With input BFDs, the flag is set according to whether any long section
143
  names are detected while reading the section headers.  For a completely
144
  new BFD, the flag is set to the default for the target format.  This
145
  information can be used by a client of the BFD library when deciding
146
  what output format to generate, and means that a BFD that is opened
147
  for read and subsequently converted to a writeable BFD and modified
148
  in-place will retain whatever format it had on input.
149
150
  If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
151
  defined to the value "1", then long section names are enabled by
152
  default; if it is defined to the value zero, they are disabled by
153
  default (but still accepted in input BFDs).  The header @file{coffcode.h}
154
  defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
155
  used in the backends to initialise the backend data structure fields
156
  appropriately; see the comments for further detail.
157
158
SUBSUBSECTION
159
  Bit twiddling
160
161
  Each flavour of coff supported in BFD has its own header file
162
  describing the external layout of the structures. There is also
163
  an internal description of the coff layout, in
164
  @file{coff/internal.h}. A major function of the
165
  coff backend is swapping the bytes and twiddling the bits to
166
  translate the external form of the structures into the normal
167
  internal form. This is all performed in the
168
  @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
169
  elements are different sizes between different versions of
170
  coff; it is the duty of the coff version specific include file
171
  to override the definitions of various packing routines in
172
  @file{coffcode.h}. E.g., the size of line number entry in coff is
173
  sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
174
  @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
175
  correct one. No doubt, some day someone will find a version of
176
  coff which has a varying field size not catered to at the
177
  moment. To port BFD, that person will have to add more @code{#defines}.
178
  Three of the bit twiddling routines are exported to
179
  @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
180
  and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
181
  table on its own, but uses BFD to fix things up.  More of the
182
  bit twiddlers are exported for @code{gas};
183
  @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
184
  @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
185
  @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
186
  @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
187
  of all the symbol table and reloc drudgery itself, thereby
188
  saving the internal BFD overhead, but uses BFD to swap things
189
  on the way out, making cross ports much safer.  Doing so also
190
  allows BFD (and thus the linker) to use the same header files
191
  as @code{gas}, which makes one avenue to disaster disappear.
192
193
SUBSUBSECTION
194
  Symbol reading
195
196
  The simple canonical form for symbols used by BFD is not rich
197
  enough to keep all the information available in a coff symbol
198
  table. The back end gets around this problem by keeping the original
199
  symbol table around, "behind the scenes".
200
201
  When a symbol table is requested (through a call to
202
  @code{bfd_canonicalize_symtab}), a request gets through to
203
  @code{coff_get_normalized_symtab}. This reads the symbol table from
204
  the coff file and swaps all the structures inside into the
205
  internal form. It also fixes up all the pointers in the table
206
  (represented in the file by offsets from the first symbol in
207
  the table) into physical pointers to elements in the new
208
  internal table. This involves some work since the meanings of
209
  fields change depending upon context: a field that is a
210
  pointer to another structure in the symbol table at one moment
211
  may be the size in bytes of a structure at the next.  Another
212
  pass is made over the table. All symbols which mark file names
213
  (<<C_FILE>> symbols) are modified so that the internal
214
  string points to the value in the auxent (the real filename)
215
  rather than the normal text associated with the symbol
216
  (@code{".file"}).
217
218
  At this time the symbol names are moved around. Coff stores
219
  all symbols less than nine characters long physically
220
  within the symbol table; longer strings are kept at the end of
221
  the file in the string table. This pass moves all strings
222
  into memory and replaces them with pointers to the strings.
223
224
  The symbol table is massaged once again, this time to create
225
  the canonical table used by the BFD application. Each symbol
226
  is inspected in turn, and a decision made (using the
227
  @code{sclass} field) about the various flags to set in the
228
  @code{asymbol}.  @xref{Symbols}. The generated canonical table
229
  shares strings with the hidden internal symbol table.
230
231
  Any linenumbers are read from the coff file too, and attached
232
  to the symbols which own the functions the linenumbers belong to.
233
234
SUBSUBSECTION
235
  Symbol writing
236
237
  Writing a symbol to a coff file which didn't come from a coff
238
  file will lose any debugging information. The @code{asymbol}
239
  structure remembers the BFD from which the symbol was taken, and on
240
  output the back end makes sure that the same destination target as
241
  source target is present.
242
243
  When the symbols have come from a coff file then all the
244
  debugging information is preserved.
245
246
  Symbol tables are provided for writing to the back end in a
247
  vector of pointers to pointers. This allows applications like
248
  the linker to accumulate and output large symbol tables
249
  without having to do too much byte copying.
250
251
  This function runs through the provided symbol table and
252
  patches each symbol marked as a file place holder
253
  (@code{C_FILE}) to point to the next file place holder in the
254
  list. It also marks each @code{offset} field in the list with
255
  the offset from the first symbol of the current symbol.
256
257
  Another function of this procedure is to turn the canonical
258
  value form of BFD into the form used by coff. Internally, BFD
259
  expects symbol values to be offsets from a section base; so a
260
  symbol physically at 0x120, but in a section starting at
261
  0x100, would have the value 0x20. Coff expects symbols to
262
  contain their final value, so symbols have their values
263
  changed at this point to reflect their sum with their owning
264
  section.  This transformation uses the
265
  <<output_section>> field of the @code{asymbol}'s
266
  @code{asection} @xref{Sections}.
267
268
  o <<coff_mangle_symbols>>
269
270
  This routine runs though the provided symbol table and uses
271
  the offsets generated by the previous pass and the pointers
272
  generated when the symbol table was read in to create the
273
  structured hierarchy required by coff. It changes each pointer
274
  to a symbol into the index into the symbol table of the asymbol.
275
276
  o <<coff_write_symbols>>
277
278
  This routine runs through the symbol table and patches up the
279
  symbols from their internal form into the coff way, calls the
280
  bit twiddlers, and writes out the table to the file.
281
282
*/
283
284
/*
285
INTERNAL_DEFINITION
286
  coff_symbol_type
287
288
DESCRIPTION
289
  The hidden information for an <<asymbol>> is described in a
290
  <<combined_entry_type>>:
291
292
CODE_FRAGMENT
293
.typedef struct coff_ptr_struct
294
.{
295
.  {* Remembers the offset from the first symbol in the file for
296
.     this symbol.  Generated by coff_renumber_symbols.  *}
297
.  unsigned int offset;
298
.
299
.  {* Selects between the elements of the union below.  *}
300
.  unsigned int is_sym : 1;
301
.
302
.  {* Selects between the elements of the x_sym.x_tagndx union.  If set,
303
.     p is valid and the field will be renumbered.  *}
304
.  unsigned int fix_tag : 1;
305
.
306
.  {* Selects between the elements of the x_sym.x_fcnary.x_fcn.x_endndx
307
.     union.  If set, p is valid and the field will be renumbered.  *}
308
.  unsigned int fix_end : 1;
309
.
310
.  {* Selects between the elements of the x_csect.x_scnlen union.  If set,
311
.     p is valid and the field will be renumbered.  *}
312
.  unsigned int fix_scnlen : 1;
313
.
314
.  {* If set, u.syment.n_value contains a pointer to a symbol.  The final
315
.     value will be the offset field.  Used for XCOFF C_BSTAT symbols.  *}
316
.  unsigned int fix_value : 1;
317
.
318
.  {* If set, u.syment.n_value is an index into the line number entries.
319
.     Used for XCOFF C_BINCL/C_EINCL symbols.  *}
320
.  unsigned int fix_line : 1;
321
.
322
.  {* The container for the symbol structure as read and translated
323
.     from the file.  *}
324
.  union
325
.  {
326
.    union internal_auxent auxent;
327
.    struct internal_syment syment;
328
.  } u;
329
.
330
. {* An extra pointer which can used by format based on COFF (like XCOFF)
331
.    to provide extra information to their backend.  *}
332
. void *extrap;
333
.} combined_entry_type;
334
.
335
.{* Each canonical asymbol really looks like this: *}
336
.
337
.typedef struct coff_symbol_struct
338
.{
339
.  {* The actual symbol which the rest of BFD works with *}
340
.  asymbol symbol;
341
.
342
.  {* A pointer to the hidden information for this symbol *}
343
.  combined_entry_type *native;
344
.
345
.  {* A pointer to the linenumber information for this symbol *}
346
.  struct lineno_cache_entry *lineno;
347
.
348
.  {* Have the line numbers been relocated yet ? *}
349
.  bool done_lineno;
350
.} coff_symbol_type;
351
.
352
*/
353
354
#include "libiberty.h"
355
#include <string.h>
356
357
#ifdef COFF_WITH_PE
358
#include "peicode.h"
359
#else
360
#include "coffswap.h"
361
#endif
362
363
22
#define STRING_SIZE_SIZE 4
364
365
38.3M
#define DOT_DEBUG ".debug"
366
38.2M
#define DOT_ZDEBUG  ".zdebug"
367
5.91M
#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
368
5.91M
#define GNU_LINKONCE_WT ".gnu.linkonce.wt."
369
94
#define DOT_RELOC ".reloc"
370
371
#if defined(COFF_WITH_PE) || defined(COFF_GO32_EXE) || defined(COFF_GO32)
372
# define COFF_WITH_EXTENDED_RELOC_COUNTER
373
#endif
374
375
#if defined (COFF_LONG_SECTION_NAMES)
376
/* Needed to expand the inputs to BLANKOR1TOODD.  */
377
#define COFFLONGSECTIONCATHELPER(x,y)    x ## y
378
/* If the input macro Y is blank or '1', return an odd number; if it is
379
   '0', return an even number.  Result undefined in all other cases.  */
380
#define BLANKOR1TOODD(y)     COFFLONGSECTIONCATHELPER(1,y)
381
/* Defined to numerical 0 or 1 according to whether generation of long
382
   section names is disabled or enabled by default.  */
383
#define COFF_ENABLE_LONG_SECTION_NAMES   (BLANKOR1TOODD(COFF_LONG_SECTION_NAMES) & 1)
384
/* Where long section names are supported, we allow them to be enabled
385
   and disabled at runtime, so select an appropriate hook function for
386
   _bfd_coff_set_long_section_names.  */
387
#define COFF_LONG_SECTION_NAMES_SETTER   bfd_coff_set_long_section_names_allowed
388
#else /* !defined (COFF_LONG_SECTION_NAMES) */
389
/* If long section names are not supported, this stub disallows any
390
   attempt to enable them at run-time.  */
391
#define COFF_LONG_SECTION_NAMES_SETTER   bfd_coff_set_long_section_names_disallowed
392
#endif /* defined (COFF_LONG_SECTION_NAMES) */
393
394
/* Define a macro that can be used to initialise both the fields relating
395
   to long section names in the backend data struct simultaneously.  */
396
#if COFF_ENABLE_LONG_SECTION_NAMES
397
#define COFF_DEFAULT_LONG_SECTION_NAMES  (true), COFF_LONG_SECTION_NAMES_SETTER
398
#else /* !COFF_ENABLE_LONG_SECTION_NAMES */
399
#define COFF_DEFAULT_LONG_SECTION_NAMES  (false), COFF_LONG_SECTION_NAMES_SETTER
400
#endif /* COFF_ENABLE_LONG_SECTION_NAMES */
401
402
static enum coff_symbol_classification coff_classify_symbol
403
  (bfd *, struct internal_syment *);
404

405
/* void warning(); */
406
407
#if defined (COFF_LONG_SECTION_NAMES)
408
static bool
409
bfd_coff_set_long_section_names_allowed (bfd *abfd, int enable)
410
9.37M
{
411
9.37M
  bfd_coff_long_section_names (abfd) = enable;
412
9.37M
  return true;
413
9.37M
}
pei-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
285k
{
411
285k
  bfd_coff_long_section_names (abfd) = enable;
412
285k
  return true;
413
285k
}
pe-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
320k
{
411
320k
  bfd_coff_long_section_names (abfd) = enable;
412
320k
  return true;
413
320k
}
pei-x86_64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
214k
{
411
214k
  bfd_coff_long_section_names (abfd) = enable;
412
214k
  return true;
413
214k
}
pe-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
123k
{
411
123k
  bfd_coff_long_section_names (abfd) = enable;
412
123k
  return true;
413
123k
}
pei-aarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
157k
{
411
157k
  bfd_coff_long_section_names (abfd) = enable;
412
157k
  return true;
413
157k
}
pei-ia64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
225k
{
411
225k
  bfd_coff_long_section_names (abfd) = enable;
412
225k
  return true;
413
225k
}
pei-loongarch64.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
170k
{
411
170k
  bfd_coff_long_section_names (abfd) = enable;
412
170k
  return true;
413
170k
}
coff-go32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
4.99M
{
411
4.99M
  bfd_coff_long_section_names (abfd) = enable;
412
4.99M
  return true;
413
4.99M
}
coff-stgo32.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
360k
{
411
360k
  bfd_coff_long_section_names (abfd) = enable;
412
360k
  return true;
413
360k
}
pe-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
40.8k
{
411
40.8k
  bfd_coff_long_section_names (abfd) = enable;
412
40.8k
  return true;
413
40.8k
}
pe-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
40.8k
{
411
40.8k
  bfd_coff_long_section_names (abfd) = enable;
412
40.8k
  return true;
413
40.8k
}
pe-i386.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
116k
{
411
116k
  bfd_coff_long_section_names (abfd) = enable;
412
116k
  return true;
413
116k
}
pe-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
807k
{
411
807k
  bfd_coff_long_section_names (abfd) = enable;
412
807k
  return true;
413
807k
}
pe-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
96.7k
{
411
96.7k
  bfd_coff_long_section_names (abfd) = enable;
412
96.7k
  return true;
413
96.7k
}
pei-arm-wince.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
200k
{
411
200k
  bfd_coff_long_section_names (abfd) = enable;
412
200k
  return true;
413
200k
}
pei-arm.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
782k
{
411
782k
  bfd_coff_long_section_names (abfd) = enable;
412
782k
  return true;
413
782k
}
pei-mcore.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
210k
{
411
210k
  bfd_coff_long_section_names (abfd) = enable;
412
210k
  return true;
413
210k
}
pei-sh.c:bfd_coff_set_long_section_names_allowed
Line
Count
Source
410
227k
{
411
227k
  bfd_coff_long_section_names (abfd) = enable;
412
227k
  return true;
413
227k
}
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
87.3M
{
419
87.3M
  return false;
420
87.3M
}
coff-x86_64.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
9.32M
{
419
9.32M
  return false;
420
9.32M
}
coff64-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
4.62M
{
419
4.62M
  return false;
420
4.62M
}
cf-i386lynx.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
6.05M
{
419
6.05M
  return false;
420
6.05M
}
coff-i386.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
5.72M
{
419
5.72M
  return false;
420
5.72M
}
coff-rs6000.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
25.5M
{
419
25.5M
  return false;
420
25.5M
}
coff-sh.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
12.2M
{
419
12.2M
  return false;
420
12.2M
}
coff-tic30.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
5.80M
{
419
5.80M
  return false;
420
5.80M
}
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
8.33M
{
419
8.33M
  return false;
420
8.33M
}
coff-z80.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
754k
{
419
754k
  return false;
420
754k
}
coff-z8k.c:bfd_coff_set_long_section_names_disallowed
Line
Count
Source
418
8.88M
{
419
8.88M
  return false;
420
8.88M
}
421
#endif /* defined (COFF_LONG_SECTION_NAMES) */
422
423
/* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
424
   the incoming SEC_* flags.  The inverse of this function is
425
   styp_to_sec_flags().  NOTE: If you add to/change this routine, you
426
   should probably mirror the changes in styp_to_sec_flags().  */
427
428
#ifndef COFF_WITH_PE
429
430
/* Macros for setting debugging flags.  */
431
432
#ifdef STYP_DEBUG
433
0
#define STYP_XCOFF_DEBUG STYP_DEBUG
434
#else
435
0
#define STYP_XCOFF_DEBUG STYP_INFO
436
#endif
437
438
#ifdef COFF_ALIGN_IN_S_FLAGS
439
0
#define STYP_DEBUG_INFO STYP_DSECT
440
#else
441
0
#define STYP_DEBUG_INFO STYP_INFO
442
#endif
443
444
static long
445
sec_to_styp_flags (const char *sec_name, flagword sec_flags)
446
254
{
447
254
  long styp_flags = 0;
448
449
254
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
254
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
254
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
#ifdef _COMMENT
461
    }
462
254
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
#endif /* _COMMENT */
466
#ifdef _LIB
467
    }
468
254
  else if (!strcmp (sec_name, _LIB))
469
0
    {
470
0
      styp_flags = STYP_LIB;
471
#endif /* _LIB */
472
#ifdef _LIT
473
    }
474
  else if (!strcmp (sec_name, _LIT))
475
    {
476
      styp_flags = STYP_LIT;
477
#endif /* _LIT */
478
0
    }
479
254
  else if (startswith (sec_name, DOT_DEBUG)
480
254
     || startswith (sec_name, DOT_ZDEBUG))
481
0
    {
482
      /* Handle the XCOFF debug section and DWARF2 debug sections.  */
483
0
      if (!sec_name[6])
484
0
  styp_flags = STYP_XCOFF_DEBUG;
485
0
      else
486
0
  styp_flags = STYP_DEBUG_INFO;
487
0
    }
488
254
  else if (startswith (sec_name, ".stab"))
489
0
    {
490
0
      styp_flags = STYP_DEBUG_INFO;
491
0
    }
492
#ifdef COFF_LONG_SECTION_NAMES
493
0
  else if (startswith (sec_name, GNU_LINKONCE_WI)
494
0
     || startswith (sec_name, GNU_LINKONCE_WT))
495
0
    {
496
0
      styp_flags = STYP_DEBUG_INFO;
497
0
    }
498
0
#endif
499
#ifdef RS6000COFF_C
500
0
  else if (!strcmp (sec_name, _TDATA))
501
0
    {
502
0
      styp_flags = STYP_TDATA;
503
0
    }
504
0
  else if (!strcmp (sec_name, _TBSS))
505
0
    {
506
0
      styp_flags = STYP_TBSS;
507
0
    }
508
0
  else if (!strcmp (sec_name, _PAD))
509
0
    {
510
0
      styp_flags = STYP_PAD;
511
0
    }
512
0
  else if (!strcmp (sec_name, _LOADER))
513
0
    {
514
0
      styp_flags = STYP_LOADER;
515
0
    }
516
0
  else if (!strcmp (sec_name, _EXCEPT))
517
0
    {
518
0
      styp_flags = STYP_EXCEPT;
519
0
    }
520
0
  else if (!strcmp (sec_name, _TYPCHK))
521
0
    {
522
0
      styp_flags = STYP_TYPCHK;
523
0
    }
524
0
  else if (sec_flags & SEC_DEBUGGING)
525
0
    {
526
0
      int i;
527
528
0
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
529
0
  if (!strcmp (sec_name, xcoff_dwsect_names[i].xcoff_name))
530
0
    {
531
0
      styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
532
0
      break;
533
0
    }
534
0
    }
535
0
#endif
536
  /* Try and figure out what it should be */
537
254
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
254
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
254
  else if (sec_flags & SEC_READONLY)
546
0
    {
547
0
#ifdef STYP_LIT     /* 29k readonly text/data section */
548
0
      styp_flags = STYP_LIT;
549
#else
550
      styp_flags = STYP_TEXT;
551
#endif /* STYP_LIT */
552
0
    }
553
254
  else if (sec_flags & SEC_LOAD)
554
254
    {
555
254
      styp_flags = STYP_TEXT;
556
254
    }
557
0
  else if (sec_flags & SEC_ALLOC)
558
0
    {
559
0
      styp_flags = STYP_BSS;
560
0
    }
561
562
#ifdef STYP_CLINK
563
0
  if (sec_flags & SEC_TIC54X_CLINK)
564
0
    styp_flags |= STYP_CLINK;
565
#endif
566
567
#ifdef STYP_BLOCK
568
0
  if (sec_flags & SEC_TIC54X_BLOCK)
569
0
    styp_flags |= STYP_BLOCK;
570
#endif
571
572
254
#ifdef STYP_NOLOAD
573
254
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
254
#endif
576
577
254
  return styp_flags;
578
254
}
Unexecuted instantiation: coff-x86_64.c:sec_to_styp_flags
Unexecuted instantiation: coff64-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: cf-i386lynx.c:sec_to_styp_flags
Unexecuted instantiation: coff-go32.c:sec_to_styp_flags
Unexecuted instantiation: coff-i386.c:sec_to_styp_flags
Unexecuted instantiation: coff-rs6000.c:sec_to_styp_flags
Unexecuted instantiation: coff-sh.c:sec_to_styp_flags
Unexecuted instantiation: coff-stgo32.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic30.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic4x.c:sec_to_styp_flags
Unexecuted instantiation: coff-tic54x.c:sec_to_styp_flags
Unexecuted instantiation: coff-z80.c:sec_to_styp_flags
coff-z8k.c:sec_to_styp_flags
Line
Count
Source
446
254
{
447
254
  long styp_flags = 0;
448
449
254
  if (!strcmp (sec_name, _TEXT))
450
0
    {
451
0
      styp_flags = STYP_TEXT;
452
0
    }
453
254
  else if (!strcmp (sec_name, _DATA))
454
0
    {
455
0
      styp_flags = STYP_DATA;
456
0
    }
457
254
  else if (!strcmp (sec_name, _BSS))
458
0
    {
459
0
      styp_flags = STYP_BSS;
460
0
#ifdef _COMMENT
461
0
    }
462
254
  else if (!strcmp (sec_name, _COMMENT))
463
0
    {
464
0
      styp_flags = STYP_INFO;
465
0
#endif /* _COMMENT */
466
0
#ifdef _LIB
467
0
    }
468
254
  else if (!strcmp (sec_name, _LIB))
469
0
    {
470
0
      styp_flags = STYP_LIB;
471
0
#endif /* _LIB */
472
#ifdef _LIT
473
    }
474
  else if (!strcmp (sec_name, _LIT))
475
    {
476
      styp_flags = STYP_LIT;
477
#endif /* _LIT */
478
0
    }
479
254
  else if (startswith (sec_name, DOT_DEBUG)
480
254
     || startswith (sec_name, DOT_ZDEBUG))
481
0
    {
482
      /* Handle the XCOFF debug section and DWARF2 debug sections.  */
483
0
      if (!sec_name[6])
484
0
  styp_flags = STYP_XCOFF_DEBUG;
485
0
      else
486
0
  styp_flags = STYP_DEBUG_INFO;
487
0
    }
488
254
  else if (startswith (sec_name, ".stab"))
489
0
    {
490
0
      styp_flags = STYP_DEBUG_INFO;
491
0
    }
492
#ifdef COFF_LONG_SECTION_NAMES
493
  else if (startswith (sec_name, GNU_LINKONCE_WI)
494
     || startswith (sec_name, GNU_LINKONCE_WT))
495
    {
496
      styp_flags = STYP_DEBUG_INFO;
497
    }
498
#endif
499
#ifdef RS6000COFF_C
500
  else if (!strcmp (sec_name, _TDATA))
501
    {
502
      styp_flags = STYP_TDATA;
503
    }
504
  else if (!strcmp (sec_name, _TBSS))
505
    {
506
      styp_flags = STYP_TBSS;
507
    }
508
  else if (!strcmp (sec_name, _PAD))
509
    {
510
      styp_flags = STYP_PAD;
511
    }
512
  else if (!strcmp (sec_name, _LOADER))
513
    {
514
      styp_flags = STYP_LOADER;
515
    }
516
  else if (!strcmp (sec_name, _EXCEPT))
517
    {
518
      styp_flags = STYP_EXCEPT;
519
    }
520
  else if (!strcmp (sec_name, _TYPCHK))
521
    {
522
      styp_flags = STYP_TYPCHK;
523
    }
524
  else if (sec_flags & SEC_DEBUGGING)
525
    {
526
      int i;
527
528
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
529
  if (!strcmp (sec_name, xcoff_dwsect_names[i].xcoff_name))
530
    {
531
      styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
532
      break;
533
    }
534
    }
535
#endif
536
  /* Try and figure out what it should be */
537
254
  else if (sec_flags & SEC_CODE)
538
0
    {
539
0
      styp_flags = STYP_TEXT;
540
0
    }
541
254
  else if (sec_flags & SEC_DATA)
542
0
    {
543
0
      styp_flags = STYP_DATA;
544
0
    }
545
254
  else if (sec_flags & SEC_READONLY)
546
0
    {
547
0
#ifdef STYP_LIT     /* 29k readonly text/data section */
548
0
      styp_flags = STYP_LIT;
549
#else
550
      styp_flags = STYP_TEXT;
551
#endif /* STYP_LIT */
552
0
    }
553
254
  else if (sec_flags & SEC_LOAD)
554
254
    {
555
254
      styp_flags = STYP_TEXT;
556
254
    }
557
0
  else if (sec_flags & SEC_ALLOC)
558
0
    {
559
0
      styp_flags = STYP_BSS;
560
0
    }
561
562
#ifdef STYP_CLINK
563
  if (sec_flags & SEC_TIC54X_CLINK)
564
    styp_flags |= STYP_CLINK;
565
#endif
566
567
#ifdef STYP_BLOCK
568
  if (sec_flags & SEC_TIC54X_BLOCK)
569
    styp_flags |= STYP_BLOCK;
570
#endif
571
572
254
#ifdef STYP_NOLOAD
573
254
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
574
0
    styp_flags |= STYP_NOLOAD;
575
254
#endif
576
577
254
  return styp_flags;
578
254
}
579
580
#else /* COFF_WITH_PE */
581
582
/* The PE version; see above for the general comments.  The non-PE
583
   case seems to be more guessing, and breaks PE format; specifically,
584
   .rdata is readonly, but it sure ain't text.  Really, all this
585
   should be set up properly in gas (or whatever assembler is in use),
586
   and honor whatever objcopy/strip, etc. sent us as input.  */
587
588
static long
589
sec_to_styp_flags (const char *sec_name, flagword sec_flags)
590
601
{
591
601
  long styp_flags = 0;
592
601
  bool is_dbg = false;
593
594
601
  if (startswith (sec_name, DOT_DEBUG)
595
601
      || startswith (sec_name, DOT_ZDEBUG)
596
601
#ifdef COFF_LONG_SECTION_NAMES
597
601
      || startswith (sec_name, GNU_LINKONCE_WI)
598
601
      || startswith (sec_name, GNU_LINKONCE_WT)
599
601
#endif
600
601
      || startswith (sec_name, ".stab"))
601
40
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
601
  if (is_dbg)
613
40
    {
614
40
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
40
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
40
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
40
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
40
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
601
  if ((sec_flags & SEC_CODE) != 0)
624
5
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
601
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
92
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
601
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
4
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
507
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
601
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
42
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
601
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
507
  if (sec_flags & SEC_LINK_ONCE)
651
1
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
507
  if ((sec_flags
653
507
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
507
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
601
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
96
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
601
  if ((sec_flags & SEC_READONLY) == 0)
663
17
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
601
  if (sec_flags & SEC_CODE)
665
5
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
601
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
601
  return styp_flags;
670
601
}
pei-i386.c:sec_to_styp_flags
Line
Count
Source
590
13
{
591
13
  long styp_flags = 0;
592
13
  bool is_dbg = false;
593
594
13
  if (startswith (sec_name, DOT_DEBUG)
595
13
      || startswith (sec_name, DOT_ZDEBUG)
596
13
#ifdef COFF_LONG_SECTION_NAMES
597
13
      || startswith (sec_name, GNU_LINKONCE_WI)
598
13
      || startswith (sec_name, GNU_LINKONCE_WT)
599
13
#endif
600
13
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
13
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
13
  if ((sec_flags & SEC_CODE) != 0)
624
2
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
13
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
11
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
13
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
1
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
13
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
1
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
13
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
13
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
13
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
13
  if ((sec_flags & SEC_READONLY) == 0)
663
5
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
13
  if (sec_flags & SEC_CODE)
665
2
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
13
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
13
  return styp_flags;
670
13
}
Unexecuted instantiation: pe-x86_64.c:sec_to_styp_flags
pei-x86_64.c:sec_to_styp_flags
Line
Count
Source
590
75
{
591
75
  long styp_flags = 0;
592
75
  bool is_dbg = false;
593
594
75
  if (startswith (sec_name, DOT_DEBUG)
595
75
      || startswith (sec_name, DOT_ZDEBUG)
596
75
#ifdef COFF_LONG_SECTION_NAMES
597
75
      || startswith (sec_name, GNU_LINKONCE_WI)
598
75
      || startswith (sec_name, GNU_LINKONCE_WT)
599
75
#endif
600
75
      || startswith (sec_name, ".stab"))
601
32
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
75
  if (is_dbg)
613
32
    {
614
32
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
32
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
32
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
32
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
32
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
75
  if ((sec_flags & SEC_CODE) != 0)
624
3
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
75
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
72
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
75
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
3
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
75
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
32
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
75
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
75
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
75
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
75
  if ((sec_flags & SEC_READONLY) == 0)
663
12
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
75
  if (sec_flags & SEC_CODE)
665
3
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
75
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
75
  return styp_flags;
670
75
}
pe-aarch64.c:sec_to_styp_flags
Line
Count
Source
590
1
{
591
1
  long styp_flags = 0;
592
1
  bool is_dbg = false;
593
594
1
  if (startswith (sec_name, DOT_DEBUG)
595
1
      || startswith (sec_name, DOT_ZDEBUG)
596
1
#ifdef COFF_LONG_SECTION_NAMES
597
1
      || startswith (sec_name, GNU_LINKONCE_WI)
598
1
      || startswith (sec_name, GNU_LINKONCE_WT)
599
1
#endif
600
1
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
1
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
1
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
1
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
1
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
1
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
1
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
1
#endif
639
1
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
1
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
1
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
1
#ifndef COFF_IMAGE_WITH_PE
650
1
  if (sec_flags & SEC_LINK_ONCE)
651
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
1
  if ((sec_flags
653
1
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
1
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
1
#endif
657
658
  /* skip LINKER_CREATED */
659
660
1
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
1
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
1
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
1
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
1
  return styp_flags;
670
1
}
pei-aarch64.c:sec_to_styp_flags
Line
Count
Source
590
4
{
591
4
  long styp_flags = 0;
592
4
  bool is_dbg = false;
593
594
4
  if (startswith (sec_name, DOT_DEBUG)
595
4
      || startswith (sec_name, DOT_ZDEBUG)
596
4
#ifdef COFF_LONG_SECTION_NAMES
597
4
      || startswith (sec_name, GNU_LINKONCE_WI)
598
4
      || startswith (sec_name, GNU_LINKONCE_WT)
599
4
#endif
600
4
      || startswith (sec_name, ".stab"))
601
4
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
4
  if (is_dbg)
613
4
    {
614
4
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
4
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
4
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
4
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
4
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
4
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
4
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
4
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
4
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
4
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
4
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
4
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
4
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
4
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
4
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
4
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
4
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
4
  return styp_flags;
670
4
}
Unexecuted instantiation: pei-ia64.c:sec_to_styp_flags
Unexecuted instantiation: pei-loongarch64.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm-wince.c:sec_to_styp_flags
Unexecuted instantiation: pe-arm.c:sec_to_styp_flags
pe-i386.c:sec_to_styp_flags
Line
Count
Source
590
499
{
591
499
  long styp_flags = 0;
592
499
  bool is_dbg = false;
593
594
499
  if (startswith (sec_name, DOT_DEBUG)
595
499
      || startswith (sec_name, DOT_ZDEBUG)
596
499
#ifdef COFF_LONG_SECTION_NAMES
597
499
      || startswith (sec_name, GNU_LINKONCE_WI)
598
499
      || startswith (sec_name, GNU_LINKONCE_WT)
599
499
#endif
600
499
      || startswith (sec_name, ".stab"))
601
2
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
499
  if (is_dbg)
613
2
    {
614
2
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
2
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
2
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
2
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
2
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
499
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
499
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
3
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
499
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
499
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
499
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
499
#endif
639
499
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
3
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
499
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
499
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
499
#ifndef COFF_IMAGE_WITH_PE
650
499
  if (sec_flags & SEC_LINK_ONCE)
651
1
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
499
  if ((sec_flags
653
499
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
499
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
499
#endif
657
658
  /* skip LINKER_CREATED */
659
660
499
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
499
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
499
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
499
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
499
  return styp_flags;
670
499
}
pe-mcore.c:sec_to_styp_flags
Line
Count
Source
590
7
{
591
7
  long styp_flags = 0;
592
7
  bool is_dbg = false;
593
594
7
  if (startswith (sec_name, DOT_DEBUG)
595
7
      || startswith (sec_name, DOT_ZDEBUG)
596
7
#ifdef COFF_LONG_SECTION_NAMES
597
7
      || startswith (sec_name, GNU_LINKONCE_WI)
598
7
      || startswith (sec_name, GNU_LINKONCE_WT)
599
7
#endif
600
7
      || startswith (sec_name, ".stab"))
601
0
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
7
  if (is_dbg)
613
0
    {
614
0
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
0
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
0
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
0
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
0
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
7
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
7
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
0
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
7
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
7
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
7
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
7
#endif
639
7
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
7
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
#ifdef COFF_IMAGE_WITH_PE
643
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
0
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
7
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
7
#ifndef COFF_IMAGE_WITH_PE
650
7
  if (sec_flags & SEC_LINK_ONCE)
651
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
7
  if ((sec_flags
653
7
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
7
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
0
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
7
#endif
657
658
  /* skip LINKER_CREATED */
659
660
7
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
0
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
7
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
7
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
7
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
7
  return styp_flags;
670
7
}
Unexecuted instantiation: pe-sh.c:sec_to_styp_flags
pei-arm-wince.c:sec_to_styp_flags
Line
Count
Source
590
2
{
591
2
  long styp_flags = 0;
592
2
  bool is_dbg = false;
593
594
2
  if (startswith (sec_name, DOT_DEBUG)
595
2
      || startswith (sec_name, DOT_ZDEBUG)
596
2
#ifdef COFF_LONG_SECTION_NAMES
597
2
      || startswith (sec_name, GNU_LINKONCE_WI)
598
2
      || startswith (sec_name, GNU_LINKONCE_WT)
599
2
#endif
600
2
      || startswith (sec_name, ".stab"))
601
2
    is_dbg = true;
602
603
  /* caution: there are at least three groups of symbols that have
604
     very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
605
     SEC_* are the BFD internal flags, used for generic BFD
606
     information.  STYP_* are the COFF section flags which appear in
607
     COFF files.  IMAGE_SCN_* are the PE section flags which appear in
608
     PE files.  The STYP_* flags and the IMAGE_SCN_* flags overlap,
609
     but there are more IMAGE_SCN_* flags.  */
610
611
  /* FIXME: There is no gas syntax to specify the debug section flag.  */
612
2
  if (is_dbg)
613
2
    {
614
2
      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
615
2
        | SEC_LINK_DUPLICATES_SAME_CONTENTS
616
2
        | SEC_LINK_DUPLICATES_SAME_SIZE);
617
2
      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
618
2
    }
619
620
  /* skip LOAD */
621
  /* READONLY later */
622
  /* skip RELOC */
623
2
  if ((sec_flags & SEC_CODE) != 0)
624
0
    styp_flags |= IMAGE_SCN_CNT_CODE;
625
2
  if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
626
2
    styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
627
2
  if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
628
0
    styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;  /* ==STYP_BSS */
629
  /* skip ROM */
630
  /* skip constRUCTOR */
631
  /* skip CONTENTS */
632
#ifndef COFF_IMAGE_WITH_PE
633
  /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set
634
     when the output is PE. Only object files should have them, for the linker
635
     to consume.  */
636
  if ((sec_flags & SEC_IS_COMMON) != 0)
637
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
638
#endif
639
2
  if ((sec_flags & SEC_DEBUGGING) != 0)
640
2
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
641
2
  if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg)
642
0
#ifdef COFF_IMAGE_WITH_PE
643
0
    styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
644
#else
645
    styp_flags |= IMAGE_SCN_LNK_REMOVE;
646
#endif
647
  /* skip IN_MEMORY */
648
  /* skip SORT */
649
#ifndef COFF_IMAGE_WITH_PE
650
  if (sec_flags & SEC_LINK_ONCE)
651
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
652
  if ((sec_flags
653
       & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
654
    | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
655
    styp_flags |= IMAGE_SCN_LNK_COMDAT;
656
#endif
657
658
  /* skip LINKER_CREATED */
659
660
2
  if ((sec_flags & SEC_COFF_NOREAD) == 0)
661
2
    styp_flags |= IMAGE_SCN_MEM_READ;     /* Invert NOREAD for read.  */
662
2
  if ((sec_flags & SEC_READONLY) == 0)
663
0
    styp_flags |= IMAGE_SCN_MEM_WRITE;    /* Invert READONLY for write.  */
664
2
  if (sec_flags & SEC_CODE)
665
0
    styp_flags |= IMAGE_SCN_MEM_EXECUTE;  /* CODE->EXECUTE.  */
666
2
  if (sec_flags & SEC_COFF_SHARED)
667
0
    styp_flags |= IMAGE_SCN_MEM_SHARED;   /* Shared remains meaningful.  */
668
669
2
  return styp_flags;
670
2
}
Unexecuted instantiation: pei-arm.c:sec_to_styp_flags
Unexecuted instantiation: pei-mcore.c:sec_to_styp_flags
Unexecuted instantiation: pei-sh.c:sec_to_styp_flags
671
672
#endif /* COFF_WITH_PE */
673
674
/* Return a word with SEC_* flags set to represent the incoming STYP_*
675
   flags (from scnhdr.s_flags).  The inverse of this function is
676
   sec_to_styp_flags().  NOTE: If you add to/change this routine, you
677
   should probably mirror the changes in sec_to_styp_flags().  */
678
679
#ifndef COFF_WITH_PE
680
681
static bool
682
styp_to_sec_flags (bfd *abfd,
683
       void * hdr,
684
       const char *name,
685
       asection *section ATTRIBUTE_UNUSED,
686
       flagword *flags_ptr)
687
92.6M
{
688
92.6M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
92.6M
  unsigned long styp_flags = internal_s->s_flags;
690
92.6M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
8.33M
  if (styp_flags & STYP_BLOCK)
694
2.62M
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
8.33M
  if (styp_flags & STYP_CLINK)
699
2.54M
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
92.6M
#ifdef STYP_NOLOAD
703
92.6M
  if (styp_flags & STYP_NOLOAD)
704
29.9M
    sec_flags |= SEC_NEVER_LOAD;
705
92.6M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
92.6M
  if (styp_flags & STYP_TEXT)
710
36.8M
    {
711
36.8M
      if (sec_flags & SEC_NEVER_LOAD)
712
20.3M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
16.4M
      else
714
16.4M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
36.8M
    }
716
55.8M
  else if (styp_flags & STYP_DATA)
717
8.12M
    {
718
8.12M
      if (sec_flags & SEC_NEVER_LOAD)
719
4.54M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
3.58M
      else
721
3.58M
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
8.12M
    }
723
47.7M
  else if (styp_flags & STYP_BSS)
724
3.18M
    {
725
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
968k
      if (sec_flags & SEC_NEVER_LOAD)
727
368k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
599k
      else
729
599k
#endif
730
2.81M
  sec_flags |= SEC_ALLOC;
731
3.18M
    }
732
44.5M
  else if (styp_flags & STYP_INFO)
733
6.00M
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
1.75M
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
6.00M
    }
744
38.5M
  else if (styp_flags & STYP_PAD)
745
2.09M
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
11.7M
  else if (styp_flags & STYP_TDATA)
748
718k
    {
749
718k
      if (sec_flags & SEC_NEVER_LOAD)
750
62.5k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
655k
      else
752
655k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
718k
    }
754
11.0M
  else if (styp_flags & STYP_TBSS)
755
295k
    {
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
295k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
295k
    }
763
10.7M
  else if (styp_flags & STYP_EXCEPT)
764
475k
    sec_flags |= SEC_LOAD;
765
10.2M
  else if (styp_flags & STYP_LOADER)
766
135k
    sec_flags |= SEC_LOAD;
767
10.1M
  else if (styp_flags & STYP_TYPCHK)
768
74.9k
    sec_flags |= SEC_LOAD;
769
10.0M
  else if (styp_flags & STYP_DWARF)
770
128k
    sec_flags |= SEC_DEBUGGING;
771
9.92M
#endif
772
34.6M
  else if (strcmp (name, _TEXT) == 0)
773
75.2k
    {
774
75.2k
      if (sec_flags & SEC_NEVER_LOAD)
775
21.2k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
53.9k
      else
777
53.9k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
75.2k
    }
779
34.5M
  else if (strcmp (name, _DATA) == 0)
780
125k
    {
781
125k
      if (sec_flags & SEC_NEVER_LOAD)
782
17.0k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
108k
      else
784
108k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
125k
    }
786
34.4M
  else if (strcmp (name, _BSS) == 0)
787
45.8k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
16.5k
      if (sec_flags & SEC_NEVER_LOAD)
790
5.77k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
10.7k
      else
792
10.7k
#endif
793
40.0k
  sec_flags |= SEC_ALLOC;
794
45.8k
    }
795
34.3M
  else if (startswith (name, DOT_DEBUG)
796
34.3M
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
21.0M
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
1.98M
     || startswith (name, GNU_LINKONCE_WI)
802
1.98M
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
34.3M
     || startswith (name, ".stab"))
805
224k
    {
806
#ifdef COFF_PAGE_SIZE
807
88.1k
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
224k
    }
810
#ifdef _LIB
811
20.9M
  else if (strcmp (name, _LIB) == 0)
812
14.1k
    ;
813
20.9M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
20.9M
  else
819
34.1M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
92.6M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
92.6M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
10.9M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
92.6M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
92.6M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
92.6M
      && (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
5.32M
  if (startswith (name, ".gnu.linkonce"))
844
413
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
92.6M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
92.6M
  * flags_ptr = sec_flags;
851
92.6M
  return true;
852
92.6M
}
coff-x86_64.c:styp_to_sec_flags
Line
Count
Source
687
9.32M
{
688
9.32M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
9.32M
  unsigned long styp_flags = internal_s->s_flags;
690
9.32M
  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.32M
#ifdef STYP_NOLOAD
703
9.32M
  if (styp_flags & STYP_NOLOAD)
704
2.77M
    sec_flags |= SEC_NEVER_LOAD;
705
9.32M
#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.32M
  if (styp_flags & STYP_TEXT)
710
3.60M
    {
711
3.60M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.91M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.68M
      else
714
1.68M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.60M
    }
716
5.71M
  else if (styp_flags & STYP_DATA)
717
702k
    {
718
702k
      if (sec_flags & SEC_NEVER_LOAD)
719
381k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
321k
      else
721
321k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
702k
    }
723
5.01M
  else if (styp_flags & STYP_BSS)
724
354k
    {
725
354k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
354k
      if (sec_flags & SEC_NEVER_LOAD)
727
111k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
242k
      else
729
242k
#endif
730
242k
  sec_flags |= SEC_ALLOC;
731
354k
    }
732
4.66M
  else if (styp_flags & STYP_INFO)
733
578k
    {
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
578k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
578k
      sec_flags |= SEC_DEBUGGING;
742
578k
#endif
743
578k
    }
744
4.08M
  else if (styp_flags & STYP_PAD)
745
207k
    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.87M
  else if (strcmp (name, _TEXT) == 0)
773
10.6k
    {
774
10.6k
      if (sec_flags & SEC_NEVER_LOAD)
775
3.93k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
6.69k
      else
777
6.69k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
10.6k
    }
779
3.86M
  else if (strcmp (name, _DATA) == 0)
780
13.9k
    {
781
13.9k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.63k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
11.2k
      else
784
11.2k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
13.9k
    }
786
3.84M
  else if (strcmp (name, _BSS) == 0)
787
7.40k
    {
788
7.40k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
7.40k
      if (sec_flags & SEC_NEVER_LOAD)
790
3.11k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
4.29k
      else
792
4.29k
#endif
793
4.29k
  sec_flags |= SEC_ALLOC;
794
7.40k
    }
795
3.84M
  else if (startswith (name, DOT_DEBUG)
796
3.84M
     || startswith (name, DOT_ZDEBUG)
797
3.84M
#ifdef _COMMENT
798
3.84M
     || strcmp (name, _COMMENT) == 0
799
3.84M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.84M
     || startswith (name, ".stab"))
805
37.1k
    {
806
37.1k
#ifdef COFF_PAGE_SIZE
807
37.1k
      sec_flags |= SEC_DEBUGGING;
808
37.1k
#endif
809
37.1k
    }
810
3.80M
#ifdef _LIB
811
3.80M
  else if (strcmp (name, _LIB) == 0)
812
2.78k
    ;
813
3.80M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.80M
  else
819
3.80M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
9.32M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
9.32M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
930k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
9.32M
#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.32M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
9.32M
      && (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.32M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
9.32M
  * flags_ptr = sec_flags;
851
9.32M
  return true;
852
9.32M
}
coff64-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
4.62M
{
688
4.62M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
4.62M
  unsigned long styp_flags = internal_s->s_flags;
690
4.62M
  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.62M
#ifdef STYP_NOLOAD
703
4.62M
  if (styp_flags & STYP_NOLOAD)
704
1.61M
    sec_flags |= SEC_NEVER_LOAD;
705
4.62M
#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.62M
  if (styp_flags & STYP_TEXT)
710
1.92M
    {
711
1.92M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.12M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
803k
      else
714
803k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.92M
    }
716
2.70M
  else if (styp_flags & STYP_DATA)
717
412k
    {
718
412k
      if (sec_flags & SEC_NEVER_LOAD)
719
236k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
176k
      else
721
176k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
412k
    }
723
2.28M
  else if (styp_flags & STYP_BSS)
724
142k
    {
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
142k
  sec_flags |= SEC_ALLOC;
731
142k
    }
732
2.14M
  else if (styp_flags & STYP_INFO)
733
300k
    {
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
300k
    }
744
1.84M
  else if (styp_flags & STYP_PAD)
745
105k
    sec_flags = 0;
746
1.73M
#ifdef RS6000COFF_C
747
1.73M
  else if (styp_flags & STYP_TDATA)
748
113k
    {
749
113k
      if (sec_flags & SEC_NEVER_LOAD)
750
9.72k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
103k
      else
752
103k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
113k
    }
754
1.62M
  else if (styp_flags & STYP_TBSS)
755
46.1k
    {
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
46.1k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
46.1k
    }
763
1.57M
  else if (styp_flags & STYP_EXCEPT)
764
85.2k
    sec_flags |= SEC_LOAD;
765
1.49M
  else if (styp_flags & STYP_LOADER)
766
33.3k
    sec_flags |= SEC_LOAD;
767
1.46M
  else if (styp_flags & STYP_TYPCHK)
768
12.8k
    sec_flags |= SEC_LOAD;
769
1.44M
  else if (styp_flags & STYP_DWARF)
770
21.4k
    sec_flags |= SEC_DEBUGGING;
771
1.42M
#endif
772
1.42M
  else if (strcmp (name, _TEXT) == 0)
773
4.38k
    {
774
4.38k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.08k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
3.30k
      else
777
3.30k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.38k
    }
779
1.42M
  else if (strcmp (name, _DATA) == 0)
780
3.88k
    {
781
3.88k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.13k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
2.74k
      else
784
2.74k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
3.88k
    }
786
1.41M
  else if (strcmp (name, _BSS) == 0)
787
1.71k
    {
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
1.71k
  sec_flags |= SEC_ALLOC;
794
1.71k
    }
795
1.41M
  else if (startswith (name, DOT_DEBUG)
796
1.41M
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
1.41M
     || startswith (name, ".stab"))
805
7.80k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
7.80k
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.40M
  else
819
1.40M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
4.62M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
4.62M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
500k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
4.62M
#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.62M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
4.62M
      && (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.62M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
4.62M
  * flags_ptr = sec_flags;
851
4.62M
  return true;
852
4.62M
}
cf-i386lynx.c:styp_to_sec_flags
Line
Count
Source
687
6.05M
{
688
6.05M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
6.05M
  unsigned long styp_flags = internal_s->s_flags;
690
6.05M
  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.05M
#ifdef STYP_NOLOAD
703
6.05M
  if (styp_flags & STYP_NOLOAD)
704
2.05M
    sec_flags |= SEC_NEVER_LOAD;
705
6.05M
#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.05M
  if (styp_flags & STYP_TEXT)
710
2.34M
    {
711
2.34M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.34M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.00M
      else
714
1.00M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.34M
    }
716
3.70M
  else if (styp_flags & STYP_DATA)
717
643k
    {
718
643k
      if (sec_flags & SEC_NEVER_LOAD)
719
356k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
286k
      else
721
286k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
643k
    }
723
3.06M
  else if (styp_flags & STYP_BSS)
724
219k
    {
725
219k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
219k
      if (sec_flags & SEC_NEVER_LOAD)
727
91.7k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
127k
      else
729
127k
#endif
730
127k
  sec_flags |= SEC_ALLOC;
731
219k
    }
732
2.84M
  else if (styp_flags & STYP_INFO)
733
414k
    {
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
414k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
414k
      sec_flags |= SEC_DEBUGGING;
742
414k
#endif
743
414k
    }
744
2.43M
  else if (styp_flags & STYP_PAD)
745
131k
    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.30M
  else if (strcmp (name, _TEXT) == 0)
773
4.72k
    {
774
4.72k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.75k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.96k
      else
777
2.96k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.72k
    }
779
2.29M
  else if (strcmp (name, _DATA) == 0)
780
5.90k
    {
781
5.90k
      if (sec_flags & SEC_NEVER_LOAD)
782
974
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.93k
      else
784
4.93k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
5.90k
    }
786
2.29M
  else if (strcmp (name, _BSS) == 0)
787
3.21k
    {
788
3.21k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3.21k
      if (sec_flags & SEC_NEVER_LOAD)
790
931
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2.28k
      else
792
2.28k
#endif
793
2.28k
  sec_flags |= SEC_ALLOC;
794
3.21k
    }
795
2.28M
  else if (startswith (name, DOT_DEBUG)
796
2.28M
     || startswith (name, DOT_ZDEBUG)
797
2.28M
#ifdef _COMMENT
798
2.28M
     || strcmp (name, _COMMENT) == 0
799
2.28M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.28M
     || startswith (name, ".stab"))
805
18.2k
    {
806
18.2k
#ifdef COFF_PAGE_SIZE
807
18.2k
      sec_flags |= SEC_DEBUGGING;
808
18.2k
#endif
809
18.2k
    }
810
2.26M
#ifdef _LIB
811
2.26M
  else if (strcmp (name, _LIB) == 0)
812
1.48k
    ;
813
2.26M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.26M
  else
819
2.26M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
6.05M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
6.05M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
795k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
6.05M
#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.05M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
6.05M
      && (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.05M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
6.05M
  * flags_ptr = sec_flags;
851
6.05M
  return true;
852
6.05M
}
coff-go32.c:styp_to_sec_flags
Line
Count
Source
687
4.96M
{
688
4.96M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
4.96M
  unsigned long styp_flags = internal_s->s_flags;
690
4.96M
  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.96M
#ifdef STYP_NOLOAD
703
4.96M
  if (styp_flags & STYP_NOLOAD)
704
1.69M
    sec_flags |= SEC_NEVER_LOAD;
705
4.96M
#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.96M
  if (styp_flags & STYP_TEXT)
710
1.95M
    {
711
1.95M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.11M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
834k
      else
714
834k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
1.95M
    }
716
3.01M
  else if (styp_flags & STYP_DATA)
717
527k
    {
718
527k
      if (sec_flags & SEC_NEVER_LOAD)
719
293k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
234k
      else
721
234k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
527k
    }
723
2.48M
  else if (styp_flags & STYP_BSS)
724
174k
    {
725
174k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
174k
      if (sec_flags & SEC_NEVER_LOAD)
727
73.1k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
101k
      else
729
101k
#endif
730
101k
  sec_flags |= SEC_ALLOC;
731
174k
    }
732
2.30M
  else if (styp_flags & STYP_INFO)
733
339k
    {
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
339k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
339k
      sec_flags |= SEC_DEBUGGING;
742
339k
#endif
743
339k
    }
744
1.97M
  else if (styp_flags & STYP_PAD)
745
107k
    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.86M
  else if (strcmp (name, _TEXT) == 0)
773
4.15k
    {
774
4.15k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.58k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.57k
      else
777
2.57k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.15k
    }
779
1.85M
  else if (strcmp (name, _DATA) == 0)
780
5.22k
    {
781
5.22k
      if (sec_flags & SEC_NEVER_LOAD)
782
824
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.40k
      else
784
4.40k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
5.22k
    }
786
1.85M
  else if (strcmp (name, _BSS) == 0)
787
2.71k
    {
788
2.71k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
2.71k
      if (sec_flags & SEC_NEVER_LOAD)
790
801
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
1.90k
      else
792
1.90k
#endif
793
1.90k
  sec_flags |= SEC_ALLOC;
794
2.71k
    }
795
1.85M
  else if (startswith (name, DOT_DEBUG)
796
1.85M
     || startswith (name, DOT_ZDEBUG)
797
1.85M
#ifdef _COMMENT
798
1.85M
     || strcmp (name, _COMMENT) == 0
799
1.85M
#endif
800
1.85M
#ifdef COFF_LONG_SECTION_NAMES
801
1.85M
     || startswith (name, GNU_LINKONCE_WI)
802
1.85M
     || startswith (name, GNU_LINKONCE_WT)
803
1.85M
#endif
804
1.85M
     || startswith (name, ".stab"))
805
14.3k
    {
806
14.3k
#ifdef COFF_PAGE_SIZE
807
14.3k
      sec_flags |= SEC_DEBUGGING;
808
14.3k
#endif
809
14.3k
    }
810
1.83M
#ifdef _LIB
811
1.83M
  else if (strcmp (name, _LIB) == 0)
812
1.25k
    ;
813
1.83M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
1.83M
  else
819
1.83M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
4.96M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
4.96M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
648k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
4.96M
#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.96M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
4.96M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
4.96M
#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
4.96M
  if (startswith (name, ".gnu.linkonce"))
844
309
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
4.96M
#endif
846
847
4.96M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
4.96M
  * flags_ptr = sec_flags;
851
4.96M
  return true;
852
4.96M
}
coff-i386.c:styp_to_sec_flags
Line
Count
Source
687
5.72M
{
688
5.72M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
5.72M
  unsigned long styp_flags = internal_s->s_flags;
690
5.72M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
5.72M
#ifdef STYP_NOLOAD
703
5.72M
  if (styp_flags & STYP_NOLOAD)
704
1.94M
    sec_flags |= SEC_NEVER_LOAD;
705
5.72M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
5.72M
  if (styp_flags & STYP_TEXT)
710
2.23M
    {
711
2.23M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.28M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
953k
      else
714
953k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.23M
    }
716
3.49M
  else if (styp_flags & STYP_DATA)
717
609k
    {
718
609k
      if (sec_flags & SEC_NEVER_LOAD)
719
340k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
269k
      else
721
269k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
609k
    }
723
2.88M
  else if (styp_flags & STYP_BSS)
724
199k
    {
725
199k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
199k
      if (sec_flags & SEC_NEVER_LOAD)
727
83.5k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
115k
      else
729
115k
#endif
730
115k
  sec_flags |= SEC_ALLOC;
731
199k
    }
732
2.68M
  else if (styp_flags & STYP_INFO)
733
387k
    {
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
387k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
387k
      sec_flags |= SEC_DEBUGGING;
742
387k
#endif
743
387k
    }
744
2.29M
  else if (styp_flags & STYP_PAD)
745
122k
    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.17M
  else if (strcmp (name, _TEXT) == 0)
773
4.44k
    {
774
4.44k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.70k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.74k
      else
777
2.74k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
4.44k
    }
779
2.16M
  else if (strcmp (name, _DATA) == 0)
780
5.74k
    {
781
5.74k
      if (sec_flags & SEC_NEVER_LOAD)
782
944
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
4.80k
      else
784
4.80k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
5.74k
    }
786
2.16M
  else if (strcmp (name, _BSS) == 0)
787
3.06k
    {
788
3.06k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
3.06k
      if (sec_flags & SEC_NEVER_LOAD)
790
905
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
2.16k
      else
792
2.16k
#endif
793
2.16k
  sec_flags |= SEC_ALLOC;
794
3.06k
    }
795
2.15M
  else if (startswith (name, DOT_DEBUG)
796
2.15M
     || startswith (name, DOT_ZDEBUG)
797
2.15M
#ifdef _COMMENT
798
2.15M
     || strcmp (name, _COMMENT) == 0
799
2.15M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.15M
     || startswith (name, ".stab"))
805
14.9k
    {
806
14.9k
#ifdef COFF_PAGE_SIZE
807
14.9k
      sec_flags |= SEC_DEBUGGING;
808
14.9k
#endif
809
14.9k
    }
810
2.14M
#ifdef _LIB
811
2.14M
  else if (strcmp (name, _LIB) == 0)
812
1.37k
    ;
813
2.14M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.14M
  else
819
2.14M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
5.72M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
5.72M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
749k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
5.72M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
5.72M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
5.72M
      && (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
5.72M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
5.72M
  * flags_ptr = sec_flags;
851
5.72M
  return true;
852
5.72M
}
coff-rs6000.c:styp_to_sec_flags
Line
Count
Source
687
25.5M
{
688
25.5M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
25.5M
  unsigned long styp_flags = internal_s->s_flags;
690
25.5M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
25.5M
#ifdef STYP_NOLOAD
703
25.5M
  if (styp_flags & STYP_NOLOAD)
704
8.24M
    sec_flags |= SEC_NEVER_LOAD;
705
25.5M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
25.5M
  if (styp_flags & STYP_TEXT)
710
10.1M
    {
711
10.1M
      if (sec_flags & SEC_NEVER_LOAD)
712
5.59M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
4.56M
      else
714
4.56M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
10.1M
    }
716
15.3M
  else if (styp_flags & STYP_DATA)
717
2.29M
    {
718
2.29M
      if (sec_flags & SEC_NEVER_LOAD)
719
1.30M
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
991k
      else
721
991k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
2.29M
    }
723
13.0M
  else if (styp_flags & STYP_BSS)
724
942k
    {
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
942k
  sec_flags |= SEC_ALLOC;
731
942k
    }
732
12.1M
  else if (styp_flags & STYP_INFO)
733
1.55M
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
1.55M
    }
744
10.5M
  else if (styp_flags & STYP_PAD)
745
578k
    sec_flags = 0;
746
10.0M
#ifdef RS6000COFF_C
747
10.0M
  else if (styp_flags & STYP_TDATA)
748
604k
    {
749
604k
      if (sec_flags & SEC_NEVER_LOAD)
750
52.8k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
551k
      else
752
551k
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
604k
    }
754
9.40M
  else if (styp_flags & STYP_TBSS)
755
248k
    {
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
248k
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
248k
    }
763
9.15M
  else if (styp_flags & STYP_EXCEPT)
764
389k
    sec_flags |= SEC_LOAD;
765
8.76M
  else if (styp_flags & STYP_LOADER)
766
101k
    sec_flags |= SEC_LOAD;
767
8.66M
  else if (styp_flags & STYP_TYPCHK)
768
62.0k
    sec_flags |= SEC_LOAD;
769
8.60M
  else if (styp_flags & STYP_DWARF)
770
107k
    sec_flags |= SEC_DEBUGGING;
771
8.49M
#endif
772
8.49M
  else if (strcmp (name, _TEXT) == 0)
773
13.4k
    {
774
13.4k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.60k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
11.8k
      else
777
11.8k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
13.4k
    }
779
8.48M
  else if (strcmp (name, _DATA) == 0)
780
36.8k
    {
781
36.8k
      if (sec_flags & SEC_NEVER_LOAD)
782
3.10k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
33.7k
      else
784
33.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
36.8k
    }
786
8.44M
  else if (strcmp (name, _BSS) == 0)
787
6.84k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
6.84k
  sec_flags |= SEC_ALLOC;
794
6.84k
    }
795
8.44M
  else if (startswith (name, DOT_DEBUG)
796
8.44M
     || startswith (name, DOT_ZDEBUG)
797
#ifdef _COMMENT
798
     || strcmp (name, _COMMENT) == 0
799
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
8.44M
     || startswith (name, ".stab"))
805
36.4k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
36.4k
    }
810
#ifdef _LIB
811
  else if (strcmp (name, _LIB) == 0)
812
    ;
813
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
8.40M
  else
819
8.40M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
25.5M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
25.5M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
3.11M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
25.5M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
25.5M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
25.5M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
25.5M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
25.5M
  * flags_ptr = sec_flags;
851
25.5M
  return true;
852
25.5M
}
coff-sh.c:styp_to_sec_flags
Line
Count
Source
687
12.2M
{
688
12.2M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
12.2M
  unsigned long styp_flags = internal_s->s_flags;
690
12.2M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
12.2M
#ifdef STYP_NOLOAD
703
12.2M
  if (styp_flags & STYP_NOLOAD)
704
3.57M
    sec_flags |= SEC_NEVER_LOAD;
705
12.2M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
12.2M
  if (styp_flags & STYP_TEXT)
710
4.72M
    {
711
4.72M
      if (sec_flags & SEC_NEVER_LOAD)
712
2.44M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
2.27M
      else
714
2.27M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
4.72M
    }
716
7.55M
  else if (styp_flags & STYP_DATA)
717
932k
    {
718
932k
      if (sec_flags & SEC_NEVER_LOAD)
719
475k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
456k
      else
721
456k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
932k
    }
723
6.62M
  else if (styp_flags & STYP_BSS)
724
388k
    {
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
388k
  sec_flags |= SEC_ALLOC;
731
388k
    }
732
6.23M
  else if (styp_flags & STYP_INFO)
733
825k
    {
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
825k
    }
744
5.41M
  else if (styp_flags & STYP_PAD)
745
318k
    sec_flags = 0;
746
#ifdef RS6000COFF_C
747
  else if (styp_flags & STYP_TDATA)
748
    {
749
      if (sec_flags & SEC_NEVER_LOAD)
750
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
751
      else
752
  sec_flags |= SEC_DATA | SEC_THREAD_LOCAL | SEC_LOAD | SEC_ALLOC;
753
    }
754
  else if (styp_flags & STYP_TBSS)
755
    {
756
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
757
      if (sec_flags & SEC_NEVER_LOAD)
758
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL | SEC_COFF_SHARED_LIBRARY;
759
      else
760
#endif
761
  sec_flags |= SEC_ALLOC | SEC_THREAD_LOCAL;
762
    }
763
  else if (styp_flags & STYP_EXCEPT)
764
    sec_flags |= SEC_LOAD;
765
  else if (styp_flags & STYP_LOADER)
766
    sec_flags |= SEC_LOAD;
767
  else if (styp_flags & STYP_TYPCHK)
768
    sec_flags |= SEC_LOAD;
769
  else if (styp_flags & STYP_DWARF)
770
    sec_flags |= SEC_DEBUGGING;
771
#endif
772
5.09M
  else if (strcmp (name, _TEXT) == 0)
773
6.66k
    {
774
6.66k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.58k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.08k
      else
777
4.08k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
6.66k
    }
779
5.08M
  else if (strcmp (name, _DATA) == 0)
780
8.45k
    {
781
8.45k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.31k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
6.14k
      else
784
6.14k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
8.45k
    }
786
5.07M
  else if (strcmp (name, _BSS) == 0)
787
6.23k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
6.23k
  sec_flags |= SEC_ALLOC;
794
6.23k
    }
795
5.07M
  else if (startswith (name, DOT_DEBUG)
796
5.07M
     || startswith (name, DOT_ZDEBUG)
797
5.07M
#ifdef _COMMENT
798
5.07M
     || strcmp (name, _COMMENT) == 0
799
5.07M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
5.07M
     || startswith (name, ".stab"))
805
27.3k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
27.3k
    }
810
5.04M
#ifdef _LIB
811
5.04M
  else if (strcmp (name, _LIB) == 0)
812
2.15k
    ;
813
5.04M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
5.04M
  else
819
5.04M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
12.2M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
12.2M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.31M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
12.2M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
12.2M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
12.2M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
12.2M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
12.2M
  * flags_ptr = sec_flags;
851
12.2M
  return true;
852
12.2M
}
coff-stgo32.c:styp_to_sec_flags
Line
Count
Source
687
358k
{
688
358k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
358k
  unsigned long styp_flags = internal_s->s_flags;
690
358k
  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
358k
#ifdef STYP_NOLOAD
703
358k
  if (styp_flags & STYP_NOLOAD)
704
115k
    sec_flags |= SEC_NEVER_LOAD;
705
358k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
358k
  if (styp_flags & STYP_TEXT)
710
122k
    {
711
122k
      if (sec_flags & SEC_NEVER_LOAD)
712
66.2k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
55.8k
      else
714
55.8k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
122k
    }
716
236k
  else if (styp_flags & STYP_DATA)
717
35.7k
    {
718
35.7k
      if (sec_flags & SEC_NEVER_LOAD)
719
17.9k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
17.7k
      else
721
17.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
35.7k
    }
723
200k
  else if (styp_flags & STYP_BSS)
724
21.1k
    {
725
21.1k
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
726
21.1k
      if (sec_flags & SEC_NEVER_LOAD)
727
8.62k
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
728
12.5k
      else
729
12.5k
#endif
730
12.5k
  sec_flags |= SEC_ALLOC;
731
21.1k
    }
732
179k
  else if (styp_flags & STYP_INFO)
733
29.9k
    {
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
29.9k
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
29.9k
      sec_flags |= SEC_DEBUGGING;
742
29.9k
#endif
743
29.9k
    }
744
149k
  else if (styp_flags & STYP_PAD)
745
9.04k
    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
140k
  else if (strcmp (name, _TEXT) == 0)
773
294
    {
774
294
      if (sec_flags & SEC_NEVER_LOAD)
775
53
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
241
      else
777
241
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
294
    }
779
140k
  else if (strcmp (name, _DATA) == 0)
780
168
    {
781
168
      if (sec_flags & SEC_NEVER_LOAD)
782
31
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
137
      else
784
137
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
168
    }
786
140k
  else if (strcmp (name, _BSS) == 0)
787
155
    {
788
155
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
155
      if (sec_flags & SEC_NEVER_LOAD)
790
26
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
129
      else
792
129
#endif
793
129
  sec_flags |= SEC_ALLOC;
794
155
    }
795
140k
  else if (startswith (name, DOT_DEBUG)
796
140k
     || startswith (name, DOT_ZDEBUG)
797
140k
#ifdef _COMMENT
798
140k
     || strcmp (name, _COMMENT) == 0
799
140k
#endif
800
140k
#ifdef COFF_LONG_SECTION_NAMES
801
140k
     || startswith (name, GNU_LINKONCE_WI)
802
140k
     || startswith (name, GNU_LINKONCE_WT)
803
140k
#endif
804
140k
     || startswith (name, ".stab"))
805
3.40k
    {
806
3.40k
#ifdef COFF_PAGE_SIZE
807
3.40k
      sec_flags |= SEC_DEBUGGING;
808
3.40k
#endif
809
3.40k
    }
810
136k
#ifdef _LIB
811
136k
  else if (strcmp (name, _LIB) == 0)
812
106
    ;
813
136k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
136k
  else
819
136k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
358k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
358k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
50.6k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
358k
#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
358k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
358k
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
358k
#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
358k
  if (startswith (name, ".gnu.linkonce"))
844
104
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
358k
#endif
846
847
358k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
358k
  * flags_ptr = sec_flags;
851
358k
  return true;
852
358k
}
coff-tic30.c:styp_to_sec_flags
Line
Count
Source
687
5.80M
{
688
5.80M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
5.80M
  unsigned long styp_flags = internal_s->s_flags;
690
5.80M
  flagword sec_flags = 0;
691
692
#ifdef STYP_BLOCK
693
  if (styp_flags & STYP_BLOCK)
694
    sec_flags |= SEC_TIC54X_BLOCK;
695
#endif
696
697
#ifdef STYP_CLINK
698
  if (styp_flags & STYP_CLINK)
699
    sec_flags |= SEC_TIC54X_CLINK;
700
#endif
701
702
5.80M
#ifdef STYP_NOLOAD
703
5.80M
  if (styp_flags & STYP_NOLOAD)
704
1.87M
    sec_flags |= SEC_NEVER_LOAD;
705
5.80M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
5.80M
  if (styp_flags & STYP_TEXT)
710
2.33M
    {
711
2.33M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.29M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.03M
      else
714
1.03M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
2.33M
    }
716
3.47M
  else if (styp_flags & STYP_DATA)
717
446k
    {
718
446k
      if (sec_flags & SEC_NEVER_LOAD)
719
256k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
190k
      else
721
190k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
446k
    }
723
3.02M
  else if (styp_flags & STYP_BSS)
724
208k
    {
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
208k
  sec_flags |= SEC_ALLOC;
731
208k
    }
732
2.81M
  else if (styp_flags & STYP_INFO)
733
393k
    {
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
393k
    }
744
2.42M
  else if (styp_flags & STYP_PAD)
745
110k
    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.31M
  else if (strcmp (name, _TEXT) == 0)
773
7.61k
    {
774
7.61k
      if (sec_flags & SEC_NEVER_LOAD)
775
1.74k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
5.87k
      else
777
5.87k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
7.61k
    }
779
2.30M
  else if (strcmp (name, _DATA) == 0)
780
14.2k
    {
781
14.2k
      if (sec_flags & SEC_NEVER_LOAD)
782
1.83k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
12.3k
      else
784
12.3k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
14.2k
    }
786
2.29M
  else if (strcmp (name, _BSS) == 0)
787
4.82k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
4.82k
  sec_flags |= SEC_ALLOC;
794
4.82k
    }
795
2.28M
  else if (startswith (name, DOT_DEBUG)
796
2.28M
     || startswith (name, DOT_ZDEBUG)
797
2.28M
#ifdef _COMMENT
798
2.28M
     || strcmp (name, _COMMENT) == 0
799
2.28M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
2.28M
     || startswith (name, ".stab"))
805
21.7k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
21.7k
    }
810
2.26M
#ifdef _LIB
811
2.26M
  else if (strcmp (name, _LIB) == 0)
812
2.40k
    ;
813
2.26M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
2.26M
  else
819
2.26M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
5.80M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
5.80M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
682k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
5.80M
#endif /* STYP_LIT */
825
826
#ifdef STYP_OTHER_LOAD    /* Other loaded sections.  */
827
  if (styp_flags & STYP_OTHER_LOAD)
828
    sec_flags = (SEC_LOAD | SEC_ALLOC);
829
#endif /* STYP_SDATA */
830
831
5.80M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
5.80M
      && (startswith (name, ".sbss")
833
0
    || startswith (name, ".sdata")))
834
0
    sec_flags |= SEC_SMALL_DATA;
835
836
#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
837
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
838
     only link a single copy of the section.  This is used to support
839
     g++.  g++ will emit each template expansion in its own section.
840
     The symbols will be defined as weak, so that multiple definitions
841
     are permitted.  The GNU linker extension is to actually discard
842
     all but one of the sections.  */
843
  if (startswith (name, ".gnu.linkonce"))
844
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
845
#endif
846
847
5.80M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
5.80M
  * flags_ptr = sec_flags;
851
5.80M
  return true;
852
5.80M
}
Unexecuted instantiation: coff-tic4x.c:styp_to_sec_flags
coff-tic54x.c:styp_to_sec_flags
Line
Count
Source
687
8.33M
{
688
8.33M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
8.33M
  unsigned long styp_flags = internal_s->s_flags;
690
8.33M
  flagword sec_flags = 0;
691
692
8.33M
#ifdef STYP_BLOCK
693
8.33M
  if (styp_flags & STYP_BLOCK)
694
2.62M
    sec_flags |= SEC_TIC54X_BLOCK;
695
8.33M
#endif
696
697
8.33M
#ifdef STYP_CLINK
698
8.33M
  if (styp_flags & STYP_CLINK)
699
2.54M
    sec_flags |= SEC_TIC54X_CLINK;
700
8.33M
#endif
701
702
8.33M
#ifdef STYP_NOLOAD
703
8.33M
  if (styp_flags & STYP_NOLOAD)
704
2.50M
    sec_flags |= SEC_NEVER_LOAD;
705
8.33M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
8.33M
  if (styp_flags & STYP_TEXT)
710
3.49M
    {
711
3.49M
      if (sec_flags & SEC_NEVER_LOAD)
712
1.83M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.65M
      else
714
1.65M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.49M
    }
716
4.83M
  else if (styp_flags & STYP_DATA)
717
543k
    {
718
543k
      if (sec_flags & SEC_NEVER_LOAD)
719
289k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
254k
      else
721
254k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
543k
    }
723
4.29M
  else if (styp_flags & STYP_BSS)
724
220k
    {
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
220k
  sec_flags |= SEC_ALLOC;
731
220k
    }
732
4.07M
  else if (styp_flags & STYP_INFO)
733
492k
    {
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
492k
    }
744
3.57M
  else if (styp_flags & STYP_PAD)
745
181k
    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.39M
  else if (strcmp (name, _TEXT) == 0)
773
9.28k
    {
774
9.28k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.16k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
7.12k
      else
777
7.12k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
9.28k
    }
779
3.38M
  else if (strcmp (name, _DATA) == 0)
780
19.9k
    {
781
19.9k
      if (sec_flags & SEC_NEVER_LOAD)
782
2.15k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
17.7k
      else
784
17.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
19.9k
    }
786
3.36M
  else if (strcmp (name, _BSS) == 0)
787
6.86k
    {
788
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
789
      if (sec_flags & SEC_NEVER_LOAD)
790
  sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
791
      else
792
#endif
793
6.86k
  sec_flags |= SEC_ALLOC;
794
6.86k
    }
795
3.36M
  else if (startswith (name, DOT_DEBUG)
796
3.36M
     || 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.36M
     || startswith (name, ".stab"))
805
16.0k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
16.0k
    }
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.34M
  else
819
3.34M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
8.33M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
8.33M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
903k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
8.33M
#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
8.33M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
8.33M
      && (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
8.33M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
8.33M
  * flags_ptr = sec_flags;
851
8.33M
  return true;
852
8.33M
}
coff-z80.c:styp_to_sec_flags
Line
Count
Source
687
753k
{
688
753k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
753k
  unsigned long styp_flags = internal_s->s_flags;
690
753k
  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
753k
#ifdef STYP_NOLOAD
703
753k
  if (styp_flags & STYP_NOLOAD)
704
236k
    sec_flags |= SEC_NEVER_LOAD;
705
753k
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
753k
  if (styp_flags & STYP_TEXT)
710
275k
    {
711
275k
      if (sec_flags & SEC_NEVER_LOAD)
712
150k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
125k
      else
714
125k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
275k
    }
716
478k
  else if (styp_flags & STYP_DATA)
717
69.4k
    {
718
69.4k
      if (sec_flags & SEC_NEVER_LOAD)
719
35.6k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
33.7k
      else
721
33.7k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
69.4k
    }
723
408k
  else if (styp_flags & STYP_BSS)
724
25.9k
    {
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
25.9k
  sec_flags |= SEC_ALLOC;
731
25.9k
    }
732
382k
  else if (styp_flags & STYP_INFO)
733
56.4k
    {
734
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
735
   defined.  coff_compute_section_file_positions uses
736
   COFF_PAGE_SIZE to ensure that the low order bits of the
737
   section VMA and the file offset match.  If we don't know
738
   COFF_PAGE_SIZE, we can't ensure the correct correspondence,
739
   and demand page loading of the file will fail.  */
740
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
741
      sec_flags |= SEC_DEBUGGING;
742
#endif
743
56.4k
    }
744
326k
  else if (styp_flags & STYP_PAD)
745
23.6k
    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
302k
  else if (strcmp (name, _TEXT) == 0)
773
2.97k
    {
774
2.97k
      if (sec_flags & SEC_NEVER_LOAD)
775
585
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
2.39k
      else
777
2.39k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
2.97k
    }
779
299k
  else if (strcmp (name, _DATA) == 0)
780
3.42k
    {
781
3.42k
      if (sec_flags & SEC_NEVER_LOAD)
782
431
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
2.98k
      else
784
2.98k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
3.42k
    }
786
296k
  else if (strcmp (name, _BSS) == 0)
787
916
    {
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
916
  sec_flags |= SEC_ALLOC;
794
916
    }
795
295k
  else if (startswith (name, DOT_DEBUG)
796
295k
     || startswith (name, DOT_ZDEBUG)
797
295k
#ifdef _COMMENT
798
295k
     || strcmp (name, _COMMENT) == 0
799
295k
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
295k
     || startswith (name, ".stab"))
805
5.27k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
5.27k
    }
810
290k
#ifdef _LIB
811
290k
  else if (strcmp (name, _LIB) == 0)
812
616
    ;
813
289k
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
289k
  else
819
289k
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
753k
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
753k
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
81.5k
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
753k
#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
753k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
753k
      && (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
753k
  if (flags_ptr == NULL)
848
0
    return false;
849
850
753k
  * flags_ptr = sec_flags;
851
753k
  return true;
852
753k
}
coff-z8k.c:styp_to_sec_flags
Line
Count
Source
687
8.88M
{
688
8.88M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
689
8.88M
  unsigned long styp_flags = internal_s->s_flags;
690
8.88M
  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
8.88M
#ifdef STYP_NOLOAD
703
8.88M
  if (styp_flags & STYP_NOLOAD)
704
3.31M
    sec_flags |= SEC_NEVER_LOAD;
705
8.88M
#endif /* STYP_NOLOAD */
706
707
  /* For 386 COFF, at least, an unloadable text or data section is
708
     actually a shared library section.  */
709
8.88M
  if (styp_flags & STYP_TEXT)
710
3.62M
    {
711
3.62M
      if (sec_flags & SEC_NEVER_LOAD)
712
2.18M
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
713
1.43M
      else
714
1.43M
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
715
3.62M
    }
716
5.25M
  else if (styp_flags & STYP_DATA)
717
903k
    {
718
903k
      if (sec_flags & SEC_NEVER_LOAD)
719
551k
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
720
351k
      else
721
351k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
722
903k
    }
723
4.35M
  else if (styp_flags & STYP_BSS)
724
291k
    {
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
291k
  sec_flags |= SEC_ALLOC;
731
291k
    }
732
4.06M
  else if (styp_flags & STYP_INFO)
733
625k
    {
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
625k
    }
744
3.43M
  else if (styp_flags & STYP_PAD)
745
195k
    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.24M
  else if (strcmp (name, _TEXT) == 0)
773
6.60k
    {
774
6.60k
      if (sec_flags & SEC_NEVER_LOAD)
775
2.45k
  sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
776
4.15k
      else
777
4.15k
  sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
778
6.60k
    }
779
3.23M
  else if (strcmp (name, _DATA) == 0)
780
7.53k
    {
781
7.53k
      if (sec_flags & SEC_NEVER_LOAD)
782
695
  sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
783
6.84k
      else
784
6.84k
  sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
785
7.53k
    }
786
3.22M
  else if (strcmp (name, _BSS) == 0)
787
1.90k
    {
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
1.90k
  sec_flags |= SEC_ALLOC;
794
1.90k
    }
795
3.22M
  else if (startswith (name, DOT_DEBUG)
796
3.22M
     || startswith (name, DOT_ZDEBUG)
797
3.22M
#ifdef _COMMENT
798
3.22M
     || strcmp (name, _COMMENT) == 0
799
3.22M
#endif
800
#ifdef COFF_LONG_SECTION_NAMES
801
     || startswith (name, GNU_LINKONCE_WI)
802
     || startswith (name, GNU_LINKONCE_WT)
803
#endif
804
3.22M
     || startswith (name, ".stab"))
805
21.8k
    {
806
#ifdef COFF_PAGE_SIZE
807
      sec_flags |= SEC_DEBUGGING;
808
#endif
809
21.8k
    }
810
3.20M
#ifdef _LIB
811
3.20M
  else if (strcmp (name, _LIB) == 0)
812
1.94k
    ;
813
3.20M
#endif
814
#ifdef _LIT
815
  else if (strcmp (name, _LIT) == 0)
816
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
817
#endif
818
3.20M
  else
819
3.20M
    sec_flags |= SEC_ALLOC | SEC_LOAD;
820
821
8.88M
#ifdef STYP_LIT     /* A29k readonly text/data section type.  */
822
8.88M
  if ((styp_flags & STYP_LIT) == STYP_LIT)
823
1.16M
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
824
8.88M
#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
8.88M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
832
8.88M
      && (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
8.88M
  if (flags_ptr == NULL)
848
0
    return false;
849
850
8.88M
  * flags_ptr = sec_flags;
851
8.88M
  return true;
852
8.88M
}
853
854
#else /* COFF_WITH_PE */
855
856
static hashval_t
857
comdat_hashf (const void *entry)
858
8.91M
{
859
8.91M
  const struct comdat_hash_entry *fe = entry;
860
8.91M
  return fe->target_index;
861
8.91M
}
pei-i386.c:comdat_hashf
Line
Count
Source
858
470k
{
859
470k
  const struct comdat_hash_entry *fe = entry;
860
470k
  return fe->target_index;
861
470k
}
pe-x86_64.c:comdat_hashf
Line
Count
Source
858
351k
{
859
351k
  const struct comdat_hash_entry *fe = entry;
860
351k
  return fe->target_index;
861
351k
}
pei-x86_64.c:comdat_hashf
Line
Count
Source
858
553k
{
859
553k
  const struct comdat_hash_entry *fe = entry;
860
553k
  return fe->target_index;
861
553k
}
pe-aarch64.c:comdat_hashf
Line
Count
Source
858
157k
{
859
157k
  const struct comdat_hash_entry *fe = entry;
860
157k
  return fe->target_index;
861
157k
}
pei-aarch64.c:comdat_hashf
Line
Count
Source
858
1.24M
{
859
1.24M
  const struct comdat_hash_entry *fe = entry;
860
1.24M
  return fe->target_index;
861
1.24M
}
pei-ia64.c:comdat_hashf
Line
Count
Source
858
721k
{
859
721k
  const struct comdat_hash_entry *fe = entry;
860
721k
  return fe->target_index;
861
721k
}
pei-loongarch64.c:comdat_hashf
Line
Count
Source
858
155k
{
859
155k
  const struct comdat_hash_entry *fe = entry;
860
155k
  return fe->target_index;
861
155k
}
pe-arm-wince.c:comdat_hashf
Line
Count
Source
858
489k
{
859
489k
  const struct comdat_hash_entry *fe = entry;
860
489k
  return fe->target_index;
861
489k
}
pe-arm.c:comdat_hashf
Line
Count
Source
858
489k
{
859
489k
  const struct comdat_hash_entry *fe = entry;
860
489k
  return fe->target_index;
861
489k
}
pe-i386.c:comdat_hashf
Line
Count
Source
858
280k
{
859
280k
  const struct comdat_hash_entry *fe = entry;
860
280k
  return fe->target_index;
861
280k
}
pe-mcore.c:comdat_hashf
Line
Count
Source
858
2.24M
{
859
2.24M
  const struct comdat_hash_entry *fe = entry;
860
2.24M
  return fe->target_index;
861
2.24M
}
pe-sh.c:comdat_hashf
Line
Count
Source
858
862k
{
859
862k
  const struct comdat_hash_entry *fe = entry;
860
862k
  return fe->target_index;
861
862k
}
pei-arm-wince.c:comdat_hashf
Line
Count
Source
858
277k
{
859
277k
  const struct comdat_hash_entry *fe = entry;
860
277k
  return fe->target_index;
861
277k
}
pei-arm.c:comdat_hashf
Line
Count
Source
858
311k
{
859
311k
  const struct comdat_hash_entry *fe = entry;
860
311k
  return fe->target_index;
861
311k
}
pei-mcore.c:comdat_hashf
Line
Count
Source
858
124k
{
859
124k
  const struct comdat_hash_entry *fe = entry;
860
124k
  return fe->target_index;
861
124k
}
pei-sh.c:comdat_hashf
Line
Count
Source
858
184k
{
859
184k
  const struct comdat_hash_entry *fe = entry;
860
184k
  return fe->target_index;
861
184k
}
862
863
static int
864
comdat_eqf (const void *e1, const void *e2)
865
7.41M
{
866
7.41M
  const struct comdat_hash_entry *fe1 = e1;
867
7.41M
  const struct comdat_hash_entry *fe2 = e2;
868
7.41M
  return fe1->target_index == fe2->target_index;
869
7.41M
}
pei-i386.c:comdat_eqf
Line
Count
Source
865
358k
{
866
358k
  const struct comdat_hash_entry *fe1 = e1;
867
358k
  const struct comdat_hash_entry *fe2 = e2;
868
358k
  return fe1->target_index == fe2->target_index;
869
358k
}
pe-x86_64.c:comdat_eqf
Line
Count
Source
865
205k
{
866
205k
  const struct comdat_hash_entry *fe1 = e1;
867
205k
  const struct comdat_hash_entry *fe2 = e2;
868
205k
  return fe1->target_index == fe2->target_index;
869
205k
}
pei-x86_64.c:comdat_eqf
Line
Count
Source
865
405k
{
866
405k
  const struct comdat_hash_entry *fe1 = e1;
867
405k
  const struct comdat_hash_entry *fe2 = e2;
868
405k
  return fe1->target_index == fe2->target_index;
869
405k
}
pe-aarch64.c:comdat_eqf
Line
Count
Source
865
133k
{
866
133k
  const struct comdat_hash_entry *fe1 = e1;
867
133k
  const struct comdat_hash_entry *fe2 = e2;
868
133k
  return fe1->target_index == fe2->target_index;
869
133k
}
pei-aarch64.c:comdat_eqf
Line
Count
Source
865
996k
{
866
996k
  const struct comdat_hash_entry *fe1 = e1;
867
996k
  const struct comdat_hash_entry *fe2 = e2;
868
996k
  return fe1->target_index == fe2->target_index;
869
996k
}
pei-ia64.c:comdat_eqf
Line
Count
Source
865
527k
{
866
527k
  const struct comdat_hash_entry *fe1 = e1;
867
527k
  const struct comdat_hash_entry *fe2 = e2;
868
527k
  return fe1->target_index == fe2->target_index;
869
527k
}
pei-loongarch64.c:comdat_eqf
Line
Count
Source
865
100k
{
866
100k
  const struct comdat_hash_entry *fe1 = e1;
867
100k
  const struct comdat_hash_entry *fe2 = e2;
868
100k
  return fe1->target_index == fe2->target_index;
869
100k
}
pe-arm-wince.c:comdat_eqf
Line
Count
Source
865
420k
{
866
420k
  const struct comdat_hash_entry *fe1 = e1;
867
420k
  const struct comdat_hash_entry *fe2 = e2;
868
420k
  return fe1->target_index == fe2->target_index;
869
420k
}
pe-arm.c:comdat_eqf
Line
Count
Source
865
420k
{
866
420k
  const struct comdat_hash_entry *fe1 = e1;
867
420k
  const struct comdat_hash_entry *fe2 = e2;
868
420k
  return fe1->target_index == fe2->target_index;
869
420k
}
pe-i386.c:comdat_eqf
Line
Count
Source
865
304k
{
866
304k
  const struct comdat_hash_entry *fe1 = e1;
867
304k
  const struct comdat_hash_entry *fe2 = e2;
868
304k
  return fe1->target_index == fe2->target_index;
869
304k
}
pe-mcore.c:comdat_eqf
Line
Count
Source
865
2.21M
{
866
2.21M
  const struct comdat_hash_entry *fe1 = e1;
867
2.21M
  const struct comdat_hash_entry *fe2 = e2;
868
2.21M
  return fe1->target_index == fe2->target_index;
869
2.21M
}
pe-sh.c:comdat_eqf
Line
Count
Source
865
744k
{
866
744k
  const struct comdat_hash_entry *fe1 = e1;
867
744k
  const struct comdat_hash_entry *fe2 = e2;
868
744k
  return fe1->target_index == fe2->target_index;
869
744k
}
pei-arm-wince.c:comdat_eqf
Line
Count
Source
865
183k
{
866
183k
  const struct comdat_hash_entry *fe1 = e1;
867
183k
  const struct comdat_hash_entry *fe2 = e2;
868
183k
  return fe1->target_index == fe2->target_index;
869
183k
}
pei-arm.c:comdat_eqf
Line
Count
Source
865
202k
{
866
202k
  const struct comdat_hash_entry *fe1 = e1;
867
202k
  const struct comdat_hash_entry *fe2 = e2;
868
202k
  return fe1->target_index == fe2->target_index;
869
202k
}
pei-mcore.c:comdat_eqf
Line
Count
Source
865
82.5k
{
866
82.5k
  const struct comdat_hash_entry *fe1 = e1;
867
82.5k
  const struct comdat_hash_entry *fe2 = e2;
868
82.5k
  return fe1->target_index == fe2->target_index;
869
82.5k
}
pei-sh.c:comdat_eqf
Line
Count
Source
865
112k
{
866
112k
  const struct comdat_hash_entry *fe1 = e1;
867
112k
  const struct comdat_hash_entry *fe2 = e2;
868
112k
  return fe1->target_index == fe2->target_index;
869
112k
}
870
871
static void
872
comdat_delf (void *ent)
873
1.45M
{
874
1.45M
  struct comdat_hash_entry *e = ent;
875
1.45M
  free (e->symname);
876
1.45M
  free (e);
877
1.45M
}
pei-i386.c:comdat_delf
Line
Count
Source
873
120k
{
874
120k
  struct comdat_hash_entry *e = ent;
875
120k
  free (e->symname);
876
120k
  free (e);
877
120k
}
pe-x86_64.c:comdat_delf
Line
Count
Source
873
92.4k
{
874
92.4k
  struct comdat_hash_entry *e = ent;
875
92.4k
  free (e->symname);
876
92.4k
  free (e);
877
92.4k
}
pei-x86_64.c:comdat_delf
Line
Count
Source
873
192k
{
874
192k
  struct comdat_hash_entry *e = ent;
875
192k
  free (e->symname);
876
192k
  free (e);
877
192k
}
pe-aarch64.c:comdat_delf
Line
Count
Source
873
17.1k
{
874
17.1k
  struct comdat_hash_entry *e = ent;
875
17.1k
  free (e->symname);
876
17.1k
  free (e);
877
17.1k
}
pei-aarch64.c:comdat_delf
Line
Count
Source
873
232k
{
874
232k
  struct comdat_hash_entry *e = ent;
875
232k
  free (e->symname);
876
232k
  free (e);
877
232k
}
pei-ia64.c:comdat_delf
Line
Count
Source
873
198k
{
874
198k
  struct comdat_hash_entry *e = ent;
875
198k
  free (e->symname);
876
198k
  free (e);
877
198k
}
pei-loongarch64.c:comdat_delf
Line
Count
Source
873
40.2k
{
874
40.2k
  struct comdat_hash_entry *e = ent;
875
40.2k
  free (e->symname);
876
40.2k
  free (e);
877
40.2k
}
pe-arm-wince.c:comdat_delf
Line
Count
Source
873
60.3k
{
874
60.3k
  struct comdat_hash_entry *e = ent;
875
60.3k
  free (e->symname);
876
60.3k
  free (e);
877
60.3k
}
pe-arm.c:comdat_delf
Line
Count
Source
873
60.3k
{
874
60.3k
  struct comdat_hash_entry *e = ent;
875
60.3k
  free (e->symname);
876
60.3k
  free (e);
877
60.3k
}
pe-i386.c:comdat_delf
Line
Count
Source
873
55.2k
{
874
55.2k
  struct comdat_hash_entry *e = ent;
875
55.2k
  free (e->symname);
876
55.2k
  free (e);
877
55.2k
}
pe-mcore.c:comdat_delf
Line
Count
Source
873
14.8k
{
874
14.8k
  struct comdat_hash_entry *e = ent;
875
14.8k
  free (e->symname);
876
14.8k
  free (e);
877
14.8k
}
pe-sh.c:comdat_delf
Line
Count
Source
873
124k
{
874
124k
  struct comdat_hash_entry *e = ent;
875
124k
  free (e->symname);
876
124k
  free (e);
877
124k
}
pei-arm-wince.c:comdat_delf
Line
Count
Source
873
77.4k
{
874
77.4k
  struct comdat_hash_entry *e = ent;
875
77.4k
  free (e->symname);
876
77.4k
  free (e);
877
77.4k
}
pei-arm.c:comdat_delf
Line
Count
Source
873
82.9k
{
874
82.9k
  struct comdat_hash_entry *e = ent;
875
82.9k
  free (e->symname);
876
82.9k
  free (e);
877
82.9k
}
pei-mcore.c:comdat_delf
Line
Count
Source
873
26.7k
{
874
26.7k
  struct comdat_hash_entry *e = ent;
875
26.7k
  free (e->symname);
876
26.7k
  free (e);
877
26.7k
}
pei-sh.c:comdat_delf
Line
Count
Source
873
57.6k
{
874
57.6k
  struct comdat_hash_entry *e = ent;
875
57.6k
  free (e->symname);
876
57.6k
  free (e);
877
57.6k
}
878
879
static struct comdat_hash_entry *
880
find_flags (htab_t comdat_hash, int target_index)
881
565k
{
882
565k
  struct comdat_hash_entry needle;
883
565k
  needle.target_index = target_index;
884
885
565k
  return htab_find (comdat_hash, &needle);
886
565k
}
pei-i386.c:find_flags
Line
Count
Source
881
42.2k
{
882
42.2k
  struct comdat_hash_entry needle;
883
42.2k
  needle.target_index = target_index;
884
885
42.2k
  return htab_find (comdat_hash, &needle);
886
42.2k
}
pe-x86_64.c:find_flags
Line
Count
Source
881
62.7k
{
882
62.7k
  struct comdat_hash_entry needle;
883
62.7k
  needle.target_index = target_index;
884
885
62.7k
  return htab_find (comdat_hash, &needle);
886
62.7k
}
pei-x86_64.c:find_flags
Line
Count
Source
881
55.1k
{
882
55.1k
  struct comdat_hash_entry needle;
883
55.1k
  needle.target_index = target_index;
884
885
55.1k
  return htab_find (comdat_hash, &needle);
886
55.1k
}
pe-aarch64.c:find_flags
Line
Count
Source
881
17.4k
{
882
17.4k
  struct comdat_hash_entry needle;
883
17.4k
  needle.target_index = target_index;
884
885
17.4k
  return htab_find (comdat_hash, &needle);
886
17.4k
}
pei-aarch64.c:find_flags
Line
Count
Source
881
37.3k
{
882
37.3k
  struct comdat_hash_entry needle;
883
37.3k
  needle.target_index = target_index;
884
885
37.3k
  return htab_find (comdat_hash, &needle);
886
37.3k
}
pei-ia64.c:find_flags
Line
Count
Source
881
49.5k
{
882
49.5k
  struct comdat_hash_entry needle;
883
49.5k
  needle.target_index = target_index;
884
885
49.5k
  return htab_find (comdat_hash, &needle);
886
49.5k
}
pei-loongarch64.c:find_flags
Line
Count
Source
881
26.3k
{
882
26.3k
  struct comdat_hash_entry needle;
883
26.3k
  needle.target_index = target_index;
884
885
26.3k
  return htab_find (comdat_hash, &needle);
886
26.3k
}
pe-arm-wince.c:find_flags
Line
Count
Source
881
12.1k
{
882
12.1k
  struct comdat_hash_entry needle;
883
12.1k
  needle.target_index = target_index;
884
885
12.1k
  return htab_find (comdat_hash, &needle);
886
12.1k
}
pe-arm.c:find_flags
Line
Count
Source
881
12.1k
{
882
12.1k
  struct comdat_hash_entry needle;
883
12.1k
  needle.target_index = target_index;
884
885
12.1k
  return htab_find (comdat_hash, &needle);
886
12.1k
}
pe-i386.c:find_flags
Line
Count
Source
881
32.8k
{
882
32.8k
  struct comdat_hash_entry needle;
883
32.8k
  needle.target_index = target_index;
884
885
32.8k
  return htab_find (comdat_hash, &needle);
886
32.8k
}
pe-mcore.c:find_flags
Line
Count
Source
881
18.8k
{
882
18.8k
  struct comdat_hash_entry needle;
883
18.8k
  needle.target_index = target_index;
884
885
18.8k
  return htab_find (comdat_hash, &needle);
886
18.8k
}
pe-sh.c:find_flags
Line
Count
Source
881
28.7k
{
882
28.7k
  struct comdat_hash_entry needle;
883
28.7k
  needle.target_index = target_index;
884
885
28.7k
  return htab_find (comdat_hash, &needle);
886
28.7k
}
pei-arm-wince.c:find_flags
Line
Count
Source
881
43.9k
{
882
43.9k
  struct comdat_hash_entry needle;
883
43.9k
  needle.target_index = target_index;
884
885
43.9k
  return htab_find (comdat_hash, &needle);
886
43.9k
}
pei-arm.c:find_flags
Line
Count
Source
881
56.0k
{
882
56.0k
  struct comdat_hash_entry needle;
883
56.0k
  needle.target_index = target_index;
884
885
56.0k
  return htab_find (comdat_hash, &needle);
886
56.0k
}
pei-mcore.c:find_flags
Line
Count
Source
881
30.2k
{
882
30.2k
  struct comdat_hash_entry needle;
883
30.2k
  needle.target_index = target_index;
884
885
30.2k
  return htab_find (comdat_hash, &needle);
886
30.2k
}
pei-sh.c:find_flags
Line
Count
Source
881
39.9k
{
882
39.9k
  struct comdat_hash_entry needle;
883
39.9k
  needle.target_index = target_index;
884
885
39.9k
  return htab_find (comdat_hash, &needle);
886
39.9k
}
887
888
static bool
889
fill_comdat_hash (bfd *abfd)
890
443k
{
891
443k
  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
443k
  if (! _bfd_coff_get_external_symbols (abfd))
909
179k
    return true;
910
911
264k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
264k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
264k
  for (struct internal_syment isym;
915
9.31M
       esym < esymend;
916
9.04M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
9.04M
    {
918
9.04M
      char buf[SYMNMLEN + 1];
919
9.04M
      const char *symname;
920
9.04M
      flagword sec_flags = SEC_LINK_ONCE;
921
922
9.04M
      bfd_coff_swap_sym_in (abfd, esym, &isym);
923
924
      /* According to the MSVC documentation, the first TWO entries
925
   with the section # are both of interest to us.  The first one
926
   is the "section symbol" (section name).  The second is the
927
   comdat symbol name.  Here, we've found the first qualifying
928
   entry; we distinguish it from the second with a state flag.
929
930
   In the case of gas-generated (at least until that is fixed)
931
   .o files, it isn't necessarily the second one.  It may be
932
   some other later symbol.
933
934
   Since gas also doesn't follow MS conventions and emits the
935
   section similar to .text$<name>, where <something> is the
936
   name we're looking for, we distinguish the two as follows:
937
938
   If the section name is simply a section name (no $) we
939
   presume it's MS-generated, and look at precisely the second
940
   symbol for the comdat name.  If the section name has a $, we
941
   assume it's gas-generated, and look for <something> (whatever
942
   follows the $) as the comdat symbol.  */
943
944
      /* All 3 branches use this.  */
945
9.04M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
9.04M
      if (symname == NULL)
949
1.71M
  {
950
1.71M
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
1.71M
            abfd);
952
1.71M
    continue;
953
1.71M
  }
954
955
7.33M
      union internal_auxent aux;
956
957
7.33M
      struct comdat_hash_entry needle;
958
7.33M
      needle.target_index = isym.n_scnum;
959
960
7.33M
      void **slot
961
7.33M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
7.33M
      if (slot == NULL)
963
0
  return false;
964
965
7.33M
      if (*slot == NULL)
966
1.53M
  {
967
1.53M
    if (isym.n_numaux == 0)
968
634k
      aux.x_scn.x_comdat = 0;
969
902k
    else
970
902k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
902k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
84.4k
    {
974
      /* xgettext:c-format */
975
84.4k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
84.4k
          " section '%s' found"),
977
84.4k
              abfd, symname);
978
84.4k
      continue;
979
84.4k
    }
980
818k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
818k
            isym.n_type, isym.n_sclass, 0,
982
818k
            isym.n_numaux, &aux);
983
818k
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
1.45M
    switch (aux.x_scn.x_comdat)
998
1.45M
      {
999
7.09k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
7.09k
        sec_flags &= ~SEC_LINK_ONCE;
1004
7.09k
#endif
1005
7.09k
        break;
1006
1007
25
      case IMAGE_COMDAT_SELECT_ANY:
1008
25
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
25
        break;
1010
1011
1.05k
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
1.05k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
1.05k
        break;
1014
1015
3.49k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
3.49k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
3.49k
        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
925
      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
925
        sec_flags &= ~SEC_LINK_ONCE;
1031
925
#endif
1032
925
        break;
1033
1034
1.44M
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
1.44M
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
1.44M
        break;
1038
1.45M
      }
1039
1040
1.45M
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
1.45M
    if (*slot == NULL)
1042
0
      return false;
1043
1.45M
    struct comdat_hash_entry *newentry = *slot;
1044
1.45M
    newentry->sec_flags = sec_flags;
1045
1.45M
    newentry->symname = bfd_strdup (symname);
1046
1.45M
    newentry->target_index = isym.n_scnum;
1047
1.45M
    newentry->isym = isym;
1048
1.45M
    newentry->comdat_symbol = -1;
1049
1.45M
  }
1050
5.79M
      else
1051
5.79M
  {
1052
5.79M
    struct comdat_hash_entry *entry = *slot;
1053
1054
5.79M
    if (entry->comdat_symbol != -1)
1055
5.54M
      continue;
1056
1057
250k
    char *target_name = strchr (entry->symname, '$');
1058
250k
    if (target_name != NULL)
1059
19.8k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
19.8k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
5.49k
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
19.8k
        if (strcmp (target_name,
1068
19.8k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
16.0k
    {
1070
      /* Not the name we're looking for */
1071
16.0k
      continue;
1072
16.0k
    }
1073
19.8k
      }
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
234k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
234k
    entry->comdat_name = bfd_strdup (symname);
1082
234k
  }
1083
7.33M
    }
1084
1085
264k
  return true;
1086
264k
}
pei-i386.c:fill_comdat_hash
Line
Count
Source
890
25.4k
{
891
25.4k
  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
25.4k
  if (! _bfd_coff_get_external_symbols (abfd))
909
8.86k
    return true;
910
911
16.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
16.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
16.5k
  for (struct internal_syment isym;
915
594k
       esym < esymend;
916
578k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
578k
    {
918
578k
      char buf[SYMNMLEN + 1];
919
578k
      const char *symname;
920
578k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
578k
      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
578k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
578k
      if (symname == NULL)
949
242k
  {
950
242k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
242k
            abfd);
952
242k
    continue;
953
242k
  }
954
955
335k
      union internal_auxent aux;
956
957
335k
      struct comdat_hash_entry needle;
958
335k
      needle.target_index = isym.n_scnum;
959
960
335k
      void **slot
961
335k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
335k
      if (slot == NULL)
963
0
  return false;
964
965
335k
      if (*slot == NULL)
966
126k
  {
967
126k
    if (isym.n_numaux == 0)
968
65.8k
      aux.x_scn.x_comdat = 0;
969
60.1k
    else
970
60.1k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
60.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
5.89k
    {
974
      /* xgettext:c-format */
975
5.89k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
5.89k
          " section '%s' found"),
977
5.89k
              abfd, symname);
978
5.89k
      continue;
979
5.89k
    }
980
54.2k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
54.2k
            isym.n_type, isym.n_sclass, 0,
982
54.2k
            isym.n_numaux, &aux);
983
54.2k
      }
984
985
    /* FIXME: Microsoft uses NODUPLICATES and ASSOCIATIVE, but
986
       gnu uses ANY and SAME_SIZE.  Unfortunately, gnu doesn't
987
       do the comdat symbols right.  So, until we can fix it to
988
       do the right thing, we are temporarily disabling comdats
989
       for the MS types (they're used in DLLs and C++, but we
990
       don't support *their* C++ libraries anyway - DJ.  */
991
992
    /* Cygwin does not follow the MS style, and uses ANY and
993
       SAME_SIZE where NODUPLICATES and ASSOCIATIVE should be
994
       used.  For Interix, we just do the right thing up
995
       front.  */
996
997
120k
    switch (aux.x_scn.x_comdat)
998
120k
      {
999
305
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
305
        sec_flags &= ~SEC_LINK_ONCE;
1004
305
#endif
1005
305
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
259
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
259
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
259
        break;
1014
1015
18
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
18
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
18
        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
16
      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
16
        sec_flags &= ~SEC_LINK_ONCE;
1031
16
#endif
1032
16
        break;
1033
1034
119k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
119k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
119k
        break;
1038
120k
      }
1039
1040
120k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
120k
    if (*slot == NULL)
1042
0
      return false;
1043
120k
    struct comdat_hash_entry *newentry = *slot;
1044
120k
    newentry->sec_flags = sec_flags;
1045
120k
    newentry->symname = bfd_strdup (symname);
1046
120k
    newentry->target_index = isym.n_scnum;
1047
120k
    newentry->isym = isym;
1048
120k
    newentry->comdat_symbol = -1;
1049
120k
  }
1050
209k
      else
1051
209k
  {
1052
209k
    struct comdat_hash_entry *entry = *slot;
1053
1054
209k
    if (entry->comdat_symbol != -1)
1055
182k
      continue;
1056
1057
26.6k
    char *target_name = strchr (entry->symname, '$');
1058
26.6k
    if (target_name != NULL)
1059
1.25k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
1.25k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
1.25k
        if (strcmp (target_name,
1068
1.25k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
869
    {
1070
      /* Not the name we're looking for */
1071
869
      continue;
1072
869
    }
1073
1.25k
      }
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
25.7k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
25.7k
    entry->comdat_name = bfd_strdup (symname);
1082
25.7k
  }
1083
335k
    }
1084
1085
16.5k
  return true;
1086
16.5k
}
pe-x86_64.c:fill_comdat_hash
Line
Count
Source
890
56.4k
{
891
56.4k
  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
56.4k
  if (! _bfd_coff_get_external_symbols (abfd))
909
26.9k
    return true;
910
911
29.5k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
29.5k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
29.5k
  for (struct internal_syment isym;
915
385k
       esym < esymend;
916
355k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
355k
    {
918
355k
      char buf[SYMNMLEN + 1];
919
355k
      const char *symname;
920
355k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
355k
      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
355k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
355k
      if (symname == NULL)
949
125k
  {
950
125k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
125k
            abfd);
952
125k
    continue;
953
125k
  }
954
955
229k
      union internal_auxent aux;
956
957
229k
      struct comdat_hash_entry needle;
958
229k
      needle.target_index = isym.n_scnum;
959
960
229k
      void **slot
961
229k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
229k
      if (slot == NULL)
963
0
  return false;
964
965
229k
      if (*slot == NULL)
966
104k
  {
967
104k
    if (isym.n_numaux == 0)
968
49.9k
      aux.x_scn.x_comdat = 0;
969
54.7k
    else
970
54.7k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
54.7k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
12.2k
    {
974
      /* xgettext:c-format */
975
12.2k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
12.2k
          " section '%s' found"),
977
12.2k
              abfd, symname);
978
12.2k
      continue;
979
12.2k
    }
980
42.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
42.4k
            isym.n_type, isym.n_sclass, 0,
982
42.4k
            isym.n_numaux, &aux);
983
42.4k
      }
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
92.4k
    switch (aux.x_scn.x_comdat)
998
92.4k
      {
999
161
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
161
        sec_flags &= ~SEC_LINK_ONCE;
1004
161
#endif
1005
161
        break;
1006
1007
5
      case IMAGE_COMDAT_SELECT_ANY:
1008
5
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
5
        break;
1010
1011
12
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
12
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
12
        break;
1014
1015
12
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
12
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
12
        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
12
      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
12
        sec_flags &= ~SEC_LINK_ONCE;
1031
12
#endif
1032
12
        break;
1033
1034
92.2k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
92.2k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
92.2k
        break;
1038
92.4k
      }
1039
1040
92.4k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
92.4k
    if (*slot == NULL)
1042
0
      return false;
1043
92.4k
    struct comdat_hash_entry *newentry = *slot;
1044
92.4k
    newentry->sec_flags = sec_flags;
1045
92.4k
    newentry->symname = bfd_strdup (symname);
1046
92.4k
    newentry->target_index = isym.n_scnum;
1047
92.4k
    newentry->isym = isym;
1048
92.4k
    newentry->comdat_symbol = -1;
1049
92.4k
  }
1050
125k
      else
1051
125k
  {
1052
125k
    struct comdat_hash_entry *entry = *slot;
1053
1054
125k
    if (entry->comdat_symbol != -1)
1055
109k
      continue;
1056
1057
15.5k
    char *target_name = strchr (entry->symname, '$');
1058
15.5k
    if (target_name != NULL)
1059
160
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
160
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
160
        if (strcmp (target_name,
1068
160
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
150
    {
1070
      /* Not the name we're looking for */
1071
150
      continue;
1072
150
    }
1073
160
      }
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.4k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
15.4k
    entry->comdat_name = bfd_strdup (symname);
1082
15.4k
  }
1083
229k
    }
1084
1085
29.5k
  return true;
1086
29.5k
}
pei-x86_64.c:fill_comdat_hash
Line
Count
Source
890
36.0k
{
891
36.0k
  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
36.0k
  if (! _bfd_coff_get_external_symbols (abfd))
909
15.8k
    return true;
910
911
20.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
20.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
20.1k
  for (struct internal_syment isym;
915
567k
       esym < esymend;
916
547k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
547k
    {
918
547k
      char buf[SYMNMLEN + 1];
919
547k
      const char *symname;
920
547k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
547k
      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
547k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
547k
      if (symname == NULL)
949
159k
  {
950
159k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
159k
            abfd);
952
159k
    continue;
953
159k
  }
954
955
387k
      union internal_auxent aux;
956
957
387k
      struct comdat_hash_entry needle;
958
387k
      needle.target_index = isym.n_scnum;
959
960
387k
      void **slot
961
387k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
387k
      if (slot == NULL)
963
0
  return false;
964
965
387k
      if (*slot == NULL)
966
200k
  {
967
200k
    if (isym.n_numaux == 0)
968
71.2k
      aux.x_scn.x_comdat = 0;
969
128k
    else
970
128k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
128k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
8.02k
    {
974
      /* xgettext:c-format */
975
8.02k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
8.02k
          " section '%s' found"),
977
8.02k
              abfd, symname);
978
8.02k
      continue;
979
8.02k
    }
980
120k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
120k
            isym.n_type, isym.n_sclass, 0,
982
120k
            isym.n_numaux, &aux);
983
120k
      }
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
192k
    switch (aux.x_scn.x_comdat)
998
192k
      {
999
795
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
795
        sec_flags &= ~SEC_LINK_ONCE;
1004
795
#endif
1005
795
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
410
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
410
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
410
        break;
1014
1015
265
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
265
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
265
        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
360
      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
360
        sec_flags &= ~SEC_LINK_ONCE;
1031
360
#endif
1032
360
        break;
1033
1034
190k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
190k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
190k
        break;
1038
192k
      }
1039
1040
192k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
192k
    if (*slot == NULL)
1042
0
      return false;
1043
192k
    struct comdat_hash_entry *newentry = *slot;
1044
192k
    newentry->sec_flags = sec_flags;
1045
192k
    newentry->symname = bfd_strdup (symname);
1046
192k
    newentry->target_index = isym.n_scnum;
1047
192k
    newentry->isym = isym;
1048
192k
    newentry->comdat_symbol = -1;
1049
192k
  }
1050
187k
      else
1051
187k
  {
1052
187k
    struct comdat_hash_entry *entry = *slot;
1053
1054
187k
    if (entry->comdat_symbol != -1)
1055
162k
      continue;
1056
1057
25.5k
    char *target_name = strchr (entry->symname, '$');
1058
25.5k
    if (target_name != NULL)
1059
1.51k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
1.51k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
1.51k
        if (strcmp (target_name,
1068
1.51k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
1.40k
    {
1070
      /* Not the name we're looking for */
1071
1.40k
      continue;
1072
1.40k
    }
1073
1.51k
      }
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
24.1k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
24.1k
    entry->comdat_name = bfd_strdup (symname);
1082
24.1k
  }
1083
387k
    }
1084
1085
20.1k
  return true;
1086
20.1k
}
pe-aarch64.c:fill_comdat_hash
Line
Count
Source
890
14.4k
{
891
14.4k
  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
14.4k
  if (! _bfd_coff_get_external_symbols (abfd))
909
5.17k
    return true;
910
911
9.25k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
9.25k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
9.25k
  for (struct internal_syment isym;
915
160k
       esym < esymend;
916
151k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
151k
    {
918
151k
      char buf[SYMNMLEN + 1];
919
151k
      const char *symname;
920
151k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
151k
      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
151k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
151k
      if (symname == NULL)
949
13.6k
  {
950
13.6k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
13.6k
            abfd);
952
13.6k
    continue;
953
13.6k
  }
954
955
137k
      union internal_auxent aux;
956
957
137k
      struct comdat_hash_entry needle;
958
137k
      needle.target_index = isym.n_scnum;
959
960
137k
      void **slot
961
137k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
137k
      if (slot == NULL)
963
0
  return false;
964
965
137k
      if (*slot == NULL)
966
21.4k
  {
967
21.4k
    if (isym.n_numaux == 0)
968
10.9k
      aux.x_scn.x_comdat = 0;
969
10.5k
    else
970
10.5k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
10.5k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
4.31k
    {
974
      /* xgettext:c-format */
975
4.31k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
4.31k
          " section '%s' found"),
977
4.31k
              abfd, symname);
978
4.31k
      continue;
979
4.31k
    }
980
6.24k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
6.24k
            isym.n_type, isym.n_sclass, 0,
982
6.24k
            isym.n_numaux, &aux);
983
6.24k
      }
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.1k
    switch (aux.x_scn.x_comdat)
998
17.1k
      {
999
8
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
8
        sec_flags &= ~SEC_LINK_ONCE;
1004
8
#endif
1005
8
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
7
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
7
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
7
        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.1k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
17.1k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
17.1k
        break;
1038
17.1k
      }
1039
1040
17.1k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
17.1k
    if (*slot == NULL)
1042
0
      return false;
1043
17.1k
    struct comdat_hash_entry *newentry = *slot;
1044
17.1k
    newentry->sec_flags = sec_flags;
1045
17.1k
    newentry->symname = bfd_strdup (symname);
1046
17.1k
    newentry->target_index = isym.n_scnum;
1047
17.1k
    newentry->isym = isym;
1048
17.1k
    newentry->comdat_symbol = -1;
1049
17.1k
  }
1050
116k
      else
1051
116k
  {
1052
116k
    struct comdat_hash_entry *entry = *slot;
1053
1054
116k
    if (entry->comdat_symbol != -1)
1055
111k
      continue;
1056
1057
4.35k
    char *target_name = strchr (entry->symname, '$');
1058
4.35k
    if (target_name != NULL)
1059
384
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
384
        target_name += 1;
1063
384
#ifndef TARGET_UNDERSCORE
1064
384
#define TARGET_UNDERSCORE 0
1065
384
#endif
1066
        /* Is this the name we're looking for ?  */
1067
384
        if (strcmp (target_name,
1068
384
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
381
    {
1070
      /* Not the name we're looking for */
1071
381
      continue;
1072
381
    }
1073
384
      }
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
3.97k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
3.97k
    entry->comdat_name = bfd_strdup (symname);
1082
3.97k
  }
1083
137k
    }
1084
1085
9.25k
  return true;
1086
9.25k
}
pei-aarch64.c:fill_comdat_hash
Line
Count
Source
890
27.9k
{
891
27.9k
  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
27.9k
  if (! _bfd_coff_get_external_symbols (abfd))
909
6.93k
    return true;
910
911
21.0k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
21.0k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
21.0k
  for (struct internal_syment isym;
915
1.32M
       esym < esymend;
916
1.30M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
1.30M
    {
918
1.30M
      char buf[SYMNMLEN + 1];
919
1.30M
      const char *symname;
920
1.30M
      flagword sec_flags = SEC_LINK_ONCE;
921
922
1.30M
      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.30M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
1.30M
      if (symname == NULL)
949
331k
  {
950
331k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
331k
            abfd);
952
331k
    continue;
953
331k
  }
954
955
971k
      union internal_auxent aux;
956
957
971k
      struct comdat_hash_entry needle;
958
971k
      needle.target_index = isym.n_scnum;
959
960
971k
      void **slot
961
971k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
971k
      if (slot == NULL)
963
0
  return false;
964
965
971k
      if (*slot == NULL)
966
238k
  {
967
238k
    if (isym.n_numaux == 0)
968
93.1k
      aux.x_scn.x_comdat = 0;
969
145k
    else
970
145k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
145k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
6.02k
    {
974
      /* xgettext:c-format */
975
6.02k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
6.02k
          " section '%s' found"),
977
6.02k
              abfd, symname);
978
6.02k
      continue;
979
6.02k
    }
980
139k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
139k
            isym.n_type, isym.n_sclass, 0,
982
139k
            isym.n_numaux, &aux);
983
139k
      }
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
232k
    switch (aux.x_scn.x_comdat)
998
232k
      {
999
1.26k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
1.26k
        sec_flags &= ~SEC_LINK_ONCE;
1004
1.26k
#endif
1005
1.26k
        break;
1006
1007
3
      case IMAGE_COMDAT_SELECT_ANY:
1008
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
3
        break;
1010
1011
4
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
4
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
4
        break;
1014
1015
1.23k
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
1.23k
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
1.23k
        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
16
      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
16
        sec_flags &= ~SEC_LINK_ONCE;
1031
16
#endif
1032
16
        break;
1033
1034
230k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
230k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
230k
        break;
1038
232k
      }
1039
1040
232k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
232k
    if (*slot == NULL)
1042
0
      return false;
1043
232k
    struct comdat_hash_entry *newentry = *slot;
1044
232k
    newentry->sec_flags = sec_flags;
1045
232k
    newentry->symname = bfd_strdup (symname);
1046
232k
    newentry->target_index = isym.n_scnum;
1047
232k
    newentry->isym = isym;
1048
232k
    newentry->comdat_symbol = -1;
1049
232k
  }
1050
732k
      else
1051
732k
  {
1052
732k
    struct comdat_hash_entry *entry = *slot;
1053
1054
732k
    if (entry->comdat_symbol != -1)
1055
692k
      continue;
1056
1057
39.4k
    char *target_name = strchr (entry->symname, '$');
1058
39.4k
    if (target_name != NULL)
1059
1.25k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
1.25k
        target_name += 1;
1063
1.25k
#ifndef TARGET_UNDERSCORE
1064
1.25k
#define TARGET_UNDERSCORE 0
1065
1.25k
#endif
1066
        /* Is this the name we're looking for ?  */
1067
1.25k
        if (strcmp (target_name,
1068
1.25k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
1.24k
    {
1070
      /* Not the name we're looking for */
1071
1.24k
      continue;
1072
1.24k
    }
1073
1.25k
      }
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
38.2k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
38.2k
    entry->comdat_name = bfd_strdup (symname);
1082
38.2k
  }
1083
971k
    }
1084
1085
21.0k
  return true;
1086
21.0k
}
pei-ia64.c:fill_comdat_hash
Line
Count
Source
890
34.0k
{
891
34.0k
  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
34.0k
  if (! _bfd_coff_get_external_symbols (abfd))
909
13.8k
    return true;
910
911
20.2k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
20.2k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
20.2k
  for (struct internal_syment isym;
915
690k
       esym < esymend;
916
670k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
670k
    {
918
670k
      char buf[SYMNMLEN + 1];
919
670k
      const char *symname;
920
670k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
670k
      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
670k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
670k
      if (symname == NULL)
949
173k
  {
950
173k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
173k
            abfd);
952
173k
    continue;
953
173k
  }
954
955
496k
      union internal_auxent aux;
956
957
496k
      struct comdat_hash_entry needle;
958
496k
      needle.target_index = isym.n_scnum;
959
960
496k
      void **slot
961
496k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
496k
      if (slot == NULL)
963
0
  return false;
964
965
496k
      if (*slot == NULL)
966
204k
  {
967
204k
    if (isym.n_numaux == 0)
968
75.5k
      aux.x_scn.x_comdat = 0;
969
128k
    else
970
128k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
128k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
6.31k
    {
974
      /* xgettext:c-format */
975
6.31k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
6.31k
          " section '%s' found"),
977
6.31k
              abfd, symname);
978
6.31k
      continue;
979
6.31k
    }
980
122k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
122k
            isym.n_type, isym.n_sclass, 0,
982
122k
            isym.n_numaux, &aux);
983
122k
      }
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
198k
    switch (aux.x_scn.x_comdat)
998
198k
      {
999
292
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
292
        sec_flags &= ~SEC_LINK_ONCE;
1004
292
#endif
1005
292
        break;
1006
1007
3
      case IMAGE_COMDAT_SELECT_ANY:
1008
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
3
        break;
1010
1011
126
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
126
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
126
        break;
1014
1015
464
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
464
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
464
        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
246
      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
246
        sec_flags &= ~SEC_LINK_ONCE;
1031
246
#endif
1032
246
        break;
1033
1034
196k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
196k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
196k
        break;
1038
198k
      }
1039
1040
198k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
198k
    if (*slot == NULL)
1042
0
      return false;
1043
198k
    struct comdat_hash_entry *newentry = *slot;
1044
198k
    newentry->sec_flags = sec_flags;
1045
198k
    newentry->symname = bfd_strdup (symname);
1046
198k
    newentry->target_index = isym.n_scnum;
1047
198k
    newentry->isym = isym;
1048
198k
    newentry->comdat_symbol = -1;
1049
198k
  }
1050
292k
      else
1051
292k
  {
1052
292k
    struct comdat_hash_entry *entry = *slot;
1053
1054
292k
    if (entry->comdat_symbol != -1)
1055
265k
      continue;
1056
1057
26.5k
    char *target_name = strchr (entry->symname, '$');
1058
26.5k
    if (target_name != NULL)
1059
1.88k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
1.88k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
1.88k
        if (strcmp (target_name,
1068
1.88k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
1.40k
    {
1070
      /* Not the name we're looking for */
1071
1.40k
      continue;
1072
1.40k
    }
1073
1.88k
      }
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
25.0k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
25.0k
    entry->comdat_name = bfd_strdup (symname);
1082
25.0k
  }
1083
496k
    }
1084
1085
20.2k
  return true;
1086
20.2k
}
pei-loongarch64.c:fill_comdat_hash
Line
Count
Source
890
23.7k
{
891
23.7k
  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.7k
  if (! _bfd_coff_get_external_symbols (abfd))
909
10.5k
    return true;
910
911
13.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
13.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
13.1k
  for (struct internal_syment isym;
915
176k
       esym < esymend;
916
163k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
163k
    {
918
163k
      char buf[SYMNMLEN + 1];
919
163k
      const char *symname;
920
163k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
163k
      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
163k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
163k
      if (symname == NULL)
949
44.5k
  {
950
44.5k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
44.5k
            abfd);
952
44.5k
    continue;
953
44.5k
  }
954
955
118k
      union internal_auxent aux;
956
957
118k
      struct comdat_hash_entry needle;
958
118k
      needle.target_index = isym.n_scnum;
959
960
118k
      void **slot
961
118k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
118k
      if (slot == NULL)
963
0
  return false;
964
965
118k
      if (*slot == NULL)
966
44.3k
  {
967
44.3k
    if (isym.n_numaux == 0)
968
26.8k
      aux.x_scn.x_comdat = 0;
969
17.4k
    else
970
17.4k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
17.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
4.00k
    {
974
      /* xgettext:c-format */
975
4.00k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
4.00k
          " section '%s' found"),
977
4.00k
              abfd, symname);
978
4.00k
      continue;
979
4.00k
    }
980
13.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
13.4k
            isym.n_type, isym.n_sclass, 0,
982
13.4k
            isym.n_numaux, &aux);
983
13.4k
      }
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.2k
    switch (aux.x_scn.x_comdat)
998
40.2k
      {
999
56
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
56
        sec_flags &= ~SEC_LINK_ONCE;
1004
56
#endif
1005
56
        break;
1006
1007
2
      case IMAGE_COMDAT_SELECT_ANY:
1008
2
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
2
        break;
1010
1011
35
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
35
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
35
        break;
1014
1015
17
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
17
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
17
        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
6
      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
6
        sec_flags &= ~SEC_LINK_ONCE;
1031
6
#endif
1032
6
        break;
1033
1034
40.1k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
40.1k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
40.1k
        break;
1038
40.2k
      }
1039
1040
40.2k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
40.2k
    if (*slot == NULL)
1042
0
      return false;
1043
40.2k
    struct comdat_hash_entry *newentry = *slot;
1044
40.2k
    newentry->sec_flags = sec_flags;
1045
40.2k
    newentry->symname = bfd_strdup (symname);
1046
40.2k
    newentry->target_index = isym.n_scnum;
1047
40.2k
    newentry->isym = isym;
1048
40.2k
    newentry->comdat_symbol = -1;
1049
40.2k
  }
1050
74.5k
      else
1051
74.5k
  {
1052
74.5k
    struct comdat_hash_entry *entry = *slot;
1053
1054
74.5k
    if (entry->comdat_symbol != -1)
1055
63.9k
      continue;
1056
1057
10.5k
    char *target_name = strchr (entry->symname, '$');
1058
10.5k
    if (target_name != NULL)
1059
675
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
675
        target_name += 1;
1063
675
#ifndef TARGET_UNDERSCORE
1064
675
#define TARGET_UNDERSCORE 0
1065
675
#endif
1066
        /* Is this the name we're looking for ?  */
1067
675
        if (strcmp (target_name,
1068
675
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
669
    {
1070
      /* Not the name we're looking for */
1071
669
      continue;
1072
669
    }
1073
675
      }
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
9.89k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
9.89k
    entry->comdat_name = bfd_strdup (symname);
1082
9.89k
  }
1083
118k
    }
1084
1085
13.1k
  return true;
1086
13.1k
}
pe-arm-wince.c:fill_comdat_hash
Line
Count
Source
890
9.29k
{
891
9.29k
  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
9.29k
  if (! _bfd_coff_get_external_symbols (abfd))
909
2.91k
    return true;
910
911
6.38k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
6.38k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
6.38k
  for (struct internal_syment isym;
915
476k
       esym < esymend;
916
470k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
470k
    {
918
470k
      char buf[SYMNMLEN + 1];
919
470k
      const char *symname;
920
470k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
470k
      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
470k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
470k
      if (symname == NULL)
949
46.8k
  {
950
46.8k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
46.8k
            abfd);
952
46.8k
    continue;
953
46.8k
  }
954
955
423k
      union internal_auxent aux;
956
957
423k
      struct comdat_hash_entry needle;
958
423k
      needle.target_index = isym.n_scnum;
959
960
423k
      void **slot
961
423k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
423k
      if (slot == NULL)
963
0
  return false;
964
965
423k
      if (*slot == NULL)
966
62.0k
  {
967
62.0k
    if (isym.n_numaux == 0)
968
17.6k
      aux.x_scn.x_comdat = 0;
969
44.4k
    else
970
44.4k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
44.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
1.75k
    {
974
      /* xgettext:c-format */
975
1.75k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
1.75k
          " section '%s' found"),
977
1.75k
              abfd, symname);
978
1.75k
      continue;
979
1.75k
    }
980
42.6k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
42.6k
            isym.n_type, isym.n_sclass, 0,
982
42.6k
            isym.n_numaux, &aux);
983
42.6k
      }
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
60.3k
    switch (aux.x_scn.x_comdat)
998
60.3k
      {
999
422
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
422
        sec_flags &= ~SEC_LINK_ONCE;
1004
422
#endif
1005
422
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
6
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
6
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
6
        break;
1014
1015
3
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
3
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
3
        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
59.8k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
59.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
59.8k
        break;
1038
60.3k
      }
1039
1040
60.3k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
60.3k
    if (*slot == NULL)
1042
0
      return false;
1043
60.3k
    struct comdat_hash_entry *newentry = *slot;
1044
60.3k
    newentry->sec_flags = sec_flags;
1045
60.3k
    newentry->symname = bfd_strdup (symname);
1046
60.3k
    newentry->target_index = isym.n_scnum;
1047
60.3k
    newentry->isym = isym;
1048
60.3k
    newentry->comdat_symbol = -1;
1049
60.3k
  }
1050
361k
      else
1051
361k
  {
1052
361k
    struct comdat_hash_entry *entry = *slot;
1053
1054
361k
    if (entry->comdat_symbol != -1)
1055
353k
      continue;
1056
1057
8.10k
    char *target_name = strchr (entry->symname, '$');
1058
8.10k
    if (target_name != NULL)
1059
539
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
539
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
539
        if (strcmp (target_name,
1068
539
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
538
    {
1070
      /* Not the name we're looking for */
1071
538
      continue;
1072
538
    }
1073
539
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
7.56k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
7.56k
    entry->comdat_name = bfd_strdup (symname);
1082
7.56k
  }
1083
423k
    }
1084
1085
6.38k
  return true;
1086
6.38k
}
pe-arm.c:fill_comdat_hash
Line
Count
Source
890
9.29k
{
891
9.29k
  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
9.29k
  if (! _bfd_coff_get_external_symbols (abfd))
909
2.91k
    return true;
910
911
6.38k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
6.38k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
6.38k
  for (struct internal_syment isym;
915
476k
       esym < esymend;
916
470k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
470k
    {
918
470k
      char buf[SYMNMLEN + 1];
919
470k
      const char *symname;
920
470k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
470k
      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
470k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
470k
      if (symname == NULL)
949
46.8k
  {
950
46.8k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
46.8k
            abfd);
952
46.8k
    continue;
953
46.8k
  }
954
955
423k
      union internal_auxent aux;
956
957
423k
      struct comdat_hash_entry needle;
958
423k
      needle.target_index = isym.n_scnum;
959
960
423k
      void **slot
961
423k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
423k
      if (slot == NULL)
963
0
  return false;
964
965
423k
      if (*slot == NULL)
966
62.0k
  {
967
62.0k
    if (isym.n_numaux == 0)
968
17.6k
      aux.x_scn.x_comdat = 0;
969
44.4k
    else
970
44.4k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
44.4k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
1.75k
    {
974
      /* xgettext:c-format */
975
1.75k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
1.75k
          " section '%s' found"),
977
1.75k
              abfd, symname);
978
1.75k
      continue;
979
1.75k
    }
980
42.6k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
42.6k
            isym.n_type, isym.n_sclass, 0,
982
42.6k
            isym.n_numaux, &aux);
983
42.6k
      }
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
60.3k
    switch (aux.x_scn.x_comdat)
998
60.3k
      {
999
422
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
422
        sec_flags &= ~SEC_LINK_ONCE;
1004
422
#endif
1005
422
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
6
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
6
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
6
        break;
1014
1015
3
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
3
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
3
        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
59.8k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
59.8k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
59.8k
        break;
1038
60.3k
      }
1039
1040
60.3k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
60.3k
    if (*slot == NULL)
1042
0
      return false;
1043
60.3k
    struct comdat_hash_entry *newentry = *slot;
1044
60.3k
    newentry->sec_flags = sec_flags;
1045
60.3k
    newentry->symname = bfd_strdup (symname);
1046
60.3k
    newentry->target_index = isym.n_scnum;
1047
60.3k
    newentry->isym = isym;
1048
60.3k
    newentry->comdat_symbol = -1;
1049
60.3k
  }
1050
361k
      else
1051
361k
  {
1052
361k
    struct comdat_hash_entry *entry = *slot;
1053
1054
361k
    if (entry->comdat_symbol != -1)
1055
353k
      continue;
1056
1057
8.10k
    char *target_name = strchr (entry->symname, '$');
1058
8.10k
    if (target_name != NULL)
1059
539
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
539
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
539
        if (strcmp (target_name,
1068
539
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
536
    {
1070
      /* Not the name we're looking for */
1071
536
      continue;
1072
536
    }
1073
539
      }
1074
    /* MSVC mode: the lexically second symbol (or drop through
1075
       from the above).  */
1076
    /* This must the second symbol with the section #.  It is
1077
       the actual symbol name.  Intel puts the two adjacent, but
1078
       Alpha (at least) spreads them out.  */
1079
1080
7.56k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
7.56k
    entry->comdat_name = bfd_strdup (symname);
1082
7.56k
  }
1083
423k
    }
1084
1085
6.38k
  return true;
1086
6.38k
}
pe-i386.c:fill_comdat_hash
Line
Count
Source
890
26.6k
{
891
26.6k
  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.6k
  if (! _bfd_coff_get_external_symbols (abfd))
909
13.4k
    return true;
910
911
13.1k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
13.1k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
13.1k
  for (struct internal_syment isym;
915
283k
       esym < esymend;
916
270k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
270k
    {
918
270k
      char buf[SYMNMLEN + 1];
919
270k
      const char *symname;
920
270k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
270k
      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
270k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
270k
      if (symname == NULL)
949
51.7k
  {
950
51.7k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
51.7k
            abfd);
952
51.7k
    continue;
953
51.7k
  }
954
955
219k
      union internal_auxent aux;
956
957
219k
      struct comdat_hash_entry needle;
958
219k
      needle.target_index = isym.n_scnum;
959
960
219k
      void **slot
961
219k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
219k
      if (slot == NULL)
963
0
  return false;
964
965
219k
      if (*slot == NULL)
966
58.8k
  {
967
58.8k
    if (isym.n_numaux == 0)
968
25.1k
      aux.x_scn.x_comdat = 0;
969
33.6k
    else
970
33.6k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
33.6k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
3.52k
    {
974
      /* xgettext:c-format */
975
3.52k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
3.52k
          " section '%s' found"),
977
3.52k
              abfd, symname);
978
3.52k
      continue;
979
3.52k
    }
980
30.1k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
30.1k
            isym.n_type, isym.n_sclass, 0,
982
30.1k
            isym.n_numaux, &aux);
983
30.1k
      }
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
55.2k
    switch (aux.x_scn.x_comdat)
998
55.2k
      {
999
34
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
34
        sec_flags &= ~SEC_LINK_ONCE;
1004
34
#endif
1005
34
        break;
1006
1007
0
      case IMAGE_COMDAT_SELECT_ANY:
1008
0
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
0
        break;
1010
1011
21
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
21
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
21
        break;
1014
1015
120
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
120
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
120
        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
8
      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
8
        sec_flags &= ~SEC_LINK_ONCE;
1031
8
#endif
1032
8
        break;
1033
1034
55.0k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
55.0k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
55.0k
        break;
1038
55.2k
      }
1039
1040
55.2k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
55.2k
    if (*slot == NULL)
1042
0
      return false;
1043
55.2k
    struct comdat_hash_entry *newentry = *slot;
1044
55.2k
    newentry->sec_flags = sec_flags;
1045
55.2k
    newentry->symname = bfd_strdup (symname);
1046
55.2k
    newentry->target_index = isym.n_scnum;
1047
55.2k
    newentry->isym = isym;
1048
55.2k
    newentry->comdat_symbol = -1;
1049
55.2k
  }
1050
160k
      else
1051
160k
  {
1052
160k
    struct comdat_hash_entry *entry = *slot;
1053
1054
160k
    if (entry->comdat_symbol != -1)
1055
151k
      continue;
1056
1057
9.00k
    char *target_name = strchr (entry->symname, '$');
1058
9.00k
    if (target_name != NULL)
1059
869
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
869
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
869
        if (strcmp (target_name,
1068
869
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
760
    {
1070
      /* Not the name we're looking for */
1071
760
      continue;
1072
760
    }
1073
869
      }
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.24k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
8.24k
    entry->comdat_name = bfd_strdup (symname);
1082
8.24k
  }
1083
219k
    }
1084
1085
13.1k
  return true;
1086
13.1k
}
pe-mcore.c:fill_comdat_hash
Line
Count
Source
890
15.3k
{
891
15.3k
  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
15.3k
  if (! _bfd_coff_get_external_symbols (abfd))
909
4.60k
    return true;
910
911
10.7k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
10.7k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
10.7k
  for (struct internal_syment isym;
915
2.25M
       esym < esymend;
916
2.24M
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
2.24M
    {
918
2.24M
      char buf[SYMNMLEN + 1];
919
2.24M
      const char *symname;
920
2.24M
      flagword sec_flags = SEC_LINK_ONCE;
921
922
2.24M
      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.24M
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
2.24M
      if (symname == NULL)
949
19.0k
  {
950
19.0k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
19.0k
            abfd);
952
19.0k
    continue;
953
19.0k
  }
954
955
2.22M
      union internal_auxent aux;
956
957
2.22M
      struct comdat_hash_entry needle;
958
2.22M
      needle.target_index = isym.n_scnum;
959
960
2.22M
      void **slot
961
2.22M
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
2.22M
      if (slot == NULL)
963
0
  return false;
964
965
2.22M
      if (*slot == NULL)
966
18.6k
  {
967
18.6k
    if (isym.n_numaux == 0)
968
8.28k
      aux.x_scn.x_comdat = 0;
969
10.3k
    else
970
10.3k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
10.3k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
3.85k
    {
974
      /* xgettext:c-format */
975
3.85k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
3.85k
          " section '%s' found"),
977
3.85k
              abfd, symname);
978
3.85k
      continue;
979
3.85k
    }
980
6.53k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
6.53k
            isym.n_type, isym.n_sclass, 0,
982
6.53k
            isym.n_numaux, &aux);
983
6.53k
      }
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
14.8k
    switch (aux.x_scn.x_comdat)
998
14.8k
      {
999
105
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
105
        sec_flags &= ~SEC_LINK_ONCE;
1004
105
#endif
1005
105
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
3
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
3
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
3
        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
14.7k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
14.7k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
14.7k
        break;
1038
14.8k
      }
1039
1040
14.8k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
14.8k
    if (*slot == NULL)
1042
0
      return false;
1043
14.8k
    struct comdat_hash_entry *newentry = *slot;
1044
14.8k
    newentry->sec_flags = sec_flags;
1045
14.8k
    newentry->symname = bfd_strdup (symname);
1046
14.8k
    newentry->target_index = isym.n_scnum;
1047
14.8k
    newentry->isym = isym;
1048
14.8k
    newentry->comdat_symbol = -1;
1049
14.8k
  }
1050
2.20M
      else
1051
2.20M
  {
1052
2.20M
    struct comdat_hash_entry *entry = *slot;
1053
1054
2.20M
    if (entry->comdat_symbol != -1)
1055
2.19M
      continue;
1056
1057
5.04k
    char *target_name = strchr (entry->symname, '$');
1058
5.04k
    if (target_name != NULL)
1059
2.42k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
2.42k
        target_name += 1;
1063
2.42k
#ifndef TARGET_UNDERSCORE
1064
2.42k
#define TARGET_UNDERSCORE 0
1065
2.42k
#endif
1066
        /* Is this the name we're looking for ?  */
1067
2.42k
        if (strcmp (target_name,
1068
2.42k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
2.42k
    {
1070
      /* Not the name we're looking for */
1071
2.42k
      continue;
1072
2.42k
    }
1073
2.42k
      }
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.62k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
2.62k
    entry->comdat_name = bfd_strdup (symname);
1082
2.62k
  }
1083
2.22M
    }
1084
1085
10.7k
  return true;
1086
10.7k
}
pe-sh.c:fill_comdat_hash
Line
Count
Source
890
24.2k
{
891
24.2k
  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
24.2k
  if (! _bfd_coff_get_external_symbols (abfd))
909
10.5k
    return true;
910
911
13.6k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
13.6k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
13.6k
  for (struct internal_syment isym;
915
959k
       esym < esymend;
916
945k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
945k
    {
918
945k
      char buf[SYMNMLEN + 1];
919
945k
      const char *symname;
920
945k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
945k
      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
945k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
945k
      if (symname == NULL)
949
210k
  {
950
210k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
210k
            abfd);
952
210k
    continue;
953
210k
  }
954
955
735k
      union internal_auxent aux;
956
957
735k
      struct comdat_hash_entry needle;
958
735k
      needle.target_index = isym.n_scnum;
959
960
735k
      void **slot
961
735k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
735k
      if (slot == NULL)
963
0
  return false;
964
965
735k
      if (*slot == NULL)
966
128k
  {
967
128k
    if (isym.n_numaux == 0)
968
55.4k
      aux.x_scn.x_comdat = 0;
969
73.1k
    else
970
73.1k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
73.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
4.39k
    {
974
      /* xgettext:c-format */
975
4.39k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
4.39k
          " section '%s' found"),
977
4.39k
              abfd, symname);
978
4.39k
      continue;
979
4.39k
    }
980
68.7k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
68.7k
            isym.n_type, isym.n_sclass, 0,
982
68.7k
            isym.n_numaux, &aux);
983
68.7k
      }
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
124k
    switch (aux.x_scn.x_comdat)
998
124k
      {
999
343
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
343
        sec_flags &= ~SEC_LINK_ONCE;
1004
343
#endif
1005
343
        break;
1006
1007
2
      case IMAGE_COMDAT_SELECT_ANY:
1008
2
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
2
        break;
1010
1011
111
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
111
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
111
        break;
1014
1015
513
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
513
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
513
        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
7
      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
7
        sec_flags &= ~SEC_LINK_ONCE;
1031
7
#endif
1032
7
        break;
1033
1034
123k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
123k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
123k
        break;
1038
124k
      }
1039
1040
124k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
124k
    if (*slot == NULL)
1042
0
      return false;
1043
124k
    struct comdat_hash_entry *newentry = *slot;
1044
124k
    newentry->sec_flags = sec_flags;
1045
124k
    newentry->symname = bfd_strdup (symname);
1046
124k
    newentry->target_index = isym.n_scnum;
1047
124k
    newentry->isym = isym;
1048
124k
    newentry->comdat_symbol = -1;
1049
124k
  }
1050
606k
      else
1051
606k
  {
1052
606k
    struct comdat_hash_entry *entry = *slot;
1053
1054
606k
    if (entry->comdat_symbol != -1)
1055
581k
      continue;
1056
1057
24.9k
    char *target_name = strchr (entry->symname, '$');
1058
24.9k
    if (target_name != NULL)
1059
850
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
850
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
850
        if (strcmp (target_name,
1068
850
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
830
    {
1070
      /* Not the name we're looking for */
1071
830
      continue;
1072
830
    }
1073
850
      }
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
24.1k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
24.1k
    entry->comdat_name = bfd_strdup (symname);
1082
24.1k
  }
1083
735k
    }
1084
1085
13.6k
  return true;
1086
13.6k
}
pei-arm-wince.c:fill_comdat_hash
Line
Count
Source
890
38.2k
{
891
38.2k
  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
38.2k
  if (! _bfd_coff_get_external_symbols (abfd))
909
17.7k
    return true;
910
911
20.4k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
20.4k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
20.4k
  for (struct internal_syment isym;
915
299k
       esym < esymend;
916
278k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
278k
    {
918
278k
      char buf[SYMNMLEN + 1];
919
278k
      const char *symname;
920
278k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
278k
      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
278k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
278k
      if (symname == NULL)
949
79.6k
  {
950
79.6k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
79.6k
            abfd);
952
79.6k
    continue;
953
79.6k
  }
954
955
199k
      union internal_auxent aux;
956
957
199k
      struct comdat_hash_entry needle;
958
199k
      needle.target_index = isym.n_scnum;
959
960
199k
      void **slot
961
199k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
199k
      if (slot == NULL)
963
0
  return false;
964
965
199k
      if (*slot == NULL)
966
83.2k
  {
967
83.2k
    if (isym.n_numaux == 0)
968
34.0k
      aux.x_scn.x_comdat = 0;
969
49.2k
    else
970
49.2k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
49.2k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
5.78k
    {
974
      /* xgettext:c-format */
975
5.78k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
5.78k
          " section '%s' found"),
977
5.78k
              abfd, symname);
978
5.78k
      continue;
979
5.78k
    }
980
43.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
43.4k
            isym.n_type, isym.n_sclass, 0,
982
43.4k
            isym.n_numaux, &aux);
983
43.4k
      }
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
77.4k
    switch (aux.x_scn.x_comdat)
998
77.4k
      {
999
1.00k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
1.00k
        sec_flags &= ~SEC_LINK_ONCE;
1004
1.00k
#endif
1005
1.00k
        break;
1006
1007
2
      case IMAGE_COMDAT_SELECT_ANY:
1008
2
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
2
        break;
1010
1011
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
5
        break;
1014
1015
400
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
400
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
400
        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
3
      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
3
        sec_flags &= ~SEC_LINK_ONCE;
1031
3
#endif
1032
3
        break;
1033
1034
76.0k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
76.0k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
76.0k
        break;
1038
77.4k
      }
1039
1040
77.4k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
77.4k
    if (*slot == NULL)
1042
0
      return false;
1043
77.4k
    struct comdat_hash_entry *newentry = *slot;
1044
77.4k
    newentry->sec_flags = sec_flags;
1045
77.4k
    newentry->symname = bfd_strdup (symname);
1046
77.4k
    newentry->target_index = isym.n_scnum;
1047
77.4k
    newentry->isym = isym;
1048
77.4k
    newentry->comdat_symbol = -1;
1049
77.4k
  }
1050
115k
      else
1051
115k
  {
1052
115k
    struct comdat_hash_entry *entry = *slot;
1053
1054
115k
    if (entry->comdat_symbol != -1)
1055
102k
      continue;
1056
1057
13.8k
    char *target_name = strchr (entry->symname, '$');
1058
13.8k
    if (target_name != NULL)
1059
2.67k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
2.67k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
2.67k
        if (strcmp (target_name,
1068
2.67k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
1.87k
    {
1070
      /* Not the name we're looking for */
1071
1.87k
      continue;
1072
1.87k
    }
1073
2.67k
      }
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
11.9k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
11.9k
    entry->comdat_name = bfd_strdup (symname);
1082
11.9k
  }
1083
199k
    }
1084
1085
20.4k
  return true;
1086
20.4k
}
pei-arm.c:fill_comdat_hash
Line
Count
Source
890
49.9k
{
891
49.9k
  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
49.9k
  if (! _bfd_coff_get_external_symbols (abfd))
909
22.6k
    return true;
910
911
27.3k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
27.3k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
27.3k
  for (struct internal_syment isym;
915
336k
       esym < esymend;
916
308k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
308k
    {
918
308k
      char buf[SYMNMLEN + 1];
919
308k
      const char *symname;
920
308k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
308k
      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
308k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
308k
      if (symname == NULL)
949
89.3k
  {
950
89.3k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
89.3k
            abfd);
952
89.3k
    continue;
953
89.3k
  }
954
955
219k
      union internal_auxent aux;
956
957
219k
      struct comdat_hash_entry needle;
958
219k
      needle.target_index = isym.n_scnum;
959
960
219k
      void **slot
961
219k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
219k
      if (slot == NULL)
963
0
  return false;
964
965
219k
      if (*slot == NULL)
966
89.5k
  {
967
89.5k
    if (isym.n_numaux == 0)
968
38.5k
      aux.x_scn.x_comdat = 0;
969
51.0k
    else
970
51.0k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
51.0k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
6.59k
    {
974
      /* xgettext:c-format */
975
6.59k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
6.59k
          " section '%s' found"),
977
6.59k
              abfd, symname);
978
6.59k
      continue;
979
6.59k
    }
980
44.4k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
44.4k
            isym.n_type, isym.n_sclass, 0,
982
44.4k
            isym.n_numaux, &aux);
983
44.4k
      }
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
82.9k
    switch (aux.x_scn.x_comdat)
998
82.9k
      {
999
1.01k
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
1.01k
        sec_flags &= ~SEC_LINK_ONCE;
1004
1.01k
#endif
1005
1.01k
        break;
1006
1007
3
      case IMAGE_COMDAT_SELECT_ANY:
1008
3
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
3
        break;
1010
1011
5
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
5
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
5
        break;
1014
1015
400
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
400
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
400
        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
3
      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
3
        sec_flags &= ~SEC_LINK_ONCE;
1031
3
#endif
1032
3
        break;
1033
1034
81.5k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
81.5k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
81.5k
        break;
1038
82.9k
      }
1039
1040
82.9k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
82.9k
    if (*slot == NULL)
1042
0
      return false;
1043
82.9k
    struct comdat_hash_entry *newentry = *slot;
1044
82.9k
    newentry->sec_flags = sec_flags;
1045
82.9k
    newentry->symname = bfd_strdup (symname);
1046
82.9k
    newentry->target_index = isym.n_scnum;
1047
82.9k
    newentry->isym = isym;
1048
82.9k
    newentry->comdat_symbol = -1;
1049
82.9k
  }
1050
129k
      else
1051
129k
  {
1052
129k
    struct comdat_hash_entry *entry = *slot;
1053
1054
129k
    if (entry->comdat_symbol != -1)
1055
114k
      continue;
1056
1057
15.3k
    char *target_name = strchr (entry->symname, '$');
1058
15.3k
    if (target_name != NULL)
1059
2.80k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
2.80k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
2.80k
        if (strcmp (target_name,
1068
2.80k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
1.65k
    {
1070
      /* Not the name we're looking for */
1071
1.65k
      continue;
1072
1.65k
    }
1073
2.80k
      }
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.6k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
13.6k
    entry->comdat_name = bfd_strdup (symname);
1082
13.6k
  }
1083
219k
    }
1084
1085
27.3k
  return true;
1086
27.3k
}
pei-mcore.c:fill_comdat_hash
Line
Count
Source
890
25.1k
{
891
25.1k
  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
25.1k
  if (! _bfd_coff_get_external_symbols (abfd))
909
9.31k
    return true;
910
911
15.8k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
15.8k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
15.8k
  for (struct internal_syment isym;
915
136k
       esym < esymend;
916
120k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
120k
    {
918
120k
      char buf[SYMNMLEN + 1];
919
120k
      const char *symname;
920
120k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
120k
      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
120k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
120k
      if (symname == NULL)
949
31.7k
  {
950
31.7k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
31.7k
            abfd);
952
31.7k
    continue;
953
31.7k
  }
954
955
88.7k
      union internal_auxent aux;
956
957
88.7k
      struct comdat_hash_entry needle;
958
88.7k
      needle.target_index = isym.n_scnum;
959
960
88.7k
      void **slot
961
88.7k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
88.7k
      if (slot == NULL)
963
0
  return false;
964
965
88.7k
      if (*slot == NULL)
966
30.6k
  {
967
30.6k
    if (isym.n_numaux == 0)
968
15.8k
      aux.x_scn.x_comdat = 0;
969
14.8k
    else
970
14.8k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
14.8k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
3.89k
    {
974
      /* xgettext:c-format */
975
3.89k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
3.89k
          " section '%s' found"),
977
3.89k
              abfd, symname);
978
3.89k
      continue;
979
3.89k
    }
980
10.9k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
10.9k
            isym.n_type, isym.n_sclass, 0,
982
10.9k
            isym.n_numaux, &aux);
983
10.9k
      }
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
26.7k
    switch (aux.x_scn.x_comdat)
998
26.7k
      {
999
855
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
855
        sec_flags &= ~SEC_LINK_ONCE;
1004
855
#endif
1005
855
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
24
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
24
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
24
        break;
1014
1015
30
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
30
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
30
        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
239
      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
239
        sec_flags &= ~SEC_LINK_ONCE;
1031
239
#endif
1032
239
        break;
1033
1034
25.6k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
25.6k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
25.6k
        break;
1038
26.7k
      }
1039
1040
26.7k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
26.7k
    if (*slot == NULL)
1042
0
      return false;
1043
26.7k
    struct comdat_hash_entry *newentry = *slot;
1044
26.7k
    newentry->sec_flags = sec_flags;
1045
26.7k
    newentry->symname = bfd_strdup (symname);
1046
26.7k
    newentry->target_index = isym.n_scnum;
1047
26.7k
    newentry->isym = isym;
1048
26.7k
    newentry->comdat_symbol = -1;
1049
26.7k
  }
1050
58.1k
      else
1051
58.1k
  {
1052
58.1k
    struct comdat_hash_entry *entry = *slot;
1053
1054
58.1k
    if (entry->comdat_symbol != -1)
1055
50.7k
      continue;
1056
1057
7.39k
    char *target_name = strchr (entry->symname, '$');
1058
7.39k
    if (target_name != NULL)
1059
754
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
754
        target_name += 1;
1063
754
#ifndef TARGET_UNDERSCORE
1064
754
#define TARGET_UNDERSCORE 0
1065
754
#endif
1066
        /* Is this the name we're looking for ?  */
1067
754
        if (strcmp (target_name,
1068
754
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
513
    {
1070
      /* Not the name we're looking for */
1071
513
      continue;
1072
513
    }
1073
754
      }
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
6.87k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
6.87k
    entry->comdat_name = bfd_strdup (symname);
1082
6.87k
  }
1083
88.7k
    }
1084
1085
15.8k
  return true;
1086
15.8k
}
pei-sh.c:fill_comdat_hash
Line
Count
Source
890
27.2k
{
891
27.2k
  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
27.2k
  if (! _bfd_coff_get_external_symbols (abfd))
909
7.26k
    return true;
910
911
19.9k
  esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
912
19.9k
  esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
913
914
19.9k
  for (struct internal_syment isym;
915
189k
       esym < esymend;
916
169k
       esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd))
917
169k
    {
918
169k
      char buf[SYMNMLEN + 1];
919
169k
      const char *symname;
920
169k
      flagword sec_flags = SEC_LINK_ONCE;
921
922
169k
      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
169k
      symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
946
947
      /* PR 17512 file: 078-11867-0.004  */
948
169k
      if (symname == NULL)
949
46.6k
  {
950
46.6k
    _bfd_error_handler (_("%pB: unable to load COMDAT section name"),
951
46.6k
            abfd);
952
46.6k
    continue;
953
46.6k
  }
954
955
123k
      union internal_auxent aux;
956
957
123k
      struct comdat_hash_entry needle;
958
123k
      needle.target_index = isym.n_scnum;
959
960
123k
      void **slot
961
123k
  = htab_find_slot (pe_data (abfd)->comdat_hash, &needle, INSERT);
962
123k
      if (slot == NULL)
963
0
  return false;
964
965
123k
      if (*slot == NULL)
966
63.6k
  {
967
63.6k
    if (isym.n_numaux == 0)
968
28.5k
      aux.x_scn.x_comdat = 0;
969
35.1k
    else
970
35.1k
      {
971
        /* PR 17512: file: e2cfe54f.  */
972
35.1k
        if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
973
6.07k
    {
974
      /* xgettext:c-format */
975
6.07k
      _bfd_error_handler (_("%pB: warning: no symbol for"
976
6.07k
          " section '%s' found"),
977
6.07k
              abfd, symname);
978
6.07k
      continue;
979
6.07k
    }
980
29.0k
        bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
981
29.0k
            isym.n_type, isym.n_sclass, 0,
982
29.0k
            isym.n_numaux, &aux);
983
29.0k
      }
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
57.6k
    switch (aux.x_scn.x_comdat)
998
57.6k
      {
999
9
      case IMAGE_COMDAT_SELECT_NODUPLICATES:
1000
#ifdef STRICT_PE_FORMAT
1001
        sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1002
#else
1003
9
        sec_flags &= ~SEC_LINK_ONCE;
1004
9
#endif
1005
9
        break;
1006
1007
1
      case IMAGE_COMDAT_SELECT_ANY:
1008
1
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1009
1
        break;
1010
1011
16
      case IMAGE_COMDAT_SELECT_SAME_SIZE:
1012
16
        sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1013
16
        break;
1014
1015
14
      case IMAGE_COMDAT_SELECT_EXACT_MATCH:
1016
        /* Not yet fully implemented ??? */
1017
14
        sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1018
14
        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
5
      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
5
        sec_flags &= ~SEC_LINK_ONCE;
1031
5
#endif
1032
5
        break;
1033
1034
57.5k
      default:  /* 0 means "no symbol" */
1035
        /* debug$F gets this case; other implications ???  */
1036
57.5k
        sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
1037
57.5k
        break;
1038
57.6k
      }
1039
1040
57.6k
    *slot = bfd_zmalloc (sizeof (struct comdat_hash_entry));
1041
57.6k
    if (*slot == NULL)
1042
0
      return false;
1043
57.6k
    struct comdat_hash_entry *newentry = *slot;
1044
57.6k
    newentry->sec_flags = sec_flags;
1045
57.6k
    newentry->symname = bfd_strdup (symname);
1046
57.6k
    newentry->target_index = isym.n_scnum;
1047
57.6k
    newentry->isym = isym;
1048
57.6k
    newentry->comdat_symbol = -1;
1049
57.6k
  }
1050
59.4k
      else
1051
59.4k
  {
1052
59.4k
    struct comdat_hash_entry *entry = *slot;
1053
1054
59.4k
    if (entry->comdat_symbol != -1)
1055
49.6k
      continue;
1056
1057
9.88k
    char *target_name = strchr (entry->symname, '$');
1058
9.88k
    if (target_name != NULL)
1059
1.28k
      {
1060
        /* Gas mode: the first matching on partial name.  */
1061
1062
1.28k
        target_name += 1;
1063
#ifndef TARGET_UNDERSCORE
1064
#define TARGET_UNDERSCORE 0
1065
#endif
1066
        /* Is this the name we're looking for ?  */
1067
1.28k
        if (strcmp (target_name,
1068
1.28k
        symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
1069
764
    {
1070
      /* Not the name we're looking for */
1071
764
      continue;
1072
764
    }
1073
1.28k
      }
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
9.12k
    entry->comdat_symbol = (esym - esymstart) / bfd_coff_symesz (abfd);
1081
9.12k
    entry->comdat_name = bfd_strdup (symname);
1082
9.12k
  }
1083
123k
    }
1084
1085
19.9k
  return true;
1086
19.9k
}
1087
1088
static bool
1089
insert_coff_comdat_info (bfd *abfd, asection *section, const char *symname,
1090
       long symbol)
1091
15.1k
{
1092
15.1k
  struct coff_comdat_info *comdat;
1093
15.1k
  size_t len = strlen (symname) + 1;
1094
1095
15.1k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
15.1k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
15.1k
  coff_section_data (abfd, section)->comdat = comdat;
1100
15.1k
  comdat->symbol = symbol;
1101
15.1k
  char *newname = (char *) (comdat + 1);
1102
15.1k
  comdat->name = newname;
1103
15.1k
  memcpy (newname, symname, len);
1104
15.1k
  return true;
1105
15.1k
}
pei-i386.c:insert_coff_comdat_info
Line
Count
Source
1091
1.90k
{
1092
1.90k
  struct coff_comdat_info *comdat;
1093
1.90k
  size_t len = strlen (symname) + 1;
1094
1095
1.90k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1.90k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1.90k
  coff_section_data (abfd, section)->comdat = comdat;
1100
1.90k
  comdat->symbol = symbol;
1101
1.90k
  char *newname = (char *) (comdat + 1);
1102
1.90k
  comdat->name = newname;
1103
1.90k
  memcpy (newname, symname, len);
1104
1.90k
  return true;
1105
1.90k
}
pe-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1091
701
{
1092
701
  struct coff_comdat_info *comdat;
1093
701
  size_t len = strlen (symname) + 1;
1094
1095
701
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
701
  if (comdat == NULL)
1097
0
    return false;
1098
1099
701
  coff_section_data (abfd, section)->comdat = comdat;
1100
701
  comdat->symbol = symbol;
1101
701
  char *newname = (char *) (comdat + 1);
1102
701
  comdat->name = newname;
1103
701
  memcpy (newname, symname, len);
1104
701
  return true;
1105
701
}
pei-x86_64.c:insert_coff_comdat_info
Line
Count
Source
1091
1.71k
{
1092
1.71k
  struct coff_comdat_info *comdat;
1093
1.71k
  size_t len = strlen (symname) + 1;
1094
1095
1.71k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1.71k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1.71k
  coff_section_data (abfd, section)->comdat = comdat;
1100
1.71k
  comdat->symbol = symbol;
1101
1.71k
  char *newname = (char *) (comdat + 1);
1102
1.71k
  comdat->name = newname;
1103
1.71k
  memcpy (newname, symname, len);
1104
1.71k
  return true;
1105
1.71k
}
pe-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1091
22
{
1092
22
  struct coff_comdat_info *comdat;
1093
22
  size_t len = strlen (symname) + 1;
1094
1095
22
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
22
  if (comdat == NULL)
1097
0
    return false;
1098
1099
22
  coff_section_data (abfd, section)->comdat = comdat;
1100
22
  comdat->symbol = symbol;
1101
22
  char *newname = (char *) (comdat + 1);
1102
22
  comdat->name = newname;
1103
22
  memcpy (newname, symname, len);
1104
22
  return true;
1105
22
}
pei-aarch64.c:insert_coff_comdat_info
Line
Count
Source
1091
2.41k
{
1092
2.41k
  struct coff_comdat_info *comdat;
1093
2.41k
  size_t len = strlen (symname) + 1;
1094
1095
2.41k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
2.41k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
2.41k
  coff_section_data (abfd, section)->comdat = comdat;
1100
2.41k
  comdat->symbol = symbol;
1101
2.41k
  char *newname = (char *) (comdat + 1);
1102
2.41k
  comdat->name = newname;
1103
2.41k
  memcpy (newname, symname, len);
1104
2.41k
  return true;
1105
2.41k
}
pei-ia64.c:insert_coff_comdat_info
Line
Count
Source
1091
1.70k
{
1092
1.70k
  struct coff_comdat_info *comdat;
1093
1.70k
  size_t len = strlen (symname) + 1;
1094
1095
1.70k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1.70k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1.70k
  coff_section_data (abfd, section)->comdat = comdat;
1100
1.70k
  comdat->symbol = symbol;
1101
1.70k
  char *newname = (char *) (comdat + 1);
1102
1.70k
  comdat->name = newname;
1103
1.70k
  memcpy (newname, symname, len);
1104
1.70k
  return true;
1105
1.70k
}
pei-loongarch64.c:insert_coff_comdat_info
Line
Count
Source
1091
592
{
1092
592
  struct coff_comdat_info *comdat;
1093
592
  size_t len = strlen (symname) + 1;
1094
1095
592
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
592
  if (comdat == NULL)
1097
0
    return false;
1098
1099
592
  coff_section_data (abfd, section)->comdat = comdat;
1100
592
  comdat->symbol = symbol;
1101
592
  char *newname = (char *) (comdat + 1);
1102
592
  comdat->name = newname;
1103
592
  memcpy (newname, symname, len);
1104
592
  return true;
1105
592
}
pe-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1091
549
{
1092
549
  struct coff_comdat_info *comdat;
1093
549
  size_t len = strlen (symname) + 1;
1094
1095
549
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
549
  if (comdat == NULL)
1097
0
    return false;
1098
1099
549
  coff_section_data (abfd, section)->comdat = comdat;
1100
549
  comdat->symbol = symbol;
1101
549
  char *newname = (char *) (comdat + 1);
1102
549
  comdat->name = newname;
1103
549
  memcpy (newname, symname, len);
1104
549
  return true;
1105
549
}
pe-arm.c:insert_coff_comdat_info
Line
Count
Source
1091
549
{
1092
549
  struct coff_comdat_info *comdat;
1093
549
  size_t len = strlen (symname) + 1;
1094
1095
549
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
549
  if (comdat == NULL)
1097
0
    return false;
1098
1099
549
  coff_section_data (abfd, section)->comdat = comdat;
1100
549
  comdat->symbol = symbol;
1101
549
  char *newname = (char *) (comdat + 1);
1102
549
  comdat->name = newname;
1103
549
  memcpy (newname, symname, len);
1104
549
  return true;
1105
549
}
pe-i386.c:insert_coff_comdat_info
Line
Count
Source
1091
384
{
1092
384
  struct coff_comdat_info *comdat;
1093
384
  size_t len = strlen (symname) + 1;
1094
1095
384
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
384
  if (comdat == NULL)
1097
0
    return false;
1098
1099
384
  coff_section_data (abfd, section)->comdat = comdat;
1100
384
  comdat->symbol = symbol;
1101
384
  char *newname = (char *) (comdat + 1);
1102
384
  comdat->name = newname;
1103
384
  memcpy (newname, symname, len);
1104
384
  return true;
1105
384
}
pe-mcore.c:insert_coff_comdat_info
Line
Count
Source
1091
375
{
1092
375
  struct coff_comdat_info *comdat;
1093
375
  size_t len = strlen (symname) + 1;
1094
1095
375
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
375
  if (comdat == NULL)
1097
0
    return false;
1098
1099
375
  coff_section_data (abfd, section)->comdat = comdat;
1100
375
  comdat->symbol = symbol;
1101
375
  char *newname = (char *) (comdat + 1);
1102
375
  comdat->name = newname;
1103
375
  memcpy (newname, symname, len);
1104
375
  return true;
1105
375
}
pe-sh.c:insert_coff_comdat_info
Line
Count
Source
1091
786
{
1092
786
  struct coff_comdat_info *comdat;
1093
786
  size_t len = strlen (symname) + 1;
1094
1095
786
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
786
  if (comdat == NULL)
1097
0
    return false;
1098
1099
786
  coff_section_data (abfd, section)->comdat = comdat;
1100
786
  comdat->symbol = symbol;
1101
786
  char *newname = (char *) (comdat + 1);
1102
786
  comdat->name = newname;
1103
786
  memcpy (newname, symname, len);
1104
786
  return true;
1105
786
}
pei-arm-wince.c:insert_coff_comdat_info
Line
Count
Source
1091
716
{
1092
716
  struct coff_comdat_info *comdat;
1093
716
  size_t len = strlen (symname) + 1;
1094
1095
716
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
716
  if (comdat == NULL)
1097
0
    return false;
1098
1099
716
  coff_section_data (abfd, section)->comdat = comdat;
1100
716
  comdat->symbol = symbol;
1101
716
  char *newname = (char *) (comdat + 1);
1102
716
  comdat->name = newname;
1103
716
  memcpy (newname, symname, len);
1104
716
  return true;
1105
716
}
pei-arm.c:insert_coff_comdat_info
Line
Count
Source
1091
733
{
1092
733
  struct coff_comdat_info *comdat;
1093
733
  size_t len = strlen (symname) + 1;
1094
1095
733
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
733
  if (comdat == NULL)
1097
0
    return false;
1098
1099
733
  coff_section_data (abfd, section)->comdat = comdat;
1100
733
  comdat->symbol = symbol;
1101
733
  char *newname = (char *) (comdat + 1);
1102
733
  comdat->name = newname;
1103
733
  memcpy (newname, symname, len);
1104
733
  return true;
1105
733
}
pei-mcore.c:insert_coff_comdat_info
Line
Count
Source
1091
839
{
1092
839
  struct coff_comdat_info *comdat;
1093
839
  size_t len = strlen (symname) + 1;
1094
1095
839
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
839
  if (comdat == NULL)
1097
0
    return false;
1098
1099
839
  coff_section_data (abfd, section)->comdat = comdat;
1100
839
  comdat->symbol = symbol;
1101
839
  char *newname = (char *) (comdat + 1);
1102
839
  comdat->name = newname;
1103
839
  memcpy (newname, symname, len);
1104
839
  return true;
1105
839
}
pei-sh.c:insert_coff_comdat_info
Line
Count
Source
1091
1.13k
{
1092
1.13k
  struct coff_comdat_info *comdat;
1093
1.13k
  size_t len = strlen (symname) + 1;
1094
1095
1.13k
  comdat = bfd_alloc (abfd, sizeof (*comdat) + len);
1096
1.13k
  if (comdat == NULL)
1097
0
    return false;
1098
1099
1.13k
  coff_section_data (abfd, section)->comdat = comdat;
1100
1.13k
  comdat->symbol = symbol;
1101
1.13k
  char *newname = (char *) (comdat + 1);
1102
1.13k
  comdat->name = newname;
1103
1.13k
  memcpy (newname, symname, len);
1104
1.13k
  return true;
1105
1.13k
}
1106
1107
static bool
1108
handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
1109
         asection *section)
1110
565k
{
1111
565k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
373k
    {
1113
373k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
373k
             comdat_delf);
1115
373k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
373k
    }
1118
1119
565k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
443k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
565k
  struct comdat_hash_entry *found
1124
565k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
565k
  if (found != NULL)
1126
78.6k
    {
1127
78.6k
      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
78.6k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
78.6k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
30.2k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
30.2k
    _bfd_error_handler
1147
30.2k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
30.2k
       abfd, found->symname);
1149
30.2k
    return false;
1150
30.2k
  }
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
48.4k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
32.9k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
32.9k
            " does not match section name '%s'"),
1160
32.9k
          abfd, found->symname, name);
1161
1162
48.4k
      if (found->comdat_symbol != -1)
1163
15.1k
  {
1164
15.1k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
15.1k
           found->comdat_symbol))
1166
0
      return false;
1167
15.1k
  }
1168
48.4k
      *sec_flags = *sec_flags | found->sec_flags;
1169
48.4k
      return true;
1170
48.4k
    }
1171
487k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
487k
  return true;
1173
565k
}
pei-i386.c:handle_COMDAT
Line
Count
Source
1110
42.2k
{
1111
42.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
21.7k
    {
1113
21.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
21.7k
             comdat_delf);
1115
21.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
21.7k
    }
1118
1119
42.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
25.4k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
42.2k
  struct comdat_hash_entry *found
1124
42.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
42.2k
  if (found != NULL)
1126
5.89k
    {
1127
5.89k
      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.89k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
5.89k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2.04k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2.04k
    _bfd_error_handler
1147
2.04k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2.04k
       abfd, found->symname);
1149
2.04k
    return false;
1150
2.04k
  }
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.85k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
2.34k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
2.34k
            " does not match section name '%s'"),
1160
2.34k
          abfd, found->symname, name);
1161
1162
3.85k
      if (found->comdat_symbol != -1)
1163
1.90k
  {
1164
1.90k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1.90k
           found->comdat_symbol))
1166
0
      return false;
1167
1.90k
  }
1168
3.85k
      *sec_flags = *sec_flags | found->sec_flags;
1169
3.85k
      return true;
1170
3.85k
    }
1171
36.3k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
36.3k
  return true;
1173
42.2k
}
pe-x86_64.c:handle_COMDAT
Line
Count
Source
1110
62.7k
{
1111
62.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
48.9k
    {
1113
48.9k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
48.9k
             comdat_delf);
1115
48.9k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
48.9k
    }
1118
1119
62.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
56.4k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
62.7k
  struct comdat_hash_entry *found
1124
62.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
62.7k
  if (found != NULL)
1126
2.49k
    {
1127
2.49k
      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.49k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2.49k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.09k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.09k
    _bfd_error_handler
1147
1.09k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.09k
       abfd, found->symname);
1149
1.09k
    return false;
1150
1.09k
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1.40k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
631
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
631
            " does not match section name '%s'"),
1160
631
          abfd, found->symname, name);
1161
1162
1.40k
      if (found->comdat_symbol != -1)
1163
701
  {
1164
701
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
701
           found->comdat_symbol))
1166
0
      return false;
1167
701
  }
1168
1.40k
      *sec_flags = *sec_flags | found->sec_flags;
1169
1.40k
      return true;
1170
1.40k
    }
1171
60.2k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
60.2k
  return true;
1173
62.7k
}
pei-x86_64.c:handle_COMDAT
Line
Count
Source
1110
55.1k
{
1111
55.1k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
31.5k
    {
1113
31.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
31.5k
             comdat_delf);
1115
31.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
31.5k
    }
1118
1119
55.1k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
36.0k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
55.1k
  struct comdat_hash_entry *found
1124
55.1k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
55.1k
  if (found != NULL)
1126
12.5k
    {
1127
12.5k
      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
12.5k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
12.5k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2.37k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2.37k
    _bfd_error_handler
1147
2.37k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2.37k
       abfd, found->symname);
1149
2.37k
    return false;
1150
2.37k
  }
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
10.1k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
9.14k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
9.14k
            " does not match section name '%s'"),
1160
9.14k
          abfd, found->symname, name);
1161
1162
10.1k
      if (found->comdat_symbol != -1)
1163
1.71k
  {
1164
1.71k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1.71k
           found->comdat_symbol))
1166
0
      return false;
1167
1.71k
  }
1168
10.1k
      *sec_flags = *sec_flags | found->sec_flags;
1169
10.1k
      return true;
1170
10.1k
    }
1171
42.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
42.6k
  return true;
1173
55.1k
}
pe-aarch64.c:handle_COMDAT
Line
Count
Source
1110
17.4k
{
1111
17.4k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
12.5k
    {
1113
12.5k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
12.5k
             comdat_delf);
1115
12.5k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
12.5k
    }
1118
1119
17.4k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
14.4k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
17.4k
  struct comdat_hash_entry *found
1124
17.4k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
17.4k
  if (found != NULL)
1126
1.12k
    {
1127
1.12k
      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.12k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
1.12k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
595
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
595
    _bfd_error_handler
1147
595
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
595
       abfd, found->symname);
1149
595
    return false;
1150
595
  }
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
531
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
239
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
239
            " does not match section name '%s'"),
1160
239
          abfd, found->symname, name);
1161
1162
531
      if (found->comdat_symbol != -1)
1163
22
  {
1164
22
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
22
           found->comdat_symbol))
1166
0
      return false;
1167
22
  }
1168
531
      *sec_flags = *sec_flags | found->sec_flags;
1169
531
      return true;
1170
531
    }
1171
16.2k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
16.2k
  return true;
1173
17.4k
}
pei-aarch64.c:handle_COMDAT
Line
Count
Source
1110
37.3k
{
1111
37.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
24.9k
    {
1113
24.9k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
24.9k
             comdat_delf);
1115
24.9k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
24.9k
    }
1118
1119
37.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
27.9k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
37.3k
  struct comdat_hash_entry *found
1124
37.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
37.3k
  if (found != NULL)
1126
8.93k
    {
1127
8.93k
      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.93k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
8.93k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
4.09k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
4.09k
    _bfd_error_handler
1147
4.09k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
4.09k
       abfd, found->symname);
1149
4.09k
    return false;
1150
4.09k
  }
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.83k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
3.02k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
3.02k
            " does not match section name '%s'"),
1160
3.02k
          abfd, found->symname, name);
1161
1162
4.83k
      if (found->comdat_symbol != -1)
1163
2.41k
  {
1164
2.41k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
2.41k
           found->comdat_symbol))
1166
0
      return false;
1167
2.41k
  }
1168
4.83k
      *sec_flags = *sec_flags | found->sec_flags;
1169
4.83k
      return true;
1170
4.83k
    }
1171
28.4k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
28.4k
  return true;
1173
37.3k
}
pei-ia64.c:handle_COMDAT
Line
Count
Source
1110
49.5k
{
1111
49.5k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
28.7k
    {
1113
28.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
28.7k
             comdat_delf);
1115
28.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
28.7k
    }
1118
1119
49.5k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
34.0k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
49.5k
  struct comdat_hash_entry *found
1124
49.5k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
49.5k
  if (found != NULL)
1126
9.71k
    {
1127
9.71k
      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
9.71k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
9.71k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
3.95k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
3.95k
    _bfd_error_handler
1147
3.95k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
3.95k
       abfd, found->symname);
1149
3.95k
    return false;
1150
3.95k
  }
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
5.76k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
5.32k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
5.32k
            " does not match section name '%s'"),
1160
5.32k
          abfd, found->symname, name);
1161
1162
5.76k
      if (found->comdat_symbol != -1)
1163
1.70k
  {
1164
1.70k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1.70k
           found->comdat_symbol))
1166
0
      return false;
1167
1.70k
  }
1168
5.76k
      *sec_flags = *sec_flags | found->sec_flags;
1169
5.76k
      return true;
1170
5.76k
    }
1171
39.8k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
39.8k
  return true;
1173
49.5k
}
pei-loongarch64.c:handle_COMDAT
Line
Count
Source
1110
26.3k
{
1111
26.3k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
19.7k
    {
1113
19.7k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
19.7k
             comdat_delf);
1115
19.7k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
19.7k
    }
1118
1119
26.3k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
23.7k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
26.3k
  struct comdat_hash_entry *found
1124
26.3k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
26.3k
  if (found != NULL)
1126
2.46k
    {
1127
2.46k
      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.46k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2.46k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.35k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.35k
    _bfd_error_handler
1147
1.35k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.35k
       abfd, found->symname);
1149
1.35k
    return false;
1150
1.35k
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1.10k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
534
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
534
            " does not match section name '%s'"),
1160
534
          abfd, found->symname, name);
1161
1162
1.10k
      if (found->comdat_symbol != -1)
1163
592
  {
1164
592
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
592
           found->comdat_symbol))
1166
0
      return false;
1167
592
  }
1168
1.10k
      *sec_flags = *sec_flags | found->sec_flags;
1169
1.10k
      return true;
1170
1.10k
    }
1171
23.9k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
23.9k
  return true;
1173
26.3k
}
pe-arm-wince.c:handle_COMDAT
Line
Count
Source
1110
12.1k
{
1111
12.1k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
7.67k
    {
1113
7.67k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
7.67k
             comdat_delf);
1115
7.67k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
7.67k
    }
1118
1119
12.1k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
9.29k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
12.1k
  struct comdat_hash_entry *found
1124
12.1k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
12.1k
  if (found != NULL)
1126
2.91k
    {
1127
2.91k
      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.91k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2.91k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.27k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.27k
    _bfd_error_handler
1147
1.27k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.27k
       abfd, found->symname);
1149
1.27k
    return false;
1150
1.27k
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1.63k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.08k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.08k
            " does not match section name '%s'"),
1160
1.08k
          abfd, found->symname, name);
1161
1162
1.63k
      if (found->comdat_symbol != -1)
1163
549
  {
1164
549
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
549
           found->comdat_symbol))
1166
0
      return false;
1167
549
  }
1168
1.63k
      *sec_flags = *sec_flags | found->sec_flags;
1169
1.63k
      return true;
1170
1.63k
    }
1171
9.24k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
9.24k
  return true;
1173
12.1k
}
pe-arm.c:handle_COMDAT
Line
Count
Source
1110
12.1k
{
1111
12.1k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
7.67k
    {
1113
7.67k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
7.67k
             comdat_delf);
1115
7.67k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
7.67k
    }
1118
1119
12.1k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
9.29k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
12.1k
  struct comdat_hash_entry *found
1124
12.1k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
12.1k
  if (found != NULL)
1126
2.91k
    {
1127
2.91k
      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.91k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2.91k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.27k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.27k
    _bfd_error_handler
1147
1.27k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.27k
       abfd, found->symname);
1149
1.27k
    return false;
1150
1.27k
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1.63k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.08k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.08k
            " does not match section name '%s'"),
1160
1.08k
          abfd, found->symname, name);
1161
1162
1.63k
      if (found->comdat_symbol != -1)
1163
549
  {
1164
549
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
549
           found->comdat_symbol))
1166
0
      return false;
1167
549
  }
1168
1.63k
      *sec_flags = *sec_flags | found->sec_flags;
1169
1.63k
      return true;
1170
1.63k
    }
1171
9.24k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
9.24k
  return true;
1173
12.1k
}
pe-i386.c:handle_COMDAT
Line
Count
Source
1110
32.8k
{
1111
32.8k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
21.3k
    {
1113
21.3k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
21.3k
             comdat_delf);
1115
21.3k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
21.3k
    }
1118
1119
32.8k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
26.6k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
32.8k
  struct comdat_hash_entry *found
1124
32.8k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
32.8k
  if (found != NULL)
1126
3.73k
    {
1127
3.73k
      struct internal_syment isym = found->isym;
1128
1129
      /* If it isn't the stuff we're expecting, die;  The MS
1130
   documentation is vague, but it appears that the second entry
1131
   serves BOTH as the comdat symbol and the defining symbol
1132
   record (either C_STAT or C_EXT, possibly with an aux entry
1133
   with debug information if it's a function.)  It appears the
1134
   only way to find the second one is to count.  (On Intel, they
1135
   appear to be adjacent, but on Alpha, they have been found
1136
   separated.)
1137
1138
   Here, we think we've found the first one, but there's some
1139
   checking we can do to be sure.  */
1140
1141
3.73k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
3.73k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.34k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.34k
    _bfd_error_handler
1147
1.34k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.34k
       abfd, found->symname);
1149
1.34k
    return false;
1150
1.34k
  }
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.38k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
876
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
876
            " does not match section name '%s'"),
1160
876
          abfd, found->symname, name);
1161
1162
2.38k
      if (found->comdat_symbol != -1)
1163
384
  {
1164
384
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
384
           found->comdat_symbol))
1166
0
      return false;
1167
384
  }
1168
2.38k
      *sec_flags = *sec_flags | found->sec_flags;
1169
2.38k
      return true;
1170
2.38k
    }
1171
29.1k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
29.1k
  return true;
1173
32.8k
}
pe-mcore.c:handle_COMDAT
Line
Count
Source
1110
18.8k
{
1111
18.8k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
12.0k
    {
1113
12.0k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
12.0k
             comdat_delf);
1115
12.0k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
12.0k
    }
1118
1119
18.8k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
15.3k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
18.8k
  struct comdat_hash_entry *found
1124
18.8k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
18.8k
  if (found != NULL)
1126
2.19k
    {
1127
2.19k
      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.19k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
2.19k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
262
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
262
    _bfd_error_handler
1147
262
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
262
       abfd, found->symname);
1149
262
    return false;
1150
262
  }
1151
1152
      /* FIXME LATER: MSVC generates section names like .text for
1153
   comdats.  Gas generates names like .text$foo__Fv (in the case
1154
   of a function).  See comment above for more.  */
1155
1156
1.93k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.31k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.31k
            " does not match section name '%s'"),
1160
1.31k
          abfd, found->symname, name);
1161
1162
1.93k
      if (found->comdat_symbol != -1)
1163
375
  {
1164
375
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
375
           found->comdat_symbol))
1166
0
      return false;
1167
375
  }
1168
1.93k
      *sec_flags = *sec_flags | found->sec_flags;
1169
1.93k
      return true;
1170
1.93k
    }
1171
16.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
16.6k
  return true;
1173
18.8k
}
pe-sh.c:handle_COMDAT
Line
Count
Source
1110
28.7k
{
1111
28.7k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
19.8k
    {
1113
19.8k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
19.8k
             comdat_delf);
1115
19.8k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
19.8k
    }
1118
1119
28.7k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
24.2k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
28.7k
  struct comdat_hash_entry *found
1124
28.7k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
28.7k
  if (found != NULL)
1126
4.39k
    {
1127
4.39k
      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.39k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4.39k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2.26k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2.26k
    _bfd_error_handler
1147
2.26k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2.26k
       abfd, found->symname);
1149
2.26k
    return false;
1150
2.26k
  }
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.13k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.14k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.14k
            " does not match section name '%s'"),
1160
1.14k
          abfd, found->symname, name);
1161
1162
2.13k
      if (found->comdat_symbol != -1)
1163
786
  {
1164
786
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
786
           found->comdat_symbol))
1166
0
      return false;
1167
786
  }
1168
2.13k
      *sec_flags = *sec_flags | found->sec_flags;
1169
2.13k
      return true;
1170
2.13k
    }
1171
24.3k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
24.3k
  return true;
1173
28.7k
}
pei-arm-wince.c:handle_COMDAT
Line
Count
Source
1110
43.9k
{
1111
43.9k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
30.6k
    {
1113
30.6k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
30.6k
             comdat_delf);
1115
30.6k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
30.6k
    }
1118
1119
43.9k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
38.2k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
43.9k
  struct comdat_hash_entry *found
1124
43.9k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
43.9k
  if (found != NULL)
1126
4.55k
    {
1127
4.55k
      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.55k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4.55k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2.21k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2.21k
    _bfd_error_handler
1147
2.21k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2.21k
       abfd, found->symname);
1149
2.21k
    return false;
1150
2.21k
  }
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.34k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.22k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.22k
            " does not match section name '%s'"),
1160
1.22k
          abfd, found->symname, name);
1161
1162
2.34k
      if (found->comdat_symbol != -1)
1163
716
  {
1164
716
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
716
           found->comdat_symbol))
1166
0
      return false;
1167
716
  }
1168
2.34k
      *sec_flags = *sec_flags | found->sec_flags;
1169
2.34k
      return true;
1170
2.34k
    }
1171
39.3k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
39.3k
  return true;
1173
43.9k
}
pei-arm.c:handle_COMDAT
Line
Count
Source
1110
56.0k
{
1111
56.0k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
40.9k
    {
1113
40.9k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
40.9k
             comdat_delf);
1115
40.9k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
40.9k
    }
1118
1119
56.0k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
49.9k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
56.0k
  struct comdat_hash_entry *found
1124
56.0k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
56.0k
  if (found != NULL)
1126
5.19k
    {
1127
5.19k
      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.19k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
5.19k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
2.69k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
2.69k
    _bfd_error_handler
1147
2.69k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
2.69k
       abfd, found->symname);
1149
2.69k
    return false;
1150
2.69k
  }
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.49k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.36k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.36k
            " does not match section name '%s'"),
1160
1.36k
          abfd, found->symname, name);
1161
1162
2.49k
      if (found->comdat_symbol != -1)
1163
733
  {
1164
733
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
733
           found->comdat_symbol))
1166
0
      return false;
1167
733
  }
1168
2.49k
      *sec_flags = *sec_flags | found->sec_flags;
1169
2.49k
      return true;
1170
2.49k
    }
1171
50.8k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
50.8k
  return true;
1173
56.0k
}
pei-mcore.c:handle_COMDAT
Line
Count
Source
1110
30.2k
{
1111
30.2k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
22.2k
    {
1113
22.2k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
22.2k
             comdat_delf);
1115
22.2k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
22.2k
    }
1118
1119
30.2k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
25.1k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
30.2k
  struct comdat_hash_entry *found
1124
30.2k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
30.2k
  if (found != NULL)
1126
4.64k
    {
1127
4.64k
      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.64k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4.64k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.86k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.86k
    _bfd_error_handler
1147
1.86k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.86k
       abfd, found->symname);
1149
1.86k
    return false;
1150
1.86k
  }
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.78k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.79k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.79k
            " does not match section name '%s'"),
1160
1.79k
          abfd, found->symname, name);
1161
1162
2.78k
      if (found->comdat_symbol != -1)
1163
839
  {
1164
839
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
839
           found->comdat_symbol))
1166
0
      return false;
1167
839
  }
1168
2.78k
      *sec_flags = *sec_flags | found->sec_flags;
1169
2.78k
      return true;
1170
2.78k
    }
1171
25.6k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
25.6k
  return true;
1173
30.2k
}
pei-sh.c:handle_COMDAT
Line
Count
Source
1110
39.9k
{
1111
39.9k
  if (pe_data (abfd)->comdat_hash == NULL)
1112
22.4k
    {
1113
22.4k
      pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf,
1114
22.4k
             comdat_delf);
1115
22.4k
      if (pe_data (abfd)->comdat_hash == NULL)
1116
0
  return false;
1117
22.4k
    }
1118
1119
39.9k
  if (htab_elements (pe_data (abfd)->comdat_hash) == 0)
1120
27.2k
    if (! fill_comdat_hash (abfd))
1121
0
      return false;
1122
1123
39.9k
  struct comdat_hash_entry *found
1124
39.9k
    = find_flags (pe_data (abfd)->comdat_hash, section->target_index);
1125
39.9k
  if (found != NULL)
1126
4.97k
    {
1127
4.97k
      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.97k
      if (! ((isym.n_sclass == C_STAT || isym.n_sclass == C_EXT)
1142
4.97k
       && BTYPE (isym.n_type) == T_NULL && isym.n_value == 0))
1143
1.57k
  {
1144
    /* Malformed input files can trigger this test.
1145
       cf PR 21781.  */
1146
1.57k
    _bfd_error_handler
1147
1.57k
      (_("%pB: error: unexpected symbol '%s' in COMDAT section"),
1148
1.57k
       abfd, found->symname);
1149
1.57k
    return false;
1150
1.57k
  }
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.39k
      if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
1157
  /* xgettext:c-format */
1158
1.80k
  _bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
1159
1.80k
            " does not match section name '%s'"),
1160
1.80k
          abfd, found->symname, name);
1161
1162
3.39k
      if (found->comdat_symbol != -1)
1163
1.13k
  {
1164
1.13k
    if (! insert_coff_comdat_info (abfd, section, found->comdat_name,
1165
1.13k
           found->comdat_symbol))
1166
0
      return false;
1167
1.13k
  }
1168
3.39k
      *sec_flags = *sec_flags | found->sec_flags;
1169
3.39k
      return true;
1170
3.39k
    }
1171
34.9k
  *sec_flags = *sec_flags | SEC_LINK_ONCE;
1172
34.9k
  return true;
1173
39.9k
}
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
3.99M
{
1192
3.99M
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
3.99M
  unsigned long styp_flags = internal_s->s_flags;
1194
3.99M
  flagword sec_flags;
1195
3.99M
  bool result = true;
1196
3.99M
  bool is_dbg = false;
1197
1198
3.99M
  if (startswith (name, DOT_DEBUG)
1199
3.99M
      || startswith (name, DOT_ZDEBUG)
1200
3.99M
#ifdef COFF_LONG_SECTION_NAMES
1201
3.99M
      || startswith (name, GNU_LINKONCE_WI)
1202
3.99M
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
3.99M
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
3.99M
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
3.99M
      || startswith (name, GNU_DEBUGLINK)
1207
3.99M
      || startswith (name, GNU_DEBUGALTLINK)
1208
3.99M
#endif
1209
3.99M
      || startswith (name, ".stab"))
1210
145k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
3.99M
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
3.99M
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
3.41M
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
19.4M
  while (styp_flags)
1220
15.4M
    {
1221
15.4M
      unsigned long flag = styp_flags & - styp_flags;
1222
15.4M
      char * unhandled = NULL;
1223
1224
15.4M
      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
15.4M
      switch (flag)
1231
15.4M
  {
1232
191k
  case STYP_DSECT:
1233
191k
    unhandled = "STYP_DSECT";
1234
191k
    break;
1235
184k
  case STYP_GROUP:
1236
184k
    unhandled = "STYP_GROUP";
1237
184k
    break;
1238
206k
  case STYP_COPY:
1239
206k
    unhandled = "STYP_COPY";
1240
206k
    break;
1241
200k
  case STYP_OVER:
1242
200k
    unhandled = "STYP_OVER";
1243
200k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
504k
  case STYP_NOLOAD:
1246
504k
    sec_flags |= SEC_NEVER_LOAD;
1247
504k
    break;
1248
0
#endif
1249
574k
  case IMAGE_SCN_MEM_READ:
1250
574k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
574k
    break;
1252
523k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
523k
    break;
1255
206k
  case IMAGE_SCN_LNK_OTHER:
1256
206k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
206k
    break;
1258
194k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
194k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
194k
    break;
1261
638k
  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
638k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
638k
        " %s in section %s"),
1268
638k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
638k
    break;
1270
660k
  case IMAGE_SCN_MEM_EXECUTE:
1271
660k
    sec_flags |= SEC_CODE;
1272
660k
    break;
1273
545k
  case IMAGE_SCN_MEM_WRITE:
1274
545k
    sec_flags &= ~ SEC_READONLY;
1275
545k
    break;
1276
681k
  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
681k
       if (is_dbg
1283
681k
#ifdef _COMMENT
1284
681k
        || strcmp (name, _COMMENT) == 0
1285
681k
#endif
1286
681k
        )
1287
85.6k
      {
1288
85.6k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
85.6k
      }
1290
681k
    break;
1291
414k
  case IMAGE_SCN_MEM_SHARED:
1292
414k
    sec_flags |= SEC_COFF_SHARED;
1293
414k
    break;
1294
680k
  case IMAGE_SCN_LNK_REMOVE:
1295
680k
    if (!is_dbg)
1296
620k
      sec_flags |= SEC_EXCLUDE;
1297
680k
    break;
1298
609k
  case IMAGE_SCN_CNT_CODE:
1299
609k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
609k
    break;
1301
425k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
425k
    if (is_dbg)
1303
35.3k
      sec_flags |= SEC_DEBUGGING;
1304
390k
    else
1305
390k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
425k
    break;
1307
469k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
469k
    sec_flags |= SEC_ALLOC;
1309
469k
    break;
1310
612k
  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
586k
    sec_flags |= SEC_DEBUGGING;
1319
#endif
1320
612k
    break;
1321
565k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
565k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
30.2k
      result = false;
1325
565k
    break;
1326
6.33M
  default:
1327
    /* Silently ignore for now.  */
1328
6.33M
    break;
1329
15.4M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
15.4M
      if (unhandled != NULL)
1333
1.18M
  {
1334
1.18M
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
1.18M
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
1.18M
       abfd, name, unhandled, flag);
1338
1.18M
    result = false;
1339
1.18M
  }
1340
15.4M
    }
1341
1342
3.99M
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
3.99M
      && (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
925k
  if (startswith (name, ".gnu.linkonce"))
1355
511
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
#endif
1357
1358
3.99M
  if (flags_ptr)
1359
3.99M
    * flags_ptr = sec_flags;
1360
1361
3.99M
  return result;
1362
3.99M
}
pei-i386.c:styp_to_sec_flags
Line
Count
Source
1191
282k
{
1192
282k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
282k
  unsigned long styp_flags = internal_s->s_flags;
1194
282k
  flagword sec_flags;
1195
282k
  bool result = true;
1196
282k
  bool is_dbg = false;
1197
1198
282k
  if (startswith (name, DOT_DEBUG)
1199
282k
      || startswith (name, DOT_ZDEBUG)
1200
282k
#ifdef COFF_LONG_SECTION_NAMES
1201
282k
      || startswith (name, GNU_LINKONCE_WI)
1202
282k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
282k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
282k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
282k
      || startswith (name, GNU_DEBUGLINK)
1207
282k
      || startswith (name, GNU_DEBUGALTLINK)
1208
282k
#endif
1209
282k
      || startswith (name, ".stab"))
1210
6.61k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
282k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
282k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
251k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.25M
  while (styp_flags)
1220
973k
    {
1221
973k
      unsigned long flag = styp_flags & - styp_flags;
1222
973k
      char * unhandled = NULL;
1223
1224
973k
      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
973k
      switch (flag)
1231
973k
  {
1232
10.0k
  case STYP_DSECT:
1233
10.0k
    unhandled = "STYP_DSECT";
1234
10.0k
    break;
1235
8.47k
  case STYP_GROUP:
1236
8.47k
    unhandled = "STYP_GROUP";
1237
8.47k
    break;
1238
10.8k
  case STYP_COPY:
1239
10.8k
    unhandled = "STYP_COPY";
1240
10.8k
    break;
1241
8.51k
  case STYP_OVER:
1242
8.51k
    unhandled = "STYP_OVER";
1243
8.51k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
35.1k
  case STYP_NOLOAD:
1246
35.1k
    sec_flags |= SEC_NEVER_LOAD;
1247
35.1k
    break;
1248
0
#endif
1249
30.8k
  case IMAGE_SCN_MEM_READ:
1250
30.8k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
30.8k
    break;
1252
28.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
28.9k
    break;
1255
10.7k
  case IMAGE_SCN_LNK_OTHER:
1256
10.7k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
10.7k
    break;
1258
7.19k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
7.19k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
7.19k
    break;
1261
32.5k
  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
32.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
32.5k
        " %s in section %s"),
1268
32.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
32.5k
    break;
1270
42.6k
  case IMAGE_SCN_MEM_EXECUTE:
1271
42.6k
    sec_flags |= SEC_CODE;
1272
42.6k
    break;
1273
32.5k
  case IMAGE_SCN_MEM_WRITE:
1274
32.5k
    sec_flags &= ~ SEC_READONLY;
1275
32.5k
    break;
1276
41.9k
  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
41.9k
       if (is_dbg
1283
41.9k
#ifdef _COMMENT
1284
41.9k
        || strcmp (name, _COMMENT) == 0
1285
41.9k
#endif
1286
41.9k
        )
1287
4.57k
      {
1288
4.57k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.57k
      }
1290
41.9k
    break;
1291
21.6k
  case IMAGE_SCN_MEM_SHARED:
1292
21.6k
    sec_flags |= SEC_COFF_SHARED;
1293
21.6k
    break;
1294
53.4k
  case IMAGE_SCN_LNK_REMOVE:
1295
53.4k
    if (!is_dbg)
1296
51.3k
      sec_flags |= SEC_EXCLUDE;
1297
53.4k
    break;
1298
37.6k
  case IMAGE_SCN_CNT_CODE:
1299
37.6k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
37.6k
    break;
1301
21.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
21.6k
    if (is_dbg)
1303
1.19k
      sec_flags |= SEC_DEBUGGING;
1304
20.4k
    else
1305
20.4k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
21.6k
    break;
1307
28.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
28.6k
    sec_flags |= SEC_ALLOC;
1309
28.6k
    break;
1310
34.0k
  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
34.0k
#ifdef COFF_PAGE_SIZE
1318
34.0k
    sec_flags |= SEC_DEBUGGING;
1319
34.0k
#endif
1320
34.0k
    break;
1321
42.2k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
42.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2.04k
      result = false;
1325
42.2k
    break;
1326
433k
  default:
1327
    /* Silently ignore for now.  */
1328
433k
    break;
1329
973k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
973k
      if (unhandled != NULL)
1333
55.7k
  {
1334
55.7k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
55.7k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
55.7k
       abfd, name, unhandled, flag);
1338
55.7k
    result = false;
1339
55.7k
  }
1340
973k
    }
1341
1342
282k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
282k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
282k
#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
282k
  if (startswith (name, ".gnu.linkonce"))
1355
67
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
282k
#endif
1357
1358
282k
  if (flags_ptr)
1359
282k
    * flags_ptr = sec_flags;
1360
1361
282k
  return result;
1362
282k
}
pe-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
318k
{
1192
318k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
318k
  unsigned long styp_flags = internal_s->s_flags;
1194
318k
  flagword sec_flags;
1195
318k
  bool result = true;
1196
318k
  bool is_dbg = false;
1197
1198
318k
  if (startswith (name, DOT_DEBUG)
1199
318k
      || startswith (name, DOT_ZDEBUG)
1200
318k
#ifdef COFF_LONG_SECTION_NAMES
1201
318k
      || startswith (name, GNU_LINKONCE_WI)
1202
318k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
318k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
318k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
318k
      || startswith (name, GNU_DEBUGLINK)
1207
318k
      || startswith (name, GNU_DEBUGALTLINK)
1208
318k
#endif
1209
318k
      || startswith (name, ".stab"))
1210
25.3k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
318k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
318k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
252k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
2.03M
  while (styp_flags)
1220
1.71M
    {
1221
1.71M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.71M
      char * unhandled = NULL;
1223
1224
1.71M
      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.71M
      switch (flag)
1231
1.71M
  {
1232
29.3k
  case STYP_DSECT:
1233
29.3k
    unhandled = "STYP_DSECT";
1234
29.3k
    break;
1235
25.8k
  case STYP_GROUP:
1236
25.8k
    unhandled = "STYP_GROUP";
1237
25.8k
    break;
1238
27.2k
  case STYP_COPY:
1239
27.2k
    unhandled = "STYP_COPY";
1240
27.2k
    break;
1241
26.4k
  case STYP_OVER:
1242
26.4k
    unhandled = "STYP_OVER";
1243
26.4k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
70.3k
  case STYP_NOLOAD:
1246
70.3k
    sec_flags |= SEC_NEVER_LOAD;
1247
70.3k
    break;
1248
0
#endif
1249
66.0k
  case IMAGE_SCN_MEM_READ:
1250
66.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
66.0k
    break;
1252
57.7k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
57.7k
    break;
1255
29.1k
  case IMAGE_SCN_LNK_OTHER:
1256
29.1k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
29.1k
    break;
1258
30.1k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
30.1k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
30.1k
    break;
1261
67.0k
  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
67.0k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
67.0k
        " %s in section %s"),
1268
67.0k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
67.0k
    break;
1270
66.4k
  case IMAGE_SCN_MEM_EXECUTE:
1271
66.4k
    sec_flags |= SEC_CODE;
1272
66.4k
    break;
1273
51.3k
  case IMAGE_SCN_MEM_WRITE:
1274
51.3k
    sec_flags &= ~ SEC_READONLY;
1275
51.3k
    break;
1276
79.9k
  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
79.9k
       if (is_dbg
1283
79.9k
#ifdef _COMMENT
1284
79.9k
        || strcmp (name, _COMMENT) == 0
1285
79.9k
#endif
1286
79.9k
        )
1287
10.2k
      {
1288
10.2k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
10.2k
      }
1290
79.9k
    break;
1291
54.7k
  case IMAGE_SCN_MEM_SHARED:
1292
54.7k
    sec_flags |= SEC_COFF_SHARED;
1293
54.7k
    break;
1294
59.6k
  case IMAGE_SCN_LNK_REMOVE:
1295
59.6k
    if (!is_dbg)
1296
54.4k
      sec_flags |= SEC_EXCLUDE;
1297
59.6k
    break;
1298
73.8k
  case IMAGE_SCN_CNT_CODE:
1299
73.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
73.8k
    break;
1301
58.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
58.1k
    if (is_dbg)
1303
4.49k
      sec_flags |= SEC_DEBUGGING;
1304
53.6k
    else
1305
53.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
58.1k
    break;
1307
32.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
32.6k
    sec_flags |= SEC_ALLOC;
1309
32.6k
    break;
1310
67.6k
  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
67.6k
#ifdef COFF_PAGE_SIZE
1318
67.6k
    sec_flags |= SEC_DEBUGGING;
1319
67.6k
#endif
1320
67.6k
    break;
1321
62.7k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
62.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.09k
      result = false;
1325
62.7k
    break;
1326
680k
  default:
1327
    /* Silently ignore for now.  */
1328
680k
    break;
1329
1.71M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.71M
      if (unhandled != NULL)
1333
168k
  {
1334
168k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
168k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
168k
       abfd, name, unhandled, flag);
1338
168k
    result = false;
1339
168k
  }
1340
1.71M
    }
1341
1342
318k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
318k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
318k
#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
318k
  if (startswith (name, ".gnu.linkonce"))
1355
0
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
318k
#endif
1357
1358
318k
  if (flags_ptr)
1359
318k
    * flags_ptr = sec_flags;
1360
1361
318k
  return result;
1362
318k
}
pei-x86_64.c:styp_to_sec_flags
Line
Count
Source
1191
212k
{
1192
212k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
212k
  unsigned long styp_flags = internal_s->s_flags;
1194
212k
  flagword sec_flags;
1195
212k
  bool result = true;
1196
212k
  bool is_dbg = false;
1197
1198
212k
  if (startswith (name, DOT_DEBUG)
1199
212k
      || startswith (name, DOT_ZDEBUG)
1200
212k
#ifdef COFF_LONG_SECTION_NAMES
1201
212k
      || startswith (name, GNU_LINKONCE_WI)
1202
212k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
212k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
212k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
212k
      || startswith (name, GNU_DEBUGLINK)
1207
212k
      || startswith (name, GNU_DEBUGALTLINK)
1208
212k
#endif
1209
212k
      || startswith (name, ".stab"))
1210
25.7k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
212k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
212k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
149k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.46M
  while (styp_flags)
1220
1.24M
    {
1221
1.24M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.24M
      char * unhandled = NULL;
1223
1224
1.24M
      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.24M
      switch (flag)
1231
1.24M
  {
1232
12.2k
  case STYP_DSECT:
1233
12.2k
    unhandled = "STYP_DSECT";
1234
12.2k
    break;
1235
12.5k
  case STYP_GROUP:
1236
12.5k
    unhandled = "STYP_GROUP";
1237
12.5k
    break;
1238
14.2k
  case STYP_COPY:
1239
14.2k
    unhandled = "STYP_COPY";
1240
14.2k
    break;
1241
14.1k
  case STYP_OVER:
1242
14.1k
    unhandled = "STYP_OVER";
1243
14.1k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
34.9k
  case STYP_NOLOAD:
1246
34.9k
    sec_flags |= SEC_NEVER_LOAD;
1247
34.9k
    break;
1248
0
#endif
1249
63.7k
  case IMAGE_SCN_MEM_READ:
1250
63.7k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
63.7k
    break;
1252
25.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
25.9k
    break;
1255
13.4k
  case IMAGE_SCN_LNK_OTHER:
1256
13.4k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
13.4k
    break;
1258
9.84k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
9.84k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
9.84k
    break;
1261
48.1k
  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
48.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
48.1k
        " %s in section %s"),
1268
48.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
48.1k
    break;
1270
42.0k
  case IMAGE_SCN_MEM_EXECUTE:
1271
42.0k
    sec_flags |= SEC_CODE;
1272
42.0k
    break;
1273
32.9k
  case IMAGE_SCN_MEM_WRITE:
1274
32.9k
    sec_flags &= ~ SEC_READONLY;
1275
32.9k
    break;
1276
61.1k
  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
61.1k
       if (is_dbg
1283
61.1k
#ifdef _COMMENT
1284
61.1k
        || strcmp (name, _COMMENT) == 0
1285
61.1k
#endif
1286
61.1k
        )
1287
12.3k
      {
1288
12.3k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
12.3k
      }
1290
61.1k
    break;
1291
40.8k
  case IMAGE_SCN_MEM_SHARED:
1292
40.8k
    sec_flags |= SEC_COFF_SHARED;
1293
40.8k
    break;
1294
59.0k
  case IMAGE_SCN_LNK_REMOVE:
1295
59.0k
    if (!is_dbg)
1296
39.0k
      sec_flags |= SEC_EXCLUDE;
1297
59.0k
    break;
1298
59.8k
  case IMAGE_SCN_CNT_CODE:
1299
59.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
59.8k
    break;
1301
36.7k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
36.7k
    if (is_dbg)
1303
4.42k
      sec_flags |= SEC_DEBUGGING;
1304
32.3k
    else
1305
32.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
36.7k
    break;
1307
32.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
32.7k
    sec_flags |= SEC_ALLOC;
1309
32.7k
    break;
1310
56.6k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
56.6k
#ifdef COFF_PAGE_SIZE
1318
56.6k
    sec_flags |= SEC_DEBUGGING;
1319
56.6k
#endif
1320
56.6k
    break;
1321
55.1k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
55.1k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2.37k
      result = false;
1325
55.1k
    break;
1326
521k
  default:
1327
    /* Silently ignore for now.  */
1328
521k
    break;
1329
1.24M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.24M
      if (unhandled != NULL)
1333
76.4k
  {
1334
76.4k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
76.4k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
76.4k
       abfd, name, unhandled, flag);
1338
76.4k
    result = false;
1339
76.4k
  }
1340
1.24M
    }
1341
1342
212k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
212k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
212k
#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
212k
  if (startswith (name, ".gnu.linkonce"))
1355
57
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
212k
#endif
1357
1358
212k
  if (flags_ptr)
1359
212k
    * flags_ptr = sec_flags;
1360
1361
212k
  return result;
1362
212k
}
pe-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
123k
{
1192
123k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
123k
  unsigned long styp_flags = internal_s->s_flags;
1194
123k
  flagword sec_flags;
1195
123k
  bool result = true;
1196
123k
  bool is_dbg = false;
1197
1198
123k
  if (startswith (name, DOT_DEBUG)
1199
123k
      || startswith (name, DOT_ZDEBUG)
1200
123k
#ifdef COFF_LONG_SECTION_NAMES
1201
123k
      || startswith (name, GNU_LINKONCE_WI)
1202
123k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
123k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
123k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
123k
      || startswith (name, GNU_DEBUGLINK)
1207
123k
      || startswith (name, GNU_DEBUGALTLINK)
1208
123k
#endif
1209
123k
      || startswith (name, ".stab"))
1210
5.01k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
123k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
123k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
97.0k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
714k
  while (styp_flags)
1220
591k
    {
1221
591k
      unsigned long flag = styp_flags & - styp_flags;
1222
591k
      char * unhandled = NULL;
1223
1224
591k
      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
591k
      switch (flag)
1231
591k
  {
1232
3.47k
  case STYP_DSECT:
1233
3.47k
    unhandled = "STYP_DSECT";
1234
3.47k
    break;
1235
2.86k
  case STYP_GROUP:
1236
2.86k
    unhandled = "STYP_GROUP";
1237
2.86k
    break;
1238
4.02k
  case STYP_COPY:
1239
4.02k
    unhandled = "STYP_COPY";
1240
4.02k
    break;
1241
4.60k
  case STYP_OVER:
1242
4.60k
    unhandled = "STYP_OVER";
1243
4.60k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
21.4k
  case STYP_NOLOAD:
1246
21.4k
    sec_flags |= SEC_NEVER_LOAD;
1247
21.4k
    break;
1248
0
#endif
1249
26.0k
  case IMAGE_SCN_MEM_READ:
1250
26.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
26.0k
    break;
1252
19.0k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
19.0k
    break;
1255
4.67k
  case IMAGE_SCN_LNK_OTHER:
1256
4.67k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
4.67k
    break;
1258
4.45k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
4.45k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
4.45k
    break;
1261
25.7k
  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
25.7k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
25.7k
        " %s in section %s"),
1268
25.7k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
25.7k
    break;
1270
30.0k
  case IMAGE_SCN_MEM_EXECUTE:
1271
30.0k
    sec_flags |= SEC_CODE;
1272
30.0k
    break;
1273
23.1k
  case IMAGE_SCN_MEM_WRITE:
1274
23.1k
    sec_flags &= ~ SEC_READONLY;
1275
23.1k
    break;
1276
25.3k
  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
25.3k
       if (is_dbg
1283
25.3k
#ifdef _COMMENT
1284
25.3k
        || strcmp (name, _COMMENT) == 0
1285
25.3k
#endif
1286
25.3k
        )
1287
2.84k
      {
1288
2.84k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2.84k
      }
1290
25.3k
    break;
1291
14.8k
  case IMAGE_SCN_MEM_SHARED:
1292
14.8k
    sec_flags |= SEC_COFF_SHARED;
1293
14.8k
    break;
1294
24.4k
  case IMAGE_SCN_LNK_REMOVE:
1295
24.4k
    if (!is_dbg)
1296
22.6k
      sec_flags |= SEC_EXCLUDE;
1297
24.4k
    break;
1298
19.5k
  case IMAGE_SCN_CNT_CODE:
1299
19.5k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
19.5k
    break;
1301
14.8k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
14.8k
    if (is_dbg)
1303
1.19k
      sec_flags |= SEC_DEBUGGING;
1304
13.6k
    else
1305
13.6k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
14.8k
    break;
1307
20.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
20.5k
    sec_flags |= SEC_ALLOC;
1309
20.5k
    break;
1310
24.4k
  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
24.4k
#ifdef COFF_PAGE_SIZE
1318
24.4k
    sec_flags |= SEC_DEBUGGING;
1319
24.4k
#endif
1320
24.4k
    break;
1321
17.4k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
17.4k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
595
      result = false;
1325
17.4k
    break;
1326
260k
  default:
1327
    /* Silently ignore for now.  */
1328
260k
    break;
1329
591k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
591k
      if (unhandled != NULL)
1333
24.0k
  {
1334
24.0k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
24.0k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
24.0k
       abfd, name, unhandled, flag);
1338
24.0k
    result = false;
1339
24.0k
  }
1340
591k
    }
1341
1342
123k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
123k
      && (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
123k
  if (flags_ptr)
1359
123k
    * flags_ptr = sec_flags;
1360
1361
123k
  return result;
1362
123k
}
pei-aarch64.c:styp_to_sec_flags
Line
Count
Source
1191
155k
{
1192
155k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
155k
  unsigned long styp_flags = internal_s->s_flags;
1194
155k
  flagword sec_flags;
1195
155k
  bool result = true;
1196
155k
  bool is_dbg = false;
1197
1198
155k
  if (startswith (name, DOT_DEBUG)
1199
155k
      || startswith (name, DOT_ZDEBUG)
1200
155k
#ifdef COFF_LONG_SECTION_NAMES
1201
155k
      || startswith (name, GNU_LINKONCE_WI)
1202
155k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
155k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
155k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
155k
      || startswith (name, GNU_DEBUGLINK)
1207
155k
      || startswith (name, GNU_DEBUGALTLINK)
1208
155k
#endif
1209
155k
      || startswith (name, ".stab"))
1210
4.22k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
155k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
155k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
113k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.13M
  while (styp_flags)
1220
982k
    {
1221
982k
      unsigned long flag = styp_flags & - styp_flags;
1222
982k
      char * unhandled = NULL;
1223
1224
982k
      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
982k
      switch (flag)
1231
982k
  {
1232
9.57k
  case STYP_DSECT:
1233
9.57k
    unhandled = "STYP_DSECT";
1234
9.57k
    break;
1235
8.77k
  case STYP_GROUP:
1236
8.77k
    unhandled = "STYP_GROUP";
1237
8.77k
    break;
1238
13.3k
  case STYP_COPY:
1239
13.3k
    unhandled = "STYP_COPY";
1240
13.3k
    break;
1241
6.55k
  case STYP_OVER:
1242
6.55k
    unhandled = "STYP_OVER";
1243
6.55k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
32.6k
  case STYP_NOLOAD:
1246
32.6k
    sec_flags |= SEC_NEVER_LOAD;
1247
32.6k
    break;
1248
0
#endif
1249
42.1k
  case IMAGE_SCN_MEM_READ:
1250
42.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
42.1k
    break;
1252
38.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
38.3k
    break;
1255
8.24k
  case IMAGE_SCN_LNK_OTHER:
1256
8.24k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
8.24k
    break;
1258
12.7k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
12.7k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
12.7k
    break;
1261
42.1k
  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
42.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
42.1k
        " %s in section %s"),
1268
42.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
42.1k
    break;
1270
46.4k
  case IMAGE_SCN_MEM_EXECUTE:
1271
46.4k
    sec_flags |= SEC_CODE;
1272
46.4k
    break;
1273
33.1k
  case IMAGE_SCN_MEM_WRITE:
1274
33.1k
    sec_flags &= ~ SEC_READONLY;
1275
33.1k
    break;
1276
33.6k
  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
33.6k
       if (is_dbg
1283
33.6k
#ifdef _COMMENT
1284
33.6k
        || strcmp (name, _COMMENT) == 0
1285
33.6k
#endif
1286
33.6k
        )
1287
2.30k
      {
1288
2.30k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2.30k
      }
1290
33.6k
    break;
1291
28.4k
  case IMAGE_SCN_MEM_SHARED:
1292
28.4k
    sec_flags |= SEC_COFF_SHARED;
1293
28.4k
    break;
1294
43.5k
  case IMAGE_SCN_LNK_REMOVE:
1295
43.5k
    if (!is_dbg)
1296
42.1k
      sec_flags |= SEC_EXCLUDE;
1297
43.5k
    break;
1298
44.9k
  case IMAGE_SCN_CNT_CODE:
1299
44.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
44.9k
    break;
1301
29.3k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
29.3k
    if (is_dbg)
1303
1.88k
      sec_flags |= SEC_DEBUGGING;
1304
27.4k
    else
1305
27.4k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
29.3k
    break;
1307
26.0k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
26.0k
    sec_flags |= SEC_ALLOC;
1309
26.0k
    break;
1310
33.9k
  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
33.9k
#ifdef COFF_PAGE_SIZE
1318
33.9k
    sec_flags |= SEC_DEBUGGING;
1319
33.9k
#endif
1320
33.9k
    break;
1321
37.3k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
37.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
4.09k
      result = false;
1325
37.3k
    break;
1326
410k
  default:
1327
    /* Silently ignore for now.  */
1328
410k
    break;
1329
982k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
982k
      if (unhandled != NULL)
1333
59.2k
  {
1334
59.2k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
59.2k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
59.2k
       abfd, name, unhandled, flag);
1338
59.2k
    result = false;
1339
59.2k
  }
1340
982k
    }
1341
1342
155k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
155k
      && (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
155k
  if (flags_ptr)
1359
155k
    * flags_ptr = sec_flags;
1360
1361
155k
  return result;
1362
155k
}
pei-ia64.c:styp_to_sec_flags
Line
Count
Source
1191
221k
{
1192
221k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
221k
  unsigned long styp_flags = internal_s->s_flags;
1194
221k
  flagword sec_flags;
1195
221k
  bool result = true;
1196
221k
  bool is_dbg = false;
1197
1198
221k
  if (startswith (name, DOT_DEBUG)
1199
221k
      || startswith (name, DOT_ZDEBUG)
1200
221k
#ifdef COFF_LONG_SECTION_NAMES
1201
221k
      || startswith (name, GNU_LINKONCE_WI)
1202
221k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
221k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
221k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
221k
      || startswith (name, GNU_DEBUGLINK)
1207
221k
      || startswith (name, GNU_DEBUGALTLINK)
1208
221k
#endif
1209
221k
      || startswith (name, ".stab"))
1210
13.9k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
221k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
221k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
179k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.41M
  while (styp_flags)
1220
1.19M
    {
1221
1.19M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.19M
      char * unhandled = NULL;
1223
1224
1.19M
      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.19M
      switch (flag)
1231
1.19M
  {
1232
14.5k
  case STYP_DSECT:
1233
14.5k
    unhandled = "STYP_DSECT";
1234
14.5k
    break;
1235
17.4k
  case STYP_GROUP:
1236
17.4k
    unhandled = "STYP_GROUP";
1237
17.4k
    break;
1238
16.3k
  case STYP_COPY:
1239
16.3k
    unhandled = "STYP_COPY";
1240
16.3k
    break;
1241
15.6k
  case STYP_OVER:
1242
15.6k
    unhandled = "STYP_OVER";
1243
15.6k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
45.4k
  case STYP_NOLOAD:
1246
45.4k
    sec_flags |= SEC_NEVER_LOAD;
1247
45.4k
    break;
1248
0
#endif
1249
42.3k
  case IMAGE_SCN_MEM_READ:
1250
42.3k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
42.3k
    break;
1252
35.8k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
35.8k
    break;
1255
16.9k
  case IMAGE_SCN_LNK_OTHER:
1256
16.9k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
16.9k
    break;
1258
16.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
16.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
16.2k
    break;
1261
42.9k
  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
42.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
42.9k
        " %s in section %s"),
1268
42.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
42.9k
    break;
1270
50.9k
  case IMAGE_SCN_MEM_EXECUTE:
1271
50.9k
    sec_flags |= SEC_CODE;
1272
50.9k
    break;
1273
37.4k
  case IMAGE_SCN_MEM_WRITE:
1274
37.4k
    sec_flags &= ~ SEC_READONLY;
1275
37.4k
    break;
1276
61.6k
  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
61.6k
       if (is_dbg
1283
61.6k
#ifdef _COMMENT
1284
61.6k
        || strcmp (name, _COMMENT) == 0
1285
61.6k
#endif
1286
61.6k
        )
1287
10.2k
      {
1288
10.2k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
10.2k
      }
1290
61.6k
    break;
1291
29.3k
  case IMAGE_SCN_MEM_SHARED:
1292
29.3k
    sec_flags |= SEC_COFF_SHARED;
1293
29.3k
    break;
1294
49.5k
  case IMAGE_SCN_LNK_REMOVE:
1295
49.5k
    if (!is_dbg)
1296
44.2k
      sec_flags |= SEC_EXCLUDE;
1297
49.5k
    break;
1298
43.8k
  case IMAGE_SCN_CNT_CODE:
1299
43.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
43.8k
    break;
1301
32.1k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
32.1k
    if (is_dbg)
1303
2.88k
      sec_flags |= SEC_DEBUGGING;
1304
29.2k
    else
1305
29.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
32.1k
    break;
1307
35.4k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
35.4k
    sec_flags |= SEC_ALLOC;
1309
35.4k
    break;
1310
53.5k
  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
53.5k
#ifdef COFF_PAGE_SIZE
1318
53.5k
    sec_flags |= SEC_DEBUGGING;
1319
53.5k
#endif
1320
53.5k
    break;
1321
49.5k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
49.5k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
3.95k
      result = false;
1325
49.5k
    break;
1326
489k
  default:
1327
    /* Silently ignore for now.  */
1328
489k
    break;
1329
1.19M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.19M
      if (unhandled != NULL)
1333
97.2k
  {
1334
97.2k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
97.2k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
97.2k
       abfd, name, unhandled, flag);
1338
97.2k
    result = false;
1339
97.2k
  }
1340
1.19M
    }
1341
1342
221k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
221k
      && (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
221k
  if (flags_ptr)
1359
221k
    * flags_ptr = sec_flags;
1360
1361
221k
  return result;
1362
221k
}
pei-loongarch64.c:styp_to_sec_flags
Line
Count
Source
1191
168k
{
1192
168k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
168k
  unsigned long styp_flags = internal_s->s_flags;
1194
168k
  flagword sec_flags;
1195
168k
  bool result = true;
1196
168k
  bool is_dbg = false;
1197
1198
168k
  if (startswith (name, DOT_DEBUG)
1199
168k
      || startswith (name, DOT_ZDEBUG)
1200
168k
#ifdef COFF_LONG_SECTION_NAMES
1201
168k
      || startswith (name, GNU_LINKONCE_WI)
1202
168k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
168k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
168k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
168k
      || startswith (name, GNU_DEBUGLINK)
1207
168k
      || startswith (name, GNU_DEBUGALTLINK)
1208
168k
#endif
1209
168k
      || startswith (name, ".stab"))
1210
5.36k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
168k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
168k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
135k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.07M
  while (styp_flags)
1220
901k
    {
1221
901k
      unsigned long flag = styp_flags & - styp_flags;
1222
901k
      char * unhandled = NULL;
1223
1224
901k
      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
901k
      switch (flag)
1231
901k
  {
1232
9.49k
  case STYP_DSECT:
1233
9.49k
    unhandled = "STYP_DSECT";
1234
9.49k
    break;
1235
8.21k
  case STYP_GROUP:
1236
8.21k
    unhandled = "STYP_GROUP";
1237
8.21k
    break;
1238
9.98k
  case STYP_COPY:
1239
9.98k
    unhandled = "STYP_COPY";
1240
9.98k
    break;
1241
10.3k
  case STYP_OVER:
1242
10.3k
    unhandled = "STYP_OVER";
1243
10.3k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
29.0k
  case STYP_NOLOAD:
1246
29.0k
    sec_flags |= SEC_NEVER_LOAD;
1247
29.0k
    break;
1248
0
#endif
1249
33.1k
  case IMAGE_SCN_MEM_READ:
1250
33.1k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
33.1k
    break;
1252
31.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
31.9k
    break;
1255
10.3k
  case IMAGE_SCN_LNK_OTHER:
1256
10.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
10.3k
    break;
1258
8.57k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
8.57k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
8.57k
    break;
1261
38.1k
  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
38.1k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
38.1k
        " %s in section %s"),
1268
38.1k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
38.1k
    break;
1270
45.2k
  case IMAGE_SCN_MEM_EXECUTE:
1271
45.2k
    sec_flags |= SEC_CODE;
1272
45.2k
    break;
1273
33.9k
  case IMAGE_SCN_MEM_WRITE:
1274
33.9k
    sec_flags &= ~ SEC_READONLY;
1275
33.9k
    break;
1276
42.3k
  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
42.3k
       if (is_dbg
1283
42.3k
#ifdef _COMMENT
1284
42.3k
        || strcmp (name, _COMMENT) == 0
1285
42.3k
#endif
1286
42.3k
        )
1287
2.96k
      {
1288
2.96k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2.96k
      }
1290
42.3k
    break;
1291
18.8k
  case IMAGE_SCN_MEM_SHARED:
1292
18.8k
    sec_flags |= SEC_COFF_SHARED;
1293
18.8k
    break;
1294
38.4k
  case IMAGE_SCN_LNK_REMOVE:
1295
38.4k
    if (!is_dbg)
1296
35.8k
      sec_flags |= SEC_EXCLUDE;
1297
38.4k
    break;
1298
39.1k
  case IMAGE_SCN_CNT_CODE:
1299
39.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
39.1k
    break;
1301
29.3k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
29.3k
    if (is_dbg)
1303
1.90k
      sec_flags |= SEC_DEBUGGING;
1304
27.3k
    else
1305
27.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
29.3k
    break;
1307
28.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
28.7k
    sec_flags |= SEC_ALLOC;
1309
28.7k
    break;
1310
37.8k
  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.8k
#ifdef COFF_PAGE_SIZE
1318
37.8k
    sec_flags |= SEC_DEBUGGING;
1319
37.8k
#endif
1320
37.8k
    break;
1321
26.3k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
26.3k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.35k
      result = false;
1325
26.3k
    break;
1326
372k
  default:
1327
    /* Silently ignore for now.  */
1328
372k
    break;
1329
901k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
901k
      if (unhandled != NULL)
1333
56.9k
  {
1334
56.9k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
56.9k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
56.9k
       abfd, name, unhandled, flag);
1338
56.9k
    result = false;
1339
56.9k
  }
1340
901k
    }
1341
1342
168k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
168k
      && (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
168k
  if (flags_ptr)
1359
168k
    * flags_ptr = sec_flags;
1360
1361
168k
  return result;
1362
168k
}
pe-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
40.6k
{
1192
40.6k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
40.6k
  unsigned long styp_flags = internal_s->s_flags;
1194
40.6k
  flagword sec_flags;
1195
40.6k
  bool result = true;
1196
40.6k
  bool is_dbg = false;
1197
1198
40.6k
  if (startswith (name, DOT_DEBUG)
1199
40.6k
      || startswith (name, DOT_ZDEBUG)
1200
40.6k
#ifdef COFF_LONG_SECTION_NAMES
1201
40.6k
      || startswith (name, GNU_LINKONCE_WI)
1202
40.6k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
40.6k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
40.6k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
40.6k
      || startswith (name, GNU_DEBUGLINK)
1207
40.6k
      || startswith (name, GNU_DEBUGALTLINK)
1208
40.6k
#endif
1209
40.6k
      || startswith (name, ".stab"))
1210
5.24k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
40.6k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
40.6k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
30.9k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
319k
  while (styp_flags)
1220
279k
    {
1221
279k
      unsigned long flag = styp_flags & - styp_flags;
1222
279k
      char * unhandled = NULL;
1223
1224
279k
      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
279k
      switch (flag)
1231
279k
  {
1232
4.39k
  case STYP_DSECT:
1233
4.39k
    unhandled = "STYP_DSECT";
1234
4.39k
    break;
1235
4.28k
  case STYP_GROUP:
1236
4.28k
    unhandled = "STYP_GROUP";
1237
4.28k
    break;
1238
4.29k
  case STYP_COPY:
1239
4.29k
    unhandled = "STYP_COPY";
1240
4.29k
    break;
1241
4.38k
  case STYP_OVER:
1242
4.38k
    unhandled = "STYP_OVER";
1243
4.38k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
8.78k
  case STYP_NOLOAD:
1246
8.78k
    sec_flags |= SEC_NEVER_LOAD;
1247
8.78k
    break;
1248
0
#endif
1249
9.70k
  case IMAGE_SCN_MEM_READ:
1250
9.70k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
9.70k
    break;
1252
8.01k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
8.01k
    break;
1255
5.26k
  case IMAGE_SCN_LNK_OTHER:
1256
5.26k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
5.26k
    break;
1258
5.34k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
5.34k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
5.34k
    break;
1261
10.6k
  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
10.6k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
10.6k
        " %s in section %s"),
1268
10.6k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
10.6k
    break;
1270
11.1k
  case IMAGE_SCN_MEM_EXECUTE:
1271
11.1k
    sec_flags |= SEC_CODE;
1272
11.1k
    break;
1273
7.10k
  case IMAGE_SCN_MEM_WRITE:
1274
7.10k
    sec_flags &= ~ SEC_READONLY;
1275
7.10k
    break;
1276
12.4k
  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
12.4k
       if (is_dbg
1283
12.4k
#ifdef _COMMENT
1284
12.4k
        || strcmp (name, _COMMENT) == 0
1285
12.4k
#endif
1286
12.4k
        )
1287
4.36k
      {
1288
4.36k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.36k
      }
1290
12.4k
    break;
1291
7.59k
  case IMAGE_SCN_MEM_SHARED:
1292
7.59k
    sec_flags |= SEC_COFF_SHARED;
1293
7.59k
    break;
1294
12.5k
  case IMAGE_SCN_LNK_REMOVE:
1295
12.5k
    if (!is_dbg)
1296
8.69k
      sec_flags |= SEC_EXCLUDE;
1297
12.5k
    break;
1298
15.8k
  case IMAGE_SCN_CNT_CODE:
1299
15.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
15.8k
    break;
1301
6.13k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
6.13k
    if (is_dbg)
1303
580
      sec_flags |= SEC_DEBUGGING;
1304
5.55k
    else
1305
5.55k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
6.13k
    break;
1307
7.22k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
7.22k
    sec_flags |= SEC_ALLOC;
1309
7.22k
    break;
1310
13.7k
  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
13.7k
#ifdef COFF_PAGE_SIZE
1318
13.7k
    sec_flags |= SEC_DEBUGGING;
1319
13.7k
#endif
1320
13.7k
    break;
1321
12.1k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
12.1k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.27k
      result = false;
1325
12.1k
    break;
1326
107k
  default:
1327
    /* Silently ignore for now.  */
1328
107k
    break;
1329
279k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
279k
      if (unhandled != NULL)
1333
27.9k
  {
1334
27.9k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
27.9k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
27.9k
       abfd, name, unhandled, flag);
1338
27.9k
    result = false;
1339
27.9k
  }
1340
279k
    }
1341
1342
40.6k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
40.6k
      && (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
40.6k
  if (flags_ptr)
1359
40.6k
    * flags_ptr = sec_flags;
1360
1361
40.6k
  return result;
1362
40.6k
}
pe-arm.c:styp_to_sec_flags
Line
Count
Source
1191
40.6k
{
1192
40.6k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
40.6k
  unsigned long styp_flags = internal_s->s_flags;
1194
40.6k
  flagword sec_flags;
1195
40.6k
  bool result = true;
1196
40.6k
  bool is_dbg = false;
1197
1198
40.6k
  if (startswith (name, DOT_DEBUG)
1199
40.6k
      || startswith (name, DOT_ZDEBUG)
1200
40.6k
#ifdef COFF_LONG_SECTION_NAMES
1201
40.6k
      || startswith (name, GNU_LINKONCE_WI)
1202
40.6k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
40.6k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
40.6k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
40.6k
      || startswith (name, GNU_DEBUGLINK)
1207
40.6k
      || startswith (name, GNU_DEBUGALTLINK)
1208
40.6k
#endif
1209
40.6k
      || startswith (name, ".stab"))
1210
5.24k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
40.6k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
40.6k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
30.9k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
319k
  while (styp_flags)
1220
279k
    {
1221
279k
      unsigned long flag = styp_flags & - styp_flags;
1222
279k
      char * unhandled = NULL;
1223
1224
279k
      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
279k
      switch (flag)
1231
279k
  {
1232
4.39k
  case STYP_DSECT:
1233
4.39k
    unhandled = "STYP_DSECT";
1234
4.39k
    break;
1235
4.28k
  case STYP_GROUP:
1236
4.28k
    unhandled = "STYP_GROUP";
1237
4.28k
    break;
1238
4.29k
  case STYP_COPY:
1239
4.29k
    unhandled = "STYP_COPY";
1240
4.29k
    break;
1241
4.38k
  case STYP_OVER:
1242
4.38k
    unhandled = "STYP_OVER";
1243
4.38k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
8.78k
  case STYP_NOLOAD:
1246
8.78k
    sec_flags |= SEC_NEVER_LOAD;
1247
8.78k
    break;
1248
0
#endif
1249
9.70k
  case IMAGE_SCN_MEM_READ:
1250
9.70k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
9.70k
    break;
1252
8.01k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
8.01k
    break;
1255
5.26k
  case IMAGE_SCN_LNK_OTHER:
1256
5.26k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
5.26k
    break;
1258
5.34k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
5.34k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
5.34k
    break;
1261
10.6k
  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
10.6k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
10.6k
        " %s in section %s"),
1268
10.6k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
10.6k
    break;
1270
11.1k
  case IMAGE_SCN_MEM_EXECUTE:
1271
11.1k
    sec_flags |= SEC_CODE;
1272
11.1k
    break;
1273
7.10k
  case IMAGE_SCN_MEM_WRITE:
1274
7.10k
    sec_flags &= ~ SEC_READONLY;
1275
7.10k
    break;
1276
12.4k
  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
12.4k
       if (is_dbg
1283
12.4k
#ifdef _COMMENT
1284
12.4k
        || strcmp (name, _COMMENT) == 0
1285
12.4k
#endif
1286
12.4k
        )
1287
4.36k
      {
1288
4.36k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.36k
      }
1290
12.4k
    break;
1291
7.59k
  case IMAGE_SCN_MEM_SHARED:
1292
7.59k
    sec_flags |= SEC_COFF_SHARED;
1293
7.59k
    break;
1294
12.5k
  case IMAGE_SCN_LNK_REMOVE:
1295
12.5k
    if (!is_dbg)
1296
8.69k
      sec_flags |= SEC_EXCLUDE;
1297
12.5k
    break;
1298
15.8k
  case IMAGE_SCN_CNT_CODE:
1299
15.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
15.8k
    break;
1301
6.13k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
6.13k
    if (is_dbg)
1303
580
      sec_flags |= SEC_DEBUGGING;
1304
5.55k
    else
1305
5.55k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
6.13k
    break;
1307
7.22k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
7.22k
    sec_flags |= SEC_ALLOC;
1309
7.22k
    break;
1310
13.7k
  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
13.7k
#ifdef COFF_PAGE_SIZE
1318
13.7k
    sec_flags |= SEC_DEBUGGING;
1319
13.7k
#endif
1320
13.7k
    break;
1321
12.1k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
12.1k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.27k
      result = false;
1325
12.1k
    break;
1326
107k
  default:
1327
    /* Silently ignore for now.  */
1328
107k
    break;
1329
279k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
279k
      if (unhandled != NULL)
1333
27.9k
  {
1334
27.9k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
27.9k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
27.9k
       abfd, name, unhandled, flag);
1338
27.9k
    result = false;
1339
27.9k
  }
1340
279k
    }
1341
1342
40.6k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
40.6k
      && (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
40.6k
  if (flags_ptr)
1359
40.6k
    * flags_ptr = sec_flags;
1360
1361
40.6k
  return result;
1362
40.6k
}
pe-i386.c:styp_to_sec_flags
Line
Count
Source
1191
111k
{
1192
111k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
111k
  unsigned long styp_flags = internal_s->s_flags;
1194
111k
  flagword sec_flags;
1195
111k
  bool result = true;
1196
111k
  bool is_dbg = false;
1197
1198
111k
  if (startswith (name, DOT_DEBUG)
1199
111k
      || startswith (name, DOT_ZDEBUG)
1200
111k
#ifdef COFF_LONG_SECTION_NAMES
1201
111k
      || startswith (name, GNU_LINKONCE_WI)
1202
111k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
111k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
111k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
111k
      || startswith (name, GNU_DEBUGLINK)
1207
111k
      || startswith (name, GNU_DEBUGALTLINK)
1208
111k
#endif
1209
111k
      || startswith (name, ".stab"))
1210
11.4k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
111k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
111k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
77.9k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
959k
  while (styp_flags)
1220
847k
    {
1221
847k
      unsigned long flag = styp_flags & - styp_flags;
1222
847k
      char * unhandled = NULL;
1223
1224
847k
      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
847k
      switch (flag)
1231
847k
  {
1232
14.4k
  case STYP_DSECT:
1233
14.4k
    unhandled = "STYP_DSECT";
1234
14.4k
    break;
1235
14.6k
  case STYP_GROUP:
1236
14.6k
    unhandled = "STYP_GROUP";
1237
14.6k
    break;
1238
16.6k
  case STYP_COPY:
1239
16.6k
    unhandled = "STYP_COPY";
1240
16.6k
    break;
1241
16.1k
  case STYP_OVER:
1242
16.1k
    unhandled = "STYP_OVER";
1243
16.1k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
25.8k
  case STYP_NOLOAD:
1246
25.8k
    sec_flags |= SEC_NEVER_LOAD;
1247
25.8k
    break;
1248
0
#endif
1249
33.4k
  case IMAGE_SCN_MEM_READ:
1250
33.4k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
33.4k
    break;
1252
23.3k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
23.3k
    break;
1255
16.3k
  case IMAGE_SCN_LNK_OTHER:
1256
16.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
16.3k
    break;
1258
17.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
17.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
17.2k
    break;
1261
30.4k
  case IMAGE_SCN_MEM_NOT_PAGED:
1262
    /* Generate a warning message rather using the 'unhandled'
1263
       variable as this will allow some .sys files generate by
1264
       other toolchains to be processed.  See bugzilla issue 196.  */
1265
    /* xgettext:c-format */
1266
30.4k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
30.4k
        " %s in section %s"),
1268
30.4k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
30.4k
    break;
1270
33.5k
  case IMAGE_SCN_MEM_EXECUTE:
1271
33.5k
    sec_flags |= SEC_CODE;
1272
33.5k
    break;
1273
27.7k
  case IMAGE_SCN_MEM_WRITE:
1274
27.7k
    sec_flags &= ~ SEC_READONLY;
1275
27.7k
    break;
1276
36.9k
  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
36.9k
       if (is_dbg
1283
36.9k
#ifdef _COMMENT
1284
36.9k
        || strcmp (name, _COMMENT) == 0
1285
36.9k
#endif
1286
36.9k
        )
1287
6.46k
      {
1288
6.46k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
6.46k
      }
1290
36.9k
    break;
1291
28.0k
  case IMAGE_SCN_MEM_SHARED:
1292
28.0k
    sec_flags |= SEC_COFF_SHARED;
1293
28.0k
    break;
1294
27.8k
  case IMAGE_SCN_LNK_REMOVE:
1295
27.8k
    if (!is_dbg)
1296
24.6k
      sec_flags |= SEC_EXCLUDE;
1297
27.8k
    break;
1298
26.1k
  case IMAGE_SCN_CNT_CODE:
1299
26.1k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
26.1k
    break;
1301
26.0k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
26.0k
    if (is_dbg)
1303
4.69k
      sec_flags |= SEC_DEBUGGING;
1304
21.3k
    else
1305
21.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
26.0k
    break;
1307
19.5k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
19.5k
    sec_flags |= SEC_ALLOC;
1309
19.5k
    break;
1310
30.0k
  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
30.0k
#ifdef COFF_PAGE_SIZE
1318
30.0k
    sec_flags |= SEC_DEBUGGING;
1319
30.0k
#endif
1320
30.0k
    break;
1321
32.8k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
32.8k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.34k
      result = false;
1325
32.8k
    break;
1326
350k
  default:
1327
    /* Silently ignore for now.  */
1328
350k
    break;
1329
847k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
847k
      if (unhandled != NULL)
1333
95.6k
  {
1334
95.6k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
95.6k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
95.6k
       abfd, name, unhandled, flag);
1338
95.6k
    result = false;
1339
95.6k
  }
1340
847k
    }
1341
1342
111k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
111k
      && (startswith (name, ".sbss")
1344
0
    || startswith (name, ".sdata")))
1345
0
    sec_flags |= SEC_SMALL_DATA;
1346
1347
111k
#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
111k
  if (startswith (name, ".gnu.linkonce"))
1355
387
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1356
111k
#endif
1357
1358
111k
  if (flags_ptr)
1359
111k
    * flags_ptr = sec_flags;
1360
1361
111k
  return result;
1362
111k
}
pe-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
806k
{
1192
806k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
806k
  unsigned long styp_flags = internal_s->s_flags;
1194
806k
  flagword sec_flags;
1195
806k
  bool result = true;
1196
806k
  bool is_dbg = false;
1197
1198
806k
  if (startswith (name, DOT_DEBUG)
1199
806k
      || startswith (name, DOT_ZDEBUG)
1200
806k
#ifdef COFF_LONG_SECTION_NAMES
1201
806k
      || startswith (name, GNU_LINKONCE_WI)
1202
806k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
806k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
806k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
806k
      || startswith (name, GNU_DEBUGLINK)
1207
806k
      || startswith (name, GNU_DEBUGALTLINK)
1208
806k
#endif
1209
806k
      || startswith (name, ".stab"))
1210
6.92k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
806k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
806k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
778k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.35M
  while (styp_flags)
1220
549k
    {
1221
549k
      unsigned long flag = styp_flags & - styp_flags;
1222
549k
      char * unhandled = NULL;
1223
1224
549k
      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
549k
      switch (flag)
1231
549k
  {
1232
2.29k
  case STYP_DSECT:
1233
2.29k
    unhandled = "STYP_DSECT";
1234
2.29k
    break;
1235
2.99k
  case STYP_GROUP:
1236
2.99k
    unhandled = "STYP_GROUP";
1237
2.99k
    break;
1238
2.59k
  case STYP_COPY:
1239
2.59k
    unhandled = "STYP_COPY";
1240
2.59k
    break;
1241
3.12k
  case STYP_OVER:
1242
3.12k
    unhandled = "STYP_OVER";
1243
3.12k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
16.9k
  case STYP_NOLOAD:
1246
16.9k
    sec_flags |= SEC_NEVER_LOAD;
1247
16.9k
    break;
1248
0
#endif
1249
28.3k
  case IMAGE_SCN_MEM_READ:
1250
28.3k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
28.3k
    break;
1252
13.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
13.6k
    break;
1255
3.35k
  case IMAGE_SCN_LNK_OTHER:
1256
3.35k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
3.35k
    break;
1258
3.25k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
3.25k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
3.25k
    break;
1261
19.6k
  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
19.6k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
19.6k
        " %s in section %s"),
1268
19.6k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
19.6k
    break;
1270
30.1k
  case IMAGE_SCN_MEM_EXECUTE:
1271
30.1k
    sec_flags |= SEC_CODE;
1272
30.1k
    break;
1273
18.7k
  case IMAGE_SCN_MEM_WRITE:
1274
18.7k
    sec_flags &= ~ SEC_READONLY;
1275
18.7k
    break;
1276
28.7k
  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
28.7k
       if (is_dbg
1283
28.7k
#ifdef _COMMENT
1284
28.7k
        || strcmp (name, _COMMENT) == 0
1285
28.7k
#endif
1286
28.7k
        )
1287
2.86k
      {
1288
2.86k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
2.86k
      }
1290
28.7k
    break;
1291
12.4k
  case IMAGE_SCN_MEM_SHARED:
1292
12.4k
    sec_flags |= SEC_COFF_SHARED;
1293
12.4k
    break;
1294
19.6k
  case IMAGE_SCN_LNK_REMOVE:
1295
19.6k
    if (!is_dbg)
1296
18.1k
      sec_flags |= SEC_EXCLUDE;
1297
19.6k
    break;
1298
24.8k
  case IMAGE_SCN_CNT_CODE:
1299
24.8k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
24.8k
    break;
1301
20.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
20.6k
    if (is_dbg)
1303
2.04k
      sec_flags |= SEC_DEBUGGING;
1304
18.5k
    else
1305
18.5k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
20.6k
    break;
1307
17.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
17.9k
    sec_flags |= SEC_ALLOC;
1309
17.9k
    break;
1310
24.2k
  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
24.2k
#ifdef COFF_PAGE_SIZE
1318
24.2k
    sec_flags |= SEC_DEBUGGING;
1319
24.2k
#endif
1320
24.2k
    break;
1321
18.8k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
18.8k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
262
      result = false;
1325
18.8k
    break;
1326
237k
  default:
1327
    /* Silently ignore for now.  */
1328
237k
    break;
1329
549k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
549k
      if (unhandled != NULL)
1333
17.6k
  {
1334
17.6k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
17.6k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
17.6k
       abfd, name, unhandled, flag);
1338
17.6k
    result = false;
1339
17.6k
  }
1340
549k
    }
1341
1342
806k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
806k
      && (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
806k
  if (flags_ptr)
1359
806k
    * flags_ptr = sec_flags;
1360
1361
806k
  return result;
1362
806k
}
pe-sh.c:styp_to_sec_flags
Line
Count
Source
1191
95.8k
{
1192
95.8k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
95.8k
  unsigned long styp_flags = internal_s->s_flags;
1194
95.8k
  flagword sec_flags;
1195
95.8k
  bool result = true;
1196
95.8k
  bool is_dbg = false;
1197
1198
95.8k
  if (startswith (name, DOT_DEBUG)
1199
95.8k
      || startswith (name, DOT_ZDEBUG)
1200
95.8k
#ifdef COFF_LONG_SECTION_NAMES
1201
95.8k
      || startswith (name, GNU_LINKONCE_WI)
1202
95.8k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
95.8k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
95.8k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
95.8k
      || startswith (name, GNU_DEBUGLINK)
1207
95.8k
      || startswith (name, GNU_DEBUGALTLINK)
1208
95.8k
#endif
1209
95.8k
      || startswith (name, ".stab"))
1210
4.88k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
95.8k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
95.8k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
78.8k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
729k
  while (styp_flags)
1220
633k
    {
1221
633k
      unsigned long flag = styp_flags & - styp_flags;
1222
633k
      char * unhandled = NULL;
1223
1224
633k
      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
633k
      switch (flag)
1231
633k
  {
1232
10.2k
  case STYP_DSECT:
1233
10.2k
    unhandled = "STYP_DSECT";
1234
10.2k
    break;
1235
10.6k
  case STYP_GROUP:
1236
10.6k
    unhandled = "STYP_GROUP";
1237
10.6k
    break;
1238
11.1k
  case STYP_COPY:
1239
11.1k
    unhandled = "STYP_COPY";
1240
11.1k
    break;
1241
13.0k
  case STYP_OVER:
1242
13.0k
    unhandled = "STYP_OVER";
1243
13.0k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
22.2k
  case STYP_NOLOAD:
1246
22.2k
    sec_flags |= SEC_NEVER_LOAD;
1247
22.2k
    break;
1248
0
#endif
1249
17.0k
  case IMAGE_SCN_MEM_READ:
1250
17.0k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
17.0k
    break;
1252
19.9k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
19.9k
    break;
1255
12.1k
  case IMAGE_SCN_LNK_OTHER:
1256
12.1k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
12.1k
    break;
1258
11.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
11.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
11.2k
    break;
1261
22.9k
  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
22.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
22.9k
        " %s in section %s"),
1268
22.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
22.9k
    break;
1270
27.7k
  case IMAGE_SCN_MEM_EXECUTE:
1271
27.7k
    sec_flags |= SEC_CODE;
1272
27.7k
    break;
1273
15.4k
  case IMAGE_SCN_MEM_WRITE:
1274
15.4k
    sec_flags &= ~ SEC_READONLY;
1275
15.4k
    break;
1276
28.6k
  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
28.6k
       if (is_dbg
1283
28.6k
#ifdef _COMMENT
1284
28.6k
        || strcmp (name, _COMMENT) == 0
1285
28.6k
#endif
1286
28.6k
        )
1287
3.50k
      {
1288
3.50k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
3.50k
      }
1290
28.6k
    break;
1291
19.9k
  case IMAGE_SCN_MEM_SHARED:
1292
19.9k
    sec_flags |= SEC_COFF_SHARED;
1293
19.9k
    break;
1294
25.7k
  case IMAGE_SCN_LNK_REMOVE:
1295
25.7k
    if (!is_dbg)
1296
24.1k
      sec_flags |= SEC_EXCLUDE;
1297
25.7k
    break;
1298
26.2k
  case IMAGE_SCN_CNT_CODE:
1299
26.2k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
26.2k
    break;
1301
19.2k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
19.2k
    if (is_dbg)
1303
2.14k
      sec_flags |= SEC_DEBUGGING;
1304
17.0k
    else
1305
17.0k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
19.2k
    break;
1307
11.6k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
11.6k
    sec_flags |= SEC_ALLOC;
1309
11.6k
    break;
1310
25.5k
  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
25.5k
    break;
1321
28.7k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
28.7k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2.26k
      result = false;
1325
28.7k
    break;
1326
253k
  default:
1327
    /* Silently ignore for now.  */
1328
253k
    break;
1329
633k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
633k
      if (unhandled != NULL)
1333
68.5k
  {
1334
68.5k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
68.5k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
68.5k
       abfd, name, unhandled, flag);
1338
68.5k
    result = false;
1339
68.5k
  }
1340
633k
    }
1341
1342
95.8k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
95.8k
      && (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
95.8k
  if (flags_ptr)
1359
95.8k
    * flags_ptr = sec_flags;
1360
1361
95.8k
  return result;
1362
95.8k
}
pei-arm-wince.c:styp_to_sec_flags
Line
Count
Source
1191
196k
{
1192
196k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
196k
  unsigned long styp_flags = internal_s->s_flags;
1194
196k
  flagword sec_flags;
1195
196k
  bool result = true;
1196
196k
  bool is_dbg = false;
1197
1198
196k
  if (startswith (name, DOT_DEBUG)
1199
196k
      || startswith (name, DOT_ZDEBUG)
1200
196k
#ifdef COFF_LONG_SECTION_NAMES
1201
196k
      || startswith (name, GNU_LINKONCE_WI)
1202
196k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
196k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
196k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
196k
      || startswith (name, GNU_DEBUGLINK)
1207
196k
      || startswith (name, GNU_DEBUGALTLINK)
1208
196k
#endif
1209
196k
      || startswith (name, ".stab"))
1210
6.12k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
196k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
196k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
153k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.50M
  while (styp_flags)
1220
1.31M
    {
1221
1.31M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.31M
      char * unhandled = NULL;
1223
1224
1.31M
      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.31M
      switch (flag)
1231
1.31M
  {
1232
20.4k
  case STYP_DSECT:
1233
20.4k
    unhandled = "STYP_DSECT";
1234
20.4k
    break;
1235
18.2k
  case STYP_GROUP:
1236
18.2k
    unhandled = "STYP_GROUP";
1237
18.2k
    break;
1238
22.3k
  case STYP_COPY:
1239
22.3k
    unhandled = "STYP_COPY";
1240
22.3k
    break;
1241
21.2k
  case STYP_OVER:
1242
21.2k
    unhandled = "STYP_OVER";
1243
21.2k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
41.2k
  case STYP_NOLOAD:
1246
41.2k
    sec_flags |= SEC_NEVER_LOAD;
1247
41.2k
    break;
1248
0
#endif
1249
43.5k
  case IMAGE_SCN_MEM_READ:
1250
43.5k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
43.5k
    break;
1252
44.7k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
44.7k
    break;
1255
19.3k
  case IMAGE_SCN_LNK_OTHER:
1256
19.3k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
19.3k
    break;
1258
18.9k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
18.9k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
18.9k
    break;
1261
59.0k
  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
59.0k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
59.0k
        " %s in section %s"),
1268
59.0k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
59.0k
    break;
1270
59.9k
  case IMAGE_SCN_MEM_EXECUTE:
1271
59.9k
    sec_flags |= SEC_CODE;
1272
59.9k
    break;
1273
48.2k
  case IMAGE_SCN_MEM_WRITE:
1274
48.2k
    sec_flags &= ~ SEC_READONLY;
1275
48.2k
    break;
1276
60.7k
  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.7k
       if (is_dbg
1283
60.7k
#ifdef _COMMENT
1284
60.7k
        || strcmp (name, _COMMENT) == 0
1285
60.7k
#endif
1286
60.7k
        )
1287
4.61k
      {
1288
4.61k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.61k
      }
1290
60.7k
    break;
1291
38.3k
  case IMAGE_SCN_MEM_SHARED:
1292
38.3k
    sec_flags |= SEC_COFF_SHARED;
1293
38.3k
    break;
1294
57.8k
  case IMAGE_SCN_LNK_REMOVE:
1295
57.8k
    if (!is_dbg)
1296
55.9k
      sec_flags |= SEC_EXCLUDE;
1297
57.8k
    break;
1298
46.3k
  case IMAGE_SCN_CNT_CODE:
1299
46.3k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
46.3k
    break;
1301
30.8k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
30.8k
    if (is_dbg)
1303
1.66k
      sec_flags |= SEC_DEBUGGING;
1304
29.2k
    else
1305
29.2k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
30.8k
    break;
1307
39.9k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
39.9k
    sec_flags |= SEC_ALLOC;
1309
39.9k
    break;
1310
55.0k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
55.0k
#ifdef COFF_PAGE_SIZE
1318
55.0k
    sec_flags |= SEC_DEBUGGING;
1319
55.0k
#endif
1320
55.0k
    break;
1321
43.9k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
43.9k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2.21k
      result = false;
1325
43.9k
    break;
1326
520k
  default:
1327
    /* Silently ignore for now.  */
1328
520k
    break;
1329
1.31M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.31M
      if (unhandled != NULL)
1333
120k
  {
1334
120k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
120k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
120k
       abfd, name, unhandled, flag);
1338
120k
    result = false;
1339
120k
  }
1340
1.31M
    }
1341
1342
196k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
196k
      && (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
196k
  if (flags_ptr)
1359
196k
    * flags_ptr = sec_flags;
1360
1361
196k
  return result;
1362
196k
}
pei-arm.c:styp_to_sec_flags
Line
Count
Source
1191
778k
{
1192
778k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
778k
  unsigned long styp_flags = internal_s->s_flags;
1194
778k
  flagword sec_flags;
1195
778k
  bool result = true;
1196
778k
  bool is_dbg = false;
1197
1198
778k
  if (startswith (name, DOT_DEBUG)
1199
778k
      || startswith (name, DOT_ZDEBUG)
1200
778k
#ifdef COFF_LONG_SECTION_NAMES
1201
778k
      || startswith (name, GNU_LINKONCE_WI)
1202
778k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
778k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
778k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
778k
      || startswith (name, GNU_DEBUGLINK)
1207
778k
      || startswith (name, GNU_DEBUGALTLINK)
1208
778k
#endif
1209
778k
      || startswith (name, ".stab"))
1210
7.02k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
778k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
778k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
722k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
2.74M
  while (styp_flags)
1220
1.96M
    {
1221
1.96M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.96M
      char * unhandled = NULL;
1223
1224
1.96M
      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.96M
      switch (flag)
1231
1.96M
  {
1232
23.1k
  case STYP_DSECT:
1233
23.1k
    unhandled = "STYP_DSECT";
1234
23.1k
    break;
1235
21.9k
  case STYP_GROUP:
1236
21.9k
    unhandled = "STYP_GROUP";
1237
21.9k
    break;
1238
24.4k
  case STYP_COPY:
1239
24.4k
    unhandled = "STYP_COPY";
1240
24.4k
    break;
1241
24.8k
  case STYP_OVER:
1242
24.8k
    unhandled = "STYP_OVER";
1243
24.8k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
45.9k
  case STYP_NOLOAD:
1246
45.9k
    sec_flags |= SEC_NEVER_LOAD;
1247
45.9k
    break;
1248
0
#endif
1249
56.4k
  case IMAGE_SCN_MEM_READ:
1250
56.4k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
56.4k
    break;
1252
101k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
101k
    break;
1255
26.0k
  case IMAGE_SCN_LNK_OTHER:
1256
26.0k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
26.0k
    break;
1258
22.4k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
22.4k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
22.4k
    break;
1261
112k
  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
112k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
112k
        " %s in section %s"),
1268
112k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
112k
    break;
1270
74.3k
  case IMAGE_SCN_MEM_EXECUTE:
1271
74.3k
    sec_flags |= SEC_CODE;
1272
74.3k
    break;
1273
107k
  case IMAGE_SCN_MEM_WRITE:
1274
107k
    sec_flags &= ~ SEC_READONLY;
1275
107k
    break;
1276
63.9k
  case IMAGE_SCN_MEM_DISCARDABLE:
1277
    /* The MS PE spec says that debug sections are DISCARDABLE,
1278
       but the presence of a DISCARDABLE flag does not necessarily
1279
       mean that a given section contains debug information.  Thus
1280
       we only set the SEC_DEBUGGING flag on sections that we
1281
       recognise as containing debug information.  */
1282
63.9k
       if (is_dbg
1283
63.9k
#ifdef _COMMENT
1284
63.9k
        || strcmp (name, _COMMENT) == 0
1285
63.9k
#endif
1286
63.9k
        )
1287
5.06k
      {
1288
5.06k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
5.06k
      }
1290
63.9k
    break;
1291
39.6k
  case IMAGE_SCN_MEM_SHARED:
1292
39.6k
    sec_flags |= SEC_COFF_SHARED;
1293
39.6k
    break;
1294
116k
  case IMAGE_SCN_LNK_REMOVE:
1295
116k
    if (!is_dbg)
1296
113k
      sec_flags |= SEC_EXCLUDE;
1297
116k
    break;
1298
64.7k
  case IMAGE_SCN_CNT_CODE:
1299
64.7k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
64.7k
    break;
1301
42.9k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
42.9k
    if (is_dbg)
1303
2.60k
      sec_flags |= SEC_DEBUGGING;
1304
40.3k
    else
1305
40.3k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
42.9k
    break;
1307
99.0k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
99.0k
    sec_flags |= SEC_ALLOC;
1309
99.0k
    break;
1310
61.6k
  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
61.6k
#ifdef COFF_PAGE_SIZE
1318
61.6k
    sec_flags |= SEC_DEBUGGING;
1319
61.6k
#endif
1320
61.6k
    break;
1321
56.0k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
56.0k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
2.69k
      result = false;
1325
56.0k
    break;
1326
783k
  default:
1327
    /* Silently ignore for now.  */
1328
783k
    break;
1329
1.96M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.96M
      if (unhandled != NULL)
1333
142k
  {
1334
142k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
142k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
142k
       abfd, name, unhandled, flag);
1338
142k
    result = false;
1339
142k
  }
1340
1.96M
    }
1341
1342
778k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
778k
      && (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
778k
  if (flags_ptr)
1359
778k
    * flags_ptr = sec_flags;
1360
1361
778k
  return result;
1362
778k
}
pei-mcore.c:styp_to_sec_flags
Line
Count
Source
1191
209k
{
1192
209k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
209k
  unsigned long styp_flags = internal_s->s_flags;
1194
209k
  flagword sec_flags;
1195
209k
  bool result = true;
1196
209k
  bool is_dbg = false;
1197
1198
209k
  if (startswith (name, DOT_DEBUG)
1199
209k
      || startswith (name, DOT_ZDEBUG)
1200
209k
#ifdef COFF_LONG_SECTION_NAMES
1201
209k
      || startswith (name, GNU_LINKONCE_WI)
1202
209k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
209k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
209k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
209k
      || startswith (name, GNU_DEBUGLINK)
1207
209k
      || startswith (name, GNU_DEBUGALTLINK)
1208
209k
#endif
1209
209k
      || startswith (name, ".stab"))
1210
5.16k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
209k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
209k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
174k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.14M
  while (styp_flags)
1220
938k
    {
1221
938k
      unsigned long flag = styp_flags & - styp_flags;
1222
938k
      char * unhandled = NULL;
1223
1224
938k
      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
938k
      switch (flag)
1231
938k
  {
1232
12.3k
  case STYP_DSECT:
1233
12.3k
    unhandled = "STYP_DSECT";
1234
12.3k
    break;
1235
10.3k
  case STYP_GROUP:
1236
10.3k
    unhandled = "STYP_GROUP";
1237
10.3k
    break;
1238
12.6k
  case STYP_COPY:
1239
12.6k
    unhandled = "STYP_COPY";
1240
12.6k
    break;
1241
12.5k
  case STYP_OVER:
1242
12.5k
    unhandled = "STYP_OVER";
1243
12.5k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
33.1k
  case STYP_NOLOAD:
1246
33.1k
    sec_flags |= SEC_NEVER_LOAD;
1247
33.1k
    break;
1248
0
#endif
1249
34.6k
  case IMAGE_SCN_MEM_READ:
1250
34.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
34.6k
    break;
1252
33.6k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
33.6k
    break;
1255
11.8k
  case IMAGE_SCN_LNK_OTHER:
1256
11.8k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
11.8k
    break;
1258
8.69k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
8.69k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
8.69k
    break;
1261
37.5k
  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
37.5k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
37.5k
        " %s in section %s"),
1268
37.5k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
37.5k
    break;
1270
45.3k
  case IMAGE_SCN_MEM_EXECUTE:
1271
45.3k
    sec_flags |= SEC_CODE;
1272
45.3k
    break;
1273
31.9k
  case IMAGE_SCN_MEM_WRITE:
1274
31.9k
    sec_flags &= ~ SEC_READONLY;
1275
31.9k
    break;
1276
41.8k
  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
41.8k
       if (is_dbg
1283
41.8k
#ifdef _COMMENT
1284
41.8k
        || strcmp (name, _COMMENT) == 0
1285
41.8k
#endif
1286
41.8k
        )
1287
4.25k
      {
1288
4.25k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.25k
      }
1290
41.8k
    break;
1291
23.4k
  case IMAGE_SCN_MEM_SHARED:
1292
23.4k
    sec_flags |= SEC_COFF_SHARED;
1293
23.4k
    break;
1294
39.3k
  case IMAGE_SCN_LNK_REMOVE:
1295
39.3k
    if (!is_dbg)
1296
37.6k
      sec_flags |= SEC_EXCLUDE;
1297
39.3k
    break;
1298
36.9k
  case IMAGE_SCN_CNT_CODE:
1299
36.9k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
36.9k
    break;
1301
24.5k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
24.5k
    if (is_dbg)
1303
1.49k
      sec_flags |= SEC_DEBUGGING;
1304
23.0k
    else
1305
23.0k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
24.5k
    break;
1307
29.7k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
29.7k
    sec_flags |= SEC_ALLOC;
1309
29.7k
    break;
1310
40.4k
  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.4k
#ifdef COFF_PAGE_SIZE
1318
40.4k
    sec_flags |= SEC_DEBUGGING;
1319
40.4k
#endif
1320
40.4k
    break;
1321
30.2k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
30.2k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.86k
      result = false;
1325
30.2k
    break;
1326
387k
  default:
1327
    /* Silently ignore for now.  */
1328
387k
    break;
1329
938k
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
938k
      if (unhandled != NULL)
1333
68.4k
  {
1334
68.4k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
68.4k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
68.4k
       abfd, name, unhandled, flag);
1338
68.4k
    result = false;
1339
68.4k
  }
1340
938k
    }
1341
1342
209k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
209k
      && (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
209k
  if (flags_ptr)
1359
209k
    * flags_ptr = sec_flags;
1360
1361
209k
  return result;
1362
209k
}
pei-sh.c:styp_to_sec_flags
Line
Count
Source
1191
226k
{
1192
226k
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
1193
226k
  unsigned long styp_flags = internal_s->s_flags;
1194
226k
  flagword sec_flags;
1195
226k
  bool result = true;
1196
226k
  bool is_dbg = false;
1197
1198
226k
  if (startswith (name, DOT_DEBUG)
1199
226k
      || startswith (name, DOT_ZDEBUG)
1200
226k
#ifdef COFF_LONG_SECTION_NAMES
1201
226k
      || startswith (name, GNU_LINKONCE_WI)
1202
226k
      || startswith (name, GNU_LINKONCE_WT)
1203
      /* FIXME: These definitions ought to be in a header file.  */
1204
226k
#define GNU_DEBUGLINK   ".gnu_debuglink"
1205
226k
#define GNU_DEBUGALTLINK  ".gnu_debugaltlink"
1206
226k
      || startswith (name, GNU_DEBUGLINK)
1207
226k
      || startswith (name, GNU_DEBUGALTLINK)
1208
226k
#endif
1209
226k
      || startswith (name, ".stab"))
1210
7.24k
    is_dbg = true;
1211
  /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
1212
226k
  sec_flags = SEC_READONLY;
1213
1214
  /* If section disallows read, then set the NOREAD flag. */
1215
226k
  if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
1216
188k
    sec_flags |= SEC_COFF_NOREAD;
1217
1218
  /* Process each flag bit in styp_flags in turn.  */
1219
1.23M
  while (styp_flags)
1220
1.00M
    {
1221
1.00M
      unsigned long flag = styp_flags & - styp_flags;
1222
1.00M
      char * unhandled = NULL;
1223
1224
1.00M
      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.00M
      switch (flag)
1231
1.00M
  {
1232
11.1k
  case STYP_DSECT:
1233
11.1k
    unhandled = "STYP_DSECT";
1234
11.1k
    break;
1235
12.9k
  case STYP_GROUP:
1236
12.9k
    unhandled = "STYP_GROUP";
1237
12.9k
    break;
1238
12.5k
  case STYP_COPY:
1239
12.5k
    unhandled = "STYP_COPY";
1240
12.5k
    break;
1241
14.1k
  case STYP_OVER:
1242
14.1k
    unhandled = "STYP_OVER";
1243
14.1k
    break;
1244
0
#ifdef SEC_NEVER_LOAD
1245
32.1k
  case STYP_NOLOAD:
1246
32.1k
    sec_flags |= SEC_NEVER_LOAD;
1247
32.1k
    break;
1248
0
#endif
1249
37.6k
  case IMAGE_SCN_MEM_READ:
1250
37.6k
    sec_flags &= ~SEC_COFF_NOREAD;
1251
37.6k
    break;
1252
32.7k
  case IMAGE_SCN_TYPE_NO_PAD:
1253
    /* Skip.  */
1254
32.7k
    break;
1255
13.5k
  case IMAGE_SCN_LNK_OTHER:
1256
13.5k
    unhandled = "IMAGE_SCN_LNK_OTHER";
1257
13.5k
    break;
1258
12.2k
  case IMAGE_SCN_MEM_NOT_CACHED:
1259
12.2k
    unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
1260
12.2k
    break;
1261
37.9k
  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
37.9k
    _bfd_error_handler (_("%pB: warning: ignoring section flag"
1267
37.9k
        " %s in section %s"),
1268
37.9k
            abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
1269
37.9k
    break;
1270
43.3k
  case IMAGE_SCN_MEM_EXECUTE:
1271
43.3k
    sec_flags |= SEC_CODE;
1272
43.3k
    break;
1273
37.5k
  case IMAGE_SCN_MEM_WRITE:
1274
37.5k
    sec_flags &= ~ SEC_READONLY;
1275
37.5k
    break;
1276
49.2k
  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
49.2k
       if (is_dbg
1283
49.2k
#ifdef _COMMENT
1284
49.2k
        || strcmp (name, _COMMENT) == 0
1285
49.2k
#endif
1286
49.2k
        )
1287
4.61k
      {
1288
4.61k
        sec_flags |= SEC_DEBUGGING | SEC_READONLY;
1289
4.61k
      }
1290
49.2k
    break;
1291
28.2k
  case IMAGE_SCN_MEM_SHARED:
1292
28.2k
    sec_flags |= SEC_COFF_SHARED;
1293
28.2k
    break;
1294
40.3k
  case IMAGE_SCN_LNK_REMOVE:
1295
40.3k
    if (!is_dbg)
1296
38.9k
      sec_flags |= SEC_EXCLUDE;
1297
40.3k
    break;
1298
34.0k
  case IMAGE_SCN_CNT_CODE:
1299
34.0k
    sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
1300
34.0k
    break;
1301
26.6k
  case IMAGE_SCN_CNT_INITIALIZED_DATA:
1302
26.6k
    if (is_dbg)
1303
1.50k
      sec_flags |= SEC_DEBUGGING;
1304
25.1k
    else
1305
25.1k
      sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
1306
26.6k
    break;
1307
31.8k
  case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
1308
31.8k
    sec_flags |= SEC_ALLOC;
1309
31.8k
    break;
1310
39.6k
  case IMAGE_SCN_LNK_INFO:
1311
    /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
1312
       defined.  coff_compute_section_file_positions uses
1313
       COFF_PAGE_SIZE to ensure that the low order bits of the
1314
       section VMA and the file offset match.  If we don't know
1315
       COFF_PAGE_SIZE, we can't ensure the correct correspondence,
1316
       and demand page loading of the file will fail.  */
1317
39.6k
#ifdef COFF_PAGE_SIZE
1318
39.6k
    sec_flags |= SEC_DEBUGGING;
1319
39.6k
#endif
1320
39.6k
    break;
1321
39.9k
  case IMAGE_SCN_LNK_COMDAT:
1322
    /* COMDAT gets very special treatment.  */
1323
39.9k
    if (!handle_COMDAT (abfd, &sec_flags, name, section))
1324
1.57k
      result = false;
1325
39.9k
    break;
1326
418k
  default:
1327
    /* Silently ignore for now.  */
1328
418k
    break;
1329
1.00M
  }
1330
1331
      /* If the section flag was not handled, report it here.  */
1332
1.00M
      if (unhandled != NULL)
1333
76.6k
  {
1334
76.6k
    _bfd_error_handler
1335
      /* xgettext:c-format */
1336
76.6k
      (_("%pB (%s): section flag %s (%#lx) ignored"),
1337
76.6k
       abfd, name, unhandled, flag);
1338
76.6k
    result = false;
1339
76.6k
  }
1340
1.00M
    }
1341
1342
226k
  if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
1343
226k
      && (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
226k
  if (flags_ptr)
1359
226k
    * flags_ptr = sec_flags;
1360
1361
226k
  return result;
1362
226k
}
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
47.3M
{
1687
47.3M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
47.3M
  if (BADMAG (*internal_f))
1690
45.9M
    return false;
1691
1692
1.36M
  return true;
1693
47.3M
}
pei-i386.c:coff_bad_format_hook
Line
Count
Source
1686
572k
{
1687
572k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
572k
  if (BADMAG (*internal_f))
1690
505k
    return false;
1691
1692
67.5k
  return true;
1693
572k
}
pe-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
3.20M
{
1687
3.20M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.20M
  if (BADMAG (*internal_f))
1690
3.10M
    return false;
1691
1692
97.3k
  return true;
1693
3.20M
}
pei-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
581k
{
1687
581k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
581k
  if (BADMAG (*internal_f))
1690
502k
    return false;
1691
1692
79.5k
  return true;
1693
581k
}
coff-x86_64.c:coff_bad_format_hook
Line
Count
Source
1686
1.65M
{
1687
1.65M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.65M
  if (BADMAG (*internal_f))
1690
1.57M
    return false;
1691
1692
76.2k
  return true;
1693
1.65M
}
Unexecuted instantiation: coff64-rs6000.c:coff_bad_format_hook
pe-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
1.65M
{
1687
1.65M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.65M
  if (BADMAG (*internal_f))
1690
1.62M
    return false;
1691
1692
29.1k
  return true;
1693
1.65M
}
pei-aarch64.c:coff_bad_format_hook
Line
Count
Source
1686
561k
{
1687
561k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
561k
  if (BADMAG (*internal_f))
1690
498k
    return false;
1691
1692
63.6k
  return true;
1693
561k
}
pei-ia64.c:coff_bad_format_hook
Line
Count
Source
1686
546k
{
1687
546k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
546k
  if (BADMAG (*internal_f))
1690
468k
    return false;
1691
1692
77.4k
  return true;
1693
546k
}
pei-loongarch64.c:coff_bad_format_hook
Line
Count
Source
1686
561k
{
1687
561k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
561k
  if (BADMAG (*internal_f))
1690
506k
    return false;
1691
1692
54.7k
  return true;
1693
561k
}
cf-i386lynx.c:coff_bad_format_hook
Line
Count
Source
1686
1.65M
{
1687
1.65M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.65M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
41.7k
  return true;
1693
1.65M
}
coff-go32.c:coff_bad_format_hook
Line
Count
Source
1686
1.65M
{
1687
1.65M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.65M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
39.4k
  return true;
1693
1.65M
}
coff-i386.c:coff_bad_format_hook
Line
Count
Source
1686
1.65M
{
1687
1.65M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.65M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
39.4k
  return true;
1693
1.65M
}
coff-rs6000.c:coff_bad_format_hook
Line
Count
Source
1686
1.63M
{
1687
1.63M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.63M
  if (BADMAG (*internal_f))
1690
1.58M
    return false;
1691
1692
52.7k
  return true;
1693
1.63M
}
coff-sh.c:coff_bad_format_hook
Line
Count
Source
1686
6.35M
{
1687
6.35M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
6.35M
  if (BADMAG (*internal_f))
1690
6.28M
    return false;
1691
1692
67.5k
  return true;
1693
6.35M
}
coff-stgo32.c:coff_bad_format_hook
Line
Count
Source
1686
2.65k
{
1687
2.65k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
2.65k
  if (BADMAG (*internal_f))
1690
99
    return false;
1691
1692
2.55k
  return true;
1693
2.65k
}
coff-tic30.c:coff_bad_format_hook
Line
Count
Source
1686
1.63M
{
1687
1.63M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.63M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
27.2k
  return true;
1693
1.63M
}
Unexecuted instantiation: coff-tic4x.c:coff_bad_format_hook
coff-tic54x.c:coff_bad_format_hook
Line
Count
Source
1686
3.26M
{
1687
3.26M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.26M
  if (BADMAG (*internal_f))
1690
3.26M
    return false;
1691
1692
28
  return true;
1693
3.26M
}
coff-z80.c:coff_bad_format_hook
Line
Count
Source
1686
1.63M
{
1687
1.63M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.63M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
22.0k
  return true;
1693
1.63M
}
coff-z8k.c:coff_bad_format_hook
Line
Count
Source
1686
1.63M
{
1687
1.63M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.63M
  if (BADMAG (*internal_f))
1690
1.61M
    return false;
1691
1692
24.7k
  return true;
1693
1.63M
}
pe-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
3.27M
{
1687
3.27M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.27M
  if (BADMAG (*internal_f))
1690
3.26M
    return false;
1691
1692
13.2k
  return true;
1693
3.27M
}
pe-arm.c:coff_bad_format_hook
Line
Count
Source
1686
3.27M
{
1687
3.27M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.27M
  if (BADMAG (*internal_f))
1690
3.26M
    return false;
1691
1692
13.2k
  return true;
1693
3.27M
}
pe-i386.c:coff_bad_format_hook
Line
Count
Source
1686
3.18M
{
1687
3.18M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.18M
  if (BADMAG (*internal_f))
1690
3.13M
    return false;
1691
1692
48.0k
  return true;
1693
3.18M
}
pe-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
3.27M
{
1687
3.27M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
3.27M
  if (BADMAG (*internal_f))
1690
3.24M
    return false;
1691
1692
30.6k
  return true;
1693
3.27M
}
pe-sh.c:coff_bad_format_hook
Line
Count
Source
1686
1.63M
{
1687
1.63M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
1.63M
  if (BADMAG (*internal_f))
1690
1.60M
    return false;
1691
1692
34.9k
  return true;
1693
1.63M
}
pei-arm-wince.c:coff_bad_format_hook
Line
Count
Source
1686
561k
{
1687
561k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
561k
  if (BADMAG (*internal_f))
1690
447k
    return false;
1691
1692
114k
  return true;
1693
561k
}
pei-arm.c:coff_bad_format_hook
Line
Count
Source
1686
561k
{
1687
561k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
561k
  if (BADMAG (*internal_f))
1690
447k
    return false;
1691
1692
114k
  return true;
1693
561k
}
pei-mcore.c:coff_bad_format_hook
Line
Count
Source
1686
561k
{
1687
561k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
561k
  if (BADMAG (*internal_f))
1690
489k
    return false;
1691
1692
72.3k
  return true;
1693
561k
}
pei-sh.c:coff_bad_format_hook
Line
Count
Source
1686
560k
{
1687
560k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1688
1689
560k
  if (BADMAG (*internal_f))
1690
497k
    return false;
1691
1692
62.7k
  return true;
1693
560k
}
1694
1695
#ifdef TICOFF
1696
static bool
1697
ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1698
3.27M
{
1699
3.27M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
3.27M
  if (COFF0_BADMAG (*internal_f))
1702
3.23M
    return false;
1703
1704
44.2k
  return true;
1705
3.27M
}
Unexecuted instantiation: coff-tic4x.c:ticoff0_bad_format_hook
coff-tic54x.c:ticoff0_bad_format_hook
Line
Count
Source
1698
3.27M
{
1699
3.27M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1700
1701
3.27M
  if (COFF0_BADMAG (*internal_f))
1702
3.23M
    return false;
1703
1704
44.2k
  return true;
1705
3.27M
}
1706
#endif
1707
1708
#ifdef TICOFF
1709
static bool
1710
ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
1711
3.26M
{
1712
3.26M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
3.26M
  if (COFF1_BADMAG (*internal_f))
1715
3.25M
    return false;
1716
1717
3.49k
  return true;
1718
3.26M
}
Unexecuted instantiation: coff-tic4x.c:ticoff1_bad_format_hook
coff-tic54x.c:ticoff1_bad_format_hook
Line
Count
Source
1711
3.26M
{
1712
3.26M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1713
1714
3.26M
  if (COFF1_BADMAG (*internal_f))
1715
3.25M
    return false;
1716
1717
3.49k
  return true;
1718
3.26M
}
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
96.7M
{
1730
96.7M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
96.7M
  unsigned int i;
1732
1733
556M
  for (i = 0; i < table_size; ++i)
1734
460M
    {
1735
460M
      const char *secname = bfd_section_name (section);
1736
1737
460M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
460M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
460M
    : strncmp (alignment_table[i].name, secname,
1740
257M
         alignment_table[i].comparison_length) == 0)
1741
479k
  break;
1742
460M
    }
1743
96.7M
  if (i >= table_size)
1744
96.2M
    return;
1745
1746
479k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
479k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
188k
    return;
1749
1750
291k
  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
291k
      )
1755
0
    return;
1756
1757
291k
  section->alignment_power = alignment_table[i].alignment_power;
1758
291k
}
pei-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
290k
{
1730
290k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
290k
  unsigned int i;
1732
1733
2.53M
  for (i = 0; i < table_size; ++i)
1734
2.26M
    {
1735
2.26M
      const char *secname = bfd_section_name (section);
1736
1737
2.26M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.26M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.26M
    : strncmp (alignment_table[i].name, secname,
1740
1.41M
         alignment_table[i].comparison_length) == 0)
1741
12.4k
  break;
1742
2.26M
    }
1743
290k
  if (i >= table_size)
1744
278k
    return;
1745
1746
12.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
12.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.83k
    return;
1749
1750
10.6k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
10.6k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
10.6k
      && default_alignment > alignment_table[i].default_alignment_max
1753
10.6k
#endif
1754
10.6k
      )
1755
0
    return;
1756
1757
10.6k
  section->alignment_power = alignment_table[i].alignment_power;
1758
10.6k
}
pe-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
321k
{
1730
321k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
321k
  unsigned int i;
1732
1733
4.36M
  for (i = 0; i < table_size; ++i)
1734
4.06M
    {
1735
4.06M
      const char *secname = bfd_section_name (section);
1736
1737
4.06M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
4.06M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
4.06M
    : strncmp (alignment_table[i].name, secname,
1740
2.84M
         alignment_table[i].comparison_length) == 0)
1741
29.2k
  break;
1742
4.06M
    }
1743
321k
  if (i >= table_size)
1744
292k
    return;
1745
1746
29.2k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
29.2k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
14.6k
    return;
1749
1750
14.6k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
14.6k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
14.6k
      && default_alignment > alignment_table[i].default_alignment_max
1753
14.6k
#endif
1754
14.6k
      )
1755
0
    return;
1756
1757
14.6k
  section->alignment_power = alignment_table[i].alignment_power;
1758
14.6k
}
pei-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
235k
{
1730
235k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
235k
  unsigned int i;
1732
1733
2.85M
  for (i = 0; i < table_size; ++i)
1734
2.66M
    {
1735
2.66M
      const char *secname = bfd_section_name (section);
1736
1737
2.66M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.66M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.66M
    : strncmp (alignment_table[i].name, secname,
1740
1.80M
         alignment_table[i].comparison_length) == 0)
1741
37.9k
  break;
1742
2.66M
    }
1743
235k
  if (i >= table_size)
1744
197k
    return;
1745
1746
37.9k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
37.9k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
10.6k
    return;
1749
1750
27.2k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
27.2k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
27.2k
      && default_alignment > alignment_table[i].default_alignment_max
1753
27.2k
#endif
1754
27.2k
      )
1755
0
    return;
1756
1757
27.2k
  section->alignment_power = alignment_table[i].alignment_power;
1758
27.2k
}
coff-x86_64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
9.32M
{
1730
9.32M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
9.32M
  unsigned int i;
1732
1733
46.4M
  for (i = 0; i < table_size; ++i)
1734
37.2M
    {
1735
37.2M
      const char *secname = bfd_section_name (section);
1736
1737
37.2M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
37.2M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
37.2M
    : strncmp (alignment_table[i].name, secname,
1740
18.6M
         alignment_table[i].comparison_length) == 0)
1741
48.6k
  break;
1742
37.2M
    }
1743
9.32M
  if (i >= table_size)
1744
9.27M
    return;
1745
1746
48.6k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
48.6k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
35.9k
    return;
1749
1750
12.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
12.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
12.7k
      && default_alignment > alignment_table[i].default_alignment_max
1753
12.7k
#endif
1754
12.7k
      )
1755
0
    return;
1756
1757
12.7k
  section->alignment_power = alignment_table[i].alignment_power;
1758
12.7k
}
coff64-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4.62M
{
1730
4.62M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4.62M
  unsigned int i;
1732
1733
23.0M
  for (i = 0; i < table_size; ++i)
1734
18.4M
    {
1735
18.4M
      const char *secname = bfd_section_name (section);
1736
1737
18.4M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
18.4M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
18.4M
    : strncmp (alignment_table[i].name, secname,
1740
9.24M
         alignment_table[i].comparison_length) == 0)
1741
18.3k
  break;
1742
18.4M
    }
1743
4.62M
  if (i >= table_size)
1744
4.60M
    return;
1745
1746
18.3k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
18.3k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
18.3k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
18.3k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
18.3k
      && default_alignment > alignment_table[i].default_alignment_max
1753
18.3k
#endif
1754
18.3k
      )
1755
0
    return;
1756
1757
18.3k
  section->alignment_power = alignment_table[i].alignment_power;
1758
18.3k
}
pe-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
124k
{
1730
124k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
124k
  unsigned int i;
1732
1733
1.59M
  for (i = 0; i < table_size; ++i)
1734
1.47M
    {
1735
1.47M
      const char *secname = bfd_section_name (section);
1736
1737
1.47M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.47M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.47M
    : strncmp (alignment_table[i].name, secname,
1740
613k
         alignment_table[i].comparison_length) == 0)
1741
4.60k
  break;
1742
1.47M
    }
1743
124k
  if (i >= table_size)
1744
119k
    return;
1745
1746
4.60k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4.60k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.55k
    return;
1749
1750
3.05k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
3.05k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
3.05k
      && default_alignment > alignment_table[i].default_alignment_max
1753
3.05k
#endif
1754
3.05k
      )
1755
0
    return;
1756
1757
3.05k
  section->alignment_power = alignment_table[i].alignment_power;
1758
3.05k
}
pei-aarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
170k
{
1730
170k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
170k
  unsigned int i;
1732
1733
2.15M
  for (i = 0; i < table_size; ++i)
1734
1.99M
    {
1735
1.99M
      const char *secname = bfd_section_name (section);
1736
1737
1.99M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
1.99M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
1.99M
    : strncmp (alignment_table[i].name, secname,
1740
823k
         alignment_table[i].comparison_length) == 0)
1741
10.1k
  break;
1742
1.99M
    }
1743
170k
  if (i >= table_size)
1744
160k
    return;
1745
1746
10.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
10.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.39k
    return;
1749
1750
8.75k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
8.75k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
8.75k
      && default_alignment > alignment_table[i].default_alignment_max
1753
8.75k
#endif
1754
8.75k
      )
1755
0
    return;
1756
1757
8.75k
  section->alignment_power = alignment_table[i].alignment_power;
1758
8.75k
}
pei-ia64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
229k
{
1730
229k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
229k
  unsigned int i;
1732
1733
1.12M
  for (i = 0; i < table_size; ++i)
1734
902k
    {
1735
902k
      const char *secname = bfd_section_name (section);
1736
1737
902k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
902k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
902k
    : strncmp (alignment_table[i].name, secname,
1740
458k
         alignment_table[i].comparison_length) == 0)
1741
8.60k
  break;
1742
902k
    }
1743
229k
  if (i >= table_size)
1744
221k
    return;
1745
1746
8.60k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
8.60k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
7.07k
    return;
1749
1750
1.52k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1.52k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1.52k
      && default_alignment > alignment_table[i].default_alignment_max
1753
1.52k
#endif
1754
1.52k
      )
1755
0
    return;
1756
1757
1.52k
  section->alignment_power = alignment_table[i].alignment_power;
1758
1.52k
}
pei-loongarch64.c:coff_set_custom_section_alignment
Line
Count
Source
1729
176k
{
1730
176k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
176k
  unsigned int i;
1732
1733
2.24M
  for (i = 0; i < table_size; ++i)
1734
2.07M
    {
1735
2.07M
      const char *secname = bfd_section_name (section);
1736
1737
2.07M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.07M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.07M
    : strncmp (alignment_table[i].name, secname,
1740
858k
         alignment_table[i].comparison_length) == 0)
1741
9.05k
  break;
1742
2.07M
    }
1743
176k
  if (i >= table_size)
1744
167k
    return;
1745
1746
9.05k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
9.05k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.66k
    return;
1749
1750
7.38k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
7.38k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
7.38k
      && default_alignment > alignment_table[i].default_alignment_max
1753
7.38k
#endif
1754
7.38k
      )
1755
0
    return;
1756
1757
7.38k
  section->alignment_power = alignment_table[i].alignment_power;
1758
7.38k
}
cf-i386lynx.c:coff_set_custom_section_alignment
Line
Count
Source
1729
6.05M
{
1730
6.05M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
6.05M
  unsigned int i;
1732
1733
30.2M
  for (i = 0; i < table_size; ++i)
1734
24.1M
    {
1735
24.1M
      const char *secname = bfd_section_name (section);
1736
1737
24.1M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
24.1M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
24.1M
    : strncmp (alignment_table[i].name, secname,
1740
12.1M
         alignment_table[i].comparison_length) == 0)
1741
20.8k
  break;
1742
24.1M
    }
1743
6.05M
  if (i >= table_size)
1744
6.03M
    return;
1745
1746
20.8k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
20.8k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
11.4k
    return;
1749
1750
9.31k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
9.31k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
9.31k
      && default_alignment > alignment_table[i].default_alignment_max
1753
9.31k
#endif
1754
9.31k
      )
1755
0
    return;
1756
1757
9.31k
  section->alignment_power = alignment_table[i].alignment_power;
1758
9.31k
}
coff-go32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
4.96M
{
1730
4.96M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
4.96M
  unsigned int i;
1732
1733
79.1M
  for (i = 0; i < table_size; ++i)
1734
74.1M
    {
1735
74.1M
      const char *secname = bfd_section_name (section);
1736
1737
74.1M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
74.1M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
74.1M
    : strncmp (alignment_table[i].name, secname,
1740
64.3M
         alignment_table[i].comparison_length) == 0)
1741
38.1k
  break;
1742
74.1M
    }
1743
4.96M
  if (i >= table_size)
1744
4.92M
    return;
1745
1746
38.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
38.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
8.44k
    return;
1749
1750
29.6k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
29.6k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
29.6k
      && default_alignment > alignment_table[i].default_alignment_max
1753
29.6k
#endif
1754
29.6k
      )
1755
0
    return;
1756
1757
29.6k
  section->alignment_power = alignment_table[i].alignment_power;
1758
29.6k
}
coff-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
5.72M
{
1730
5.72M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
5.72M
  unsigned int i;
1732
1733
28.5M
  for (i = 0; i < table_size; ++i)
1734
22.8M
    {
1735
22.8M
      const char *secname = bfd_section_name (section);
1736
1737
22.8M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
22.8M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
22.8M
    : strncmp (alignment_table[i].name, secname,
1740
11.4M
         alignment_table[i].comparison_length) == 0)
1741
16.5k
  break;
1742
22.8M
    }
1743
5.72M
  if (i >= table_size)
1744
5.71M
    return;
1745
1746
16.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
16.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
9.78k
    return;
1749
1750
6.77k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
6.77k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
6.77k
      && default_alignment > alignment_table[i].default_alignment_max
1753
6.77k
#endif
1754
6.77k
      )
1755
0
    return;
1756
1757
6.77k
  section->alignment_power = alignment_table[i].alignment_power;
1758
6.77k
}
coff-rs6000.c:coff_set_custom_section_alignment
Line
Count
Source
1729
25.5M
{
1730
25.5M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
25.5M
  unsigned int i;
1732
1733
127M
  for (i = 0; i < table_size; ++i)
1734
102M
    {
1735
102M
      const char *secname = bfd_section_name (section);
1736
1737
102M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
102M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
102M
    : strncmp (alignment_table[i].name, secname,
1740
51.0M
         alignment_table[i].comparison_length) == 0)
1741
42.4k
  break;
1742
102M
    }
1743
25.5M
  if (i >= table_size)
1744
25.5M
    return;
1745
1746
42.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
42.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
42.4k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
42.4k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
42.4k
      && default_alignment > alignment_table[i].default_alignment_max
1753
42.4k
#endif
1754
42.4k
      )
1755
0
    return;
1756
1757
42.4k
  section->alignment_power = alignment_table[i].alignment_power;
1758
42.4k
}
coff-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
12.2M
{
1730
12.2M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
12.2M
  unsigned int i;
1732
1733
61.3M
  for (i = 0; i < table_size; ++i)
1734
49.0M
    {
1735
49.0M
      const char *secname = bfd_section_name (section);
1736
1737
49.0M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
49.0M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
49.0M
    : strncmp (alignment_table[i].name, secname,
1740
24.5M
         alignment_table[i].comparison_length) == 0)
1741
33.7k
  break;
1742
49.0M
    }
1743
12.2M
  if (i >= table_size)
1744
12.2M
    return;
1745
1746
33.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
33.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
0
    return;
1749
1750
33.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
33.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
33.7k
      && default_alignment > alignment_table[i].default_alignment_max
1753
33.7k
#endif
1754
33.7k
      )
1755
0
    return;
1756
1757
33.7k
  section->alignment_power = alignment_table[i].alignment_power;
1758
33.7k
}
coff-stgo32.c:coff_set_custom_section_alignment
Line
Count
Source
1729
358k
{
1730
358k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
358k
  unsigned int i;
1732
1733
3.20M
  for (i = 0; i < table_size; ++i)
1734
2.85M
    {
1735
2.85M
      const char *secname = bfd_section_name (section);
1736
1737
2.85M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.85M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.85M
    : strncmp (alignment_table[i].name, secname,
1740
1.42M
         alignment_table[i].comparison_length) == 0)
1741
5.95k
  break;
1742
2.85M
    }
1743
358k
  if (i >= table_size)
1744
352k
    return;
1745
1746
5.95k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
5.95k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.77k
    return;
1749
1750
4.17k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
4.17k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
4.17k
      && default_alignment > alignment_table[i].default_alignment_max
1753
4.17k
#endif
1754
4.17k
      )
1755
0
    return;
1756
1757
4.17k
  section->alignment_power = alignment_table[i].alignment_power;
1758
4.17k
}
coff-tic30.c:coff_set_custom_section_alignment
Line
Count
Source
1729
5.80M
{
1730
5.80M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
5.80M
  unsigned int i;
1732
1733
28.9M
  for (i = 0; i < table_size; ++i)
1734
23.1M
    {
1735
23.1M
      const char *secname = bfd_section_name (section);
1736
1737
23.1M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
23.1M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
23.1M
    : strncmp (alignment_table[i].name, secname,
1740
11.5M
         alignment_table[i].comparison_length) == 0)
1741
26.7k
  break;
1742
23.1M
    }
1743
5.80M
  if (i >= table_size)
1744
5.77M
    return;
1745
1746
26.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
26.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
18.7k
    return;
1749
1750
7.98k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
7.98k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
7.98k
      && default_alignment > alignment_table[i].default_alignment_max
1753
7.98k
#endif
1754
7.98k
      )
1755
0
    return;
1756
1757
7.98k
  section->alignment_power = alignment_table[i].alignment_power;
1758
7.98k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_custom_section_alignment
coff-tic54x.c:coff_set_custom_section_alignment
Line
Count
Source
1729
8.33M
{
1730
8.33M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
8.33M
  unsigned int i;
1732
1733
41.6M
  for (i = 0; i < table_size; ++i)
1734
33.3M
    {
1735
33.3M
      const char *secname = bfd_section_name (section);
1736
1737
33.3M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
33.3M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
33.3M
    : strncmp (alignment_table[i].name, secname,
1740
16.6M
         alignment_table[i].comparison_length) == 0)
1741
13.5k
  break;
1742
33.3M
    }
1743
8.33M
  if (i >= table_size)
1744
8.32M
    return;
1745
1746
13.5k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
13.5k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
13.5k
    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
753k
{
1730
753k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
753k
  unsigned int i;
1732
1733
3.75M
  for (i = 0; i < table_size; ++i)
1734
3.00M
    {
1735
3.00M
      const char *secname = bfd_section_name (section);
1736
1737
3.00M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
3.00M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
3.00M
    : strncmp (alignment_table[i].name, secname,
1740
1.50M
         alignment_table[i].comparison_length) == 0)
1741
3.21k
  break;
1742
3.00M
    }
1743
753k
  if (i >= table_size)
1744
750k
    return;
1745
1746
3.21k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
3.21k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3.21k
    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
8.88M
{
1730
8.88M
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
8.88M
  unsigned int i;
1732
1733
44.3M
  for (i = 0; i < table_size; ++i)
1734
35.5M
    {
1735
35.5M
      const char *secname = bfd_section_name (section);
1736
1737
35.5M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
35.5M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
35.5M
    : strncmp (alignment_table[i].name, secname,
1740
17.7M
         alignment_table[i].comparison_length) == 0)
1741
31.7k
  break;
1742
35.5M
    }
1743
8.88M
  if (i >= table_size)
1744
8.85M
    return;
1745
1746
31.7k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
31.7k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
21.9k
    return;
1749
1750
9.82k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
9.82k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
9.82k
      && default_alignment > alignment_table[i].default_alignment_max
1753
9.82k
#endif
1754
9.82k
      )
1755
0
    return;
1756
1757
9.82k
  section->alignment_power = alignment_table[i].alignment_power;
1758
9.82k
}
pe-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
42.1k
{
1730
42.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
42.1k
  unsigned int i;
1732
1733
560k
  for (i = 0; i < table_size; ++i)
1734
524k
    {
1735
524k
      const char *secname = bfd_section_name (section);
1736
1737
524k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
524k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
524k
    : strncmp (alignment_table[i].name, secname,
1740
240k
         alignment_table[i].comparison_length) == 0)
1741
5.61k
  break;
1742
524k
    }
1743
42.1k
  if (i >= table_size)
1744
36.4k
    return;
1745
1746
5.61k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
5.61k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.93k
    return;
1749
1750
3.68k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
3.68k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
3.68k
      && default_alignment > alignment_table[i].default_alignment_max
1753
3.68k
#endif
1754
3.68k
      )
1755
0
    return;
1756
1757
3.68k
  section->alignment_power = alignment_table[i].alignment_power;
1758
3.68k
}
pe-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
42.1k
{
1730
42.1k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
42.1k
  unsigned int i;
1732
1733
560k
  for (i = 0; i < table_size; ++i)
1734
524k
    {
1735
524k
      const char *secname = bfd_section_name (section);
1736
1737
524k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
524k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
524k
    : strncmp (alignment_table[i].name, secname,
1740
240k
         alignment_table[i].comparison_length) == 0)
1741
5.61k
  break;
1742
524k
    }
1743
42.1k
  if (i >= table_size)
1744
36.4k
    return;
1745
1746
5.61k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
5.61k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.93k
    return;
1749
1750
3.68k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
3.68k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
3.68k
      && default_alignment > alignment_table[i].default_alignment_max
1753
3.68k
#endif
1754
3.68k
      )
1755
0
    return;
1756
1757
3.68k
  section->alignment_power = alignment_table[i].alignment_power;
1758
3.68k
}
pe-i386.c:coff_set_custom_section_alignment
Line
Count
Source
1729
113k
{
1730
113k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
113k
  unsigned int i;
1732
1733
1.07M
  for (i = 0; i < table_size; ++i)
1734
975k
    {
1735
975k
      const char *secname = bfd_section_name (section);
1736
1737
975k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
975k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
975k
    : strncmp (alignment_table[i].name, secname,
1740
658k
         alignment_table[i].comparison_length) == 0)
1741
11.4k
  break;
1742
975k
    }
1743
113k
  if (i >= table_size)
1744
101k
    return;
1745
1746
11.4k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
11.4k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2.38k
    return;
1749
1750
9.05k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
9.05k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
9.05k
      && default_alignment > alignment_table[i].default_alignment_max
1753
9.05k
#endif
1754
9.05k
      )
1755
0
    return;
1756
1757
9.05k
  section->alignment_power = alignment_table[i].alignment_power;
1758
9.05k
}
pe-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
809k
{
1730
809k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
809k
  unsigned int i;
1732
1733
4.03M
  for (i = 0; i < table_size; ++i)
1734
3.23M
    {
1735
3.23M
      const char *secname = bfd_section_name (section);
1736
1737
3.23M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
3.23M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
3.23M
    : strncmp (alignment_table[i].name, secname,
1740
1.61M
         alignment_table[i].comparison_length) == 0)
1741
5.35k
  break;
1742
3.23M
    }
1743
809k
  if (i >= table_size)
1744
804k
    return;
1745
1746
5.35k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
5.35k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
4.40k
    return;
1749
1750
949
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
949
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
949
      && default_alignment > alignment_table[i].default_alignment_max
1753
949
#endif
1754
949
      )
1755
0
    return;
1756
1757
949
  section->alignment_power = alignment_table[i].alignment_power;
1758
949
}
pe-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
98.0k
{
1730
98.0k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
98.0k
  unsigned int i;
1732
1733
476k
  for (i = 0; i < table_size; ++i)
1734
382k
    {
1735
382k
      const char *secname = bfd_section_name (section);
1736
1737
382k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
382k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
382k
    : strncmp (alignment_table[i].name, secname,
1740
193k
         alignment_table[i].comparison_length) == 0)
1741
4.02k
  break;
1742
382k
    }
1743
98.0k
  if (i >= table_size)
1744
94.0k
    return;
1745
1746
4.02k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4.02k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
1.53k
    return;
1749
1750
2.49k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
2.49k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
2.49k
      && default_alignment > alignment_table[i].default_alignment_max
1753
2.49k
#endif
1754
2.49k
      )
1755
0
    return;
1756
1757
2.49k
  section->alignment_power = alignment_table[i].alignment_power;
1758
2.49k
}
pei-arm-wince.c:coff_set_custom_section_alignment
Line
Count
Source
1729
200k
{
1730
200k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
200k
  unsigned int i;
1732
1733
2.56M
  for (i = 0; i < table_size; ++i)
1734
2.36M
    {
1735
2.36M
      const char *secname = bfd_section_name (section);
1736
1737
2.36M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
2.36M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
2.36M
    : strncmp (alignment_table[i].name, secname,
1740
985k
         alignment_table[i].comparison_length) == 0)
1741
7.33k
  break;
1742
2.36M
    }
1743
200k
  if (i >= table_size)
1744
193k
    return;
1745
1746
7.33k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
7.33k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2.07k
    return;
1749
1750
5.26k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
5.26k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
5.26k
      && default_alignment > alignment_table[i].default_alignment_max
1753
5.26k
#endif
1754
5.26k
      )
1755
0
    return;
1756
1757
5.26k
  section->alignment_power = alignment_table[i].alignment_power;
1758
5.26k
}
pei-arm.c:coff_set_custom_section_alignment
Line
Count
Source
1729
792k
{
1730
792k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
792k
  unsigned int i;
1732
1733
10.1M
  for (i = 0; i < table_size; ++i)
1734
9.40M
    {
1735
9.40M
      const char *secname = bfd_section_name (section);
1736
1737
9.40M
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
9.40M
    ? strcmp (alignment_table[i].name, secname) == 0
1739
9.40M
    : strncmp (alignment_table[i].name, secname,
1740
3.90M
         alignment_table[i].comparison_length) == 0)
1741
18.1k
  break;
1742
9.40M
    }
1743
792k
  if (i >= table_size)
1744
774k
    return;
1745
1746
18.1k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
18.1k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
2.44k
    return;
1749
1750
15.7k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
15.7k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
15.7k
      && default_alignment > alignment_table[i].default_alignment_max
1753
15.7k
#endif
1754
15.7k
      )
1755
0
    return;
1756
1757
15.7k
  section->alignment_power = alignment_table[i].alignment_power;
1758
15.7k
}
pei-mcore.c:coff_set_custom_section_alignment
Line
Count
Source
1729
212k
{
1730
212k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
212k
  unsigned int i;
1732
1733
1.04M
  for (i = 0; i < table_size; ++i)
1734
841k
    {
1735
841k
      const char *secname = bfd_section_name (section);
1736
1737
841k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
841k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
841k
    : strncmp (alignment_table[i].name, secname,
1740
423k
         alignment_table[i].comparison_length) == 0)
1741
4.21k
  break;
1742
841k
    }
1743
212k
  if (i >= table_size)
1744
208k
    return;
1745
1746
4.21k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
4.21k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
3.39k
    return;
1749
1750
826
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
826
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
826
      && default_alignment > alignment_table[i].default_alignment_max
1753
826
#endif
1754
826
      )
1755
0
    return;
1756
1757
826
  section->alignment_power = alignment_table[i].alignment_power;
1758
826
}
pei-sh.c:coff_set_custom_section_alignment
Line
Count
Source
1729
238k
{
1730
238k
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1731
238k
  unsigned int i;
1732
1733
1.17M
  for (i = 0; i < table_size; ++i)
1734
941k
    {
1735
941k
      const char *secname = bfd_section_name (section);
1736
1737
941k
      if (alignment_table[i].comparison_length == (unsigned int) -1
1738
941k
    ? strcmp (alignment_table[i].name, secname) == 0
1739
941k
    : strncmp (alignment_table[i].name, secname,
1740
475k
         alignment_table[i].comparison_length) == 0)
1741
5.85k
  break;
1742
941k
    }
1743
238k
  if (i >= table_size)
1744
232k
    return;
1745
1746
5.85k
  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
1747
5.85k
      && default_alignment < alignment_table[i].default_alignment_min)
1748
4.66k
    return;
1749
1750
1.19k
  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
1751
1.19k
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
1752
1.19k
      && default_alignment > alignment_table[i].default_alignment_max
1753
1.19k
#endif
1754
1.19k
      )
1755
0
    return;
1756
1757
1.19k
  section->alignment_power = alignment_table[i].alignment_power;
1758
1.19k
}
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
96.7M
{
1790
96.7M
  combined_entry_type *native;
1791
96.7M
  size_t amt;
1792
96.7M
  unsigned char sclass = C_STAT;
1793
1794
96.7M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
30.1M
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
30.1M
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
37.4k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
30.1M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
30.1M
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
9.50k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
30.1M
  else
1804
30.1M
    {
1805
30.1M
      int i;
1806
1807
361M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
331M
  if (strcmp (bfd_section_name (section),
1809
331M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
10.1k
    {
1811
10.1k
      section->alignment_power = 0;
1812
10.1k
      sclass = C_DWARF;
1813
10.1k
      break;
1814
10.1k
    }
1815
30.1M
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
96.7M
  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
96.7M
  amt = sizeof (combined_entry_type) * 10;
1828
96.7M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
96.7M
  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
96.7M
  native->is_sym = true;
1839
96.7M
  native->u.syment.n_type = T_NULL;
1840
96.7M
  native->u.syment.n_sclass = sclass;
1841
1842
96.7M
  coffsymbol (section->symbol)->native = native;
1843
1844
96.7M
  coff_set_custom_section_alignment (abfd, section,
1845
96.7M
             coff_section_alignment_table,
1846
96.7M
             coff_section_alignment_table_size);
1847
1848
96.7M
  return true;
1849
96.7M
}
pei-i386.c:coff_new_section_hook
Line
Count
Source
1789
290k
{
1790
290k
  combined_entry_type *native;
1791
290k
  size_t amt;
1792
290k
  unsigned char sclass = C_STAT;
1793
1794
290k
  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
290k
  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
290k
  amt = sizeof (combined_entry_type) * 10;
1828
290k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
290k
  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
290k
  native->is_sym = true;
1839
290k
  native->u.syment.n_type = T_NULL;
1840
290k
  native->u.syment.n_sclass = sclass;
1841
1842
290k
  coffsymbol (section->symbol)->native = native;
1843
1844
290k
  coff_set_custom_section_alignment (abfd, section,
1845
290k
             coff_section_alignment_table,
1846
290k
             coff_section_alignment_table_size);
1847
1848
290k
  return true;
1849
290k
}
pe-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
321k
{
1790
321k
  combined_entry_type *native;
1791
321k
  size_t amt;
1792
321k
  unsigned char sclass = C_STAT;
1793
1794
321k
  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
321k
  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
321k
  amt = sizeof (combined_entry_type) * 10;
1828
321k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
321k
  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
321k
  native->is_sym = true;
1839
321k
  native->u.syment.n_type = T_NULL;
1840
321k
  native->u.syment.n_sclass = sclass;
1841
1842
321k
  coffsymbol (section->symbol)->native = native;
1843
1844
321k
  coff_set_custom_section_alignment (abfd, section,
1845
321k
             coff_section_alignment_table,
1846
321k
             coff_section_alignment_table_size);
1847
1848
321k
  return true;
1849
321k
}
pei-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
235k
{
1790
235k
  combined_entry_type *native;
1791
235k
  size_t amt;
1792
235k
  unsigned char sclass = C_STAT;
1793
1794
235k
  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
235k
  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
235k
  amt = sizeof (combined_entry_type) * 10;
1828
235k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
235k
  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
235k
  native->is_sym = true;
1839
235k
  native->u.syment.n_type = T_NULL;
1840
235k
  native->u.syment.n_sclass = sclass;
1841
1842
235k
  coffsymbol (section->symbol)->native = native;
1843
1844
235k
  coff_set_custom_section_alignment (abfd, section,
1845
235k
             coff_section_alignment_table,
1846
235k
             coff_section_alignment_table_size);
1847
1848
235k
  return true;
1849
235k
}
coff-x86_64.c:coff_new_section_hook
Line
Count
Source
1789
9.32M
{
1790
9.32M
  combined_entry_type *native;
1791
9.32M
  size_t amt;
1792
9.32M
  unsigned char sclass = C_STAT;
1793
1794
9.32M
  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.32M
  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.32M
  amt = sizeof (combined_entry_type) * 10;
1828
9.32M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
9.32M
  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.32M
  native->is_sym = true;
1839
9.32M
  native->u.syment.n_type = T_NULL;
1840
9.32M
  native->u.syment.n_sclass = sclass;
1841
1842
9.32M
  coffsymbol (section->symbol)->native = native;
1843
1844
9.32M
  coff_set_custom_section_alignment (abfd, section,
1845
9.32M
             coff_section_alignment_table,
1846
9.32M
             coff_section_alignment_table_size);
1847
1848
9.32M
  return true;
1849
9.32M
}
coff64-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
4.62M
{
1790
4.62M
  combined_entry_type *native;
1791
4.62M
  size_t amt;
1792
4.62M
  unsigned char sclass = C_STAT;
1793
1794
4.62M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
4.62M
#ifdef RS6000COFF_C
1797
4.62M
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
4.62M
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
7.58k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
4.61M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
4.61M
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
3.55k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
4.61M
  else
1804
4.61M
    {
1805
4.61M
      int i;
1806
1807
55.3M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
50.7M
  if (strcmp (bfd_section_name (section),
1809
50.7M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
3.34k
    {
1811
3.34k
      section->alignment_power = 0;
1812
3.34k
      sclass = C_DWARF;
1813
3.34k
      break;
1814
3.34k
    }
1815
4.61M
    }
1816
4.62M
#endif
1817
1818
  /* Set up the section symbol.  */
1819
4.62M
  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.62M
  amt = sizeof (combined_entry_type) * 10;
1828
4.62M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4.62M
  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.62M
  native->is_sym = true;
1839
4.62M
  native->u.syment.n_type = T_NULL;
1840
4.62M
  native->u.syment.n_sclass = sclass;
1841
1842
4.62M
  coffsymbol (section->symbol)->native = native;
1843
1844
4.62M
  coff_set_custom_section_alignment (abfd, section,
1845
4.62M
             coff_section_alignment_table,
1846
4.62M
             coff_section_alignment_table_size);
1847
1848
4.62M
  return true;
1849
4.62M
}
pe-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
124k
{
1790
124k
  combined_entry_type *native;
1791
124k
  size_t amt;
1792
124k
  unsigned char sclass = C_STAT;
1793
1794
124k
  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
124k
  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
124k
  amt = sizeof (combined_entry_type) * 10;
1828
124k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
124k
  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
124k
  native->is_sym = true;
1839
124k
  native->u.syment.n_type = T_NULL;
1840
124k
  native->u.syment.n_sclass = sclass;
1841
1842
124k
  coffsymbol (section->symbol)->native = native;
1843
1844
124k
  coff_set_custom_section_alignment (abfd, section,
1845
124k
             coff_section_alignment_table,
1846
124k
             coff_section_alignment_table_size);
1847
1848
124k
  return true;
1849
124k
}
pei-aarch64.c:coff_new_section_hook
Line
Count
Source
1789
170k
{
1790
170k
  combined_entry_type *native;
1791
170k
  size_t amt;
1792
170k
  unsigned char sclass = C_STAT;
1793
1794
170k
  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
170k
  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
170k
  amt = sizeof (combined_entry_type) * 10;
1828
170k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
170k
  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
170k
  native->is_sym = true;
1839
170k
  native->u.syment.n_type = T_NULL;
1840
170k
  native->u.syment.n_sclass = sclass;
1841
1842
170k
  coffsymbol (section->symbol)->native = native;
1843
1844
170k
  coff_set_custom_section_alignment (abfd, section,
1845
170k
             coff_section_alignment_table,
1846
170k
             coff_section_alignment_table_size);
1847
1848
170k
  return true;
1849
170k
}
pei-ia64.c:coff_new_section_hook
Line
Count
Source
1789
229k
{
1790
229k
  combined_entry_type *native;
1791
229k
  size_t amt;
1792
229k
  unsigned char sclass = C_STAT;
1793
1794
229k
  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
229k
  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
229k
  amt = sizeof (combined_entry_type) * 10;
1828
229k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
229k
  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
229k
  native->is_sym = true;
1839
229k
  native->u.syment.n_type = T_NULL;
1840
229k
  native->u.syment.n_sclass = sclass;
1841
1842
229k
  coffsymbol (section->symbol)->native = native;
1843
1844
229k
  coff_set_custom_section_alignment (abfd, section,
1845
229k
             coff_section_alignment_table,
1846
229k
             coff_section_alignment_table_size);
1847
1848
229k
  return true;
1849
229k
}
pei-loongarch64.c:coff_new_section_hook
Line
Count
Source
1789
176k
{
1790
176k
  combined_entry_type *native;
1791
176k
  size_t amt;
1792
176k
  unsigned char sclass = C_STAT;
1793
1794
176k
  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
176k
  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
176k
  amt = sizeof (combined_entry_type) * 10;
1828
176k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
176k
  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
176k
  native->is_sym = true;
1839
176k
  native->u.syment.n_type = T_NULL;
1840
176k
  native->u.syment.n_sclass = sclass;
1841
1842
176k
  coffsymbol (section->symbol)->native = native;
1843
1844
176k
  coff_set_custom_section_alignment (abfd, section,
1845
176k
             coff_section_alignment_table,
1846
176k
             coff_section_alignment_table_size);
1847
1848
176k
  return true;
1849
176k
}
cf-i386lynx.c:coff_new_section_hook
Line
Count
Source
1789
6.05M
{
1790
6.05M
  combined_entry_type *native;
1791
6.05M
  size_t amt;
1792
6.05M
  unsigned char sclass = C_STAT;
1793
1794
6.05M
  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.05M
  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.05M
  amt = sizeof (combined_entry_type) * 10;
1828
6.05M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
6.05M
  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.05M
  native->is_sym = true;
1839
6.05M
  native->u.syment.n_type = T_NULL;
1840
6.05M
  native->u.syment.n_sclass = sclass;
1841
1842
6.05M
  coffsymbol (section->symbol)->native = native;
1843
1844
6.05M
  coff_set_custom_section_alignment (abfd, section,
1845
6.05M
             coff_section_alignment_table,
1846
6.05M
             coff_section_alignment_table_size);
1847
1848
6.05M
  return true;
1849
6.05M
}
coff-go32.c:coff_new_section_hook
Line
Count
Source
1789
4.96M
{
1790
4.96M
  combined_entry_type *native;
1791
4.96M
  size_t amt;
1792
4.96M
  unsigned char sclass = C_STAT;
1793
1794
4.96M
  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.96M
  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.96M
  amt = sizeof (combined_entry_type) * 10;
1828
4.96M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
4.96M
  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.96M
  native->is_sym = true;
1839
4.96M
  native->u.syment.n_type = T_NULL;
1840
4.96M
  native->u.syment.n_sclass = sclass;
1841
1842
4.96M
  coffsymbol (section->symbol)->native = native;
1843
1844
4.96M
  coff_set_custom_section_alignment (abfd, section,
1845
4.96M
             coff_section_alignment_table,
1846
4.96M
             coff_section_alignment_table_size);
1847
1848
4.96M
  return true;
1849
4.96M
}
coff-i386.c:coff_new_section_hook
Line
Count
Source
1789
5.72M
{
1790
5.72M
  combined_entry_type *native;
1791
5.72M
  size_t amt;
1792
5.72M
  unsigned char sclass = C_STAT;
1793
1794
5.72M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
5.72M
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
5.72M
  amt = sizeof (combined_entry_type) * 10;
1828
5.72M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
5.72M
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
5.72M
  native->is_sym = true;
1839
5.72M
  native->u.syment.n_type = T_NULL;
1840
5.72M
  native->u.syment.n_sclass = sclass;
1841
1842
5.72M
  coffsymbol (section->symbol)->native = native;
1843
1844
5.72M
  coff_set_custom_section_alignment (abfd, section,
1845
5.72M
             coff_section_alignment_table,
1846
5.72M
             coff_section_alignment_table_size);
1847
1848
5.72M
  return true;
1849
5.72M
}
coff-rs6000.c:coff_new_section_hook
Line
Count
Source
1789
25.5M
{
1790
25.5M
  combined_entry_type *native;
1791
25.5M
  size_t amt;
1792
25.5M
  unsigned char sclass = C_STAT;
1793
1794
25.5M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
25.5M
#ifdef RS6000COFF_C
1797
25.5M
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
25.5M
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
29.8k
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
25.5M
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
25.5M
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
5.94k
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
25.5M
  else
1804
25.5M
    {
1805
25.5M
      int i;
1806
1807
306M
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
280M
  if (strcmp (bfd_section_name (section),
1809
280M
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
6.79k
    {
1811
6.79k
      section->alignment_power = 0;
1812
6.79k
      sclass = C_DWARF;
1813
6.79k
      break;
1814
6.79k
    }
1815
25.5M
    }
1816
25.5M
#endif
1817
1818
  /* Set up the section symbol.  */
1819
25.5M
  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
25.5M
  amt = sizeof (combined_entry_type) * 10;
1828
25.5M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
25.5M
  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
25.5M
  native->is_sym = true;
1839
25.5M
  native->u.syment.n_type = T_NULL;
1840
25.5M
  native->u.syment.n_sclass = sclass;
1841
1842
25.5M
  coffsymbol (section->symbol)->native = native;
1843
1844
25.5M
  coff_set_custom_section_alignment (abfd, section,
1845
25.5M
             coff_section_alignment_table,
1846
25.5M
             coff_section_alignment_table_size);
1847
1848
25.5M
  return true;
1849
25.5M
}
coff-sh.c:coff_new_section_hook
Line
Count
Source
1789
12.2M
{
1790
12.2M
  combined_entry_type *native;
1791
12.2M
  size_t amt;
1792
12.2M
  unsigned char sclass = C_STAT;
1793
1794
12.2M
  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
12.2M
  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
12.2M
  amt = sizeof (combined_entry_type) * 10;
1828
12.2M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
12.2M
  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
12.2M
  native->is_sym = true;
1839
12.2M
  native->u.syment.n_type = T_NULL;
1840
12.2M
  native->u.syment.n_sclass = sclass;
1841
1842
12.2M
  coffsymbol (section->symbol)->native = native;
1843
1844
12.2M
  coff_set_custom_section_alignment (abfd, section,
1845
12.2M
             coff_section_alignment_table,
1846
12.2M
             coff_section_alignment_table_size);
1847
1848
12.2M
  return true;
1849
12.2M
}
coff-stgo32.c:coff_new_section_hook
Line
Count
Source
1789
358k
{
1790
358k
  combined_entry_type *native;
1791
358k
  size_t amt;
1792
358k
  unsigned char sclass = C_STAT;
1793
1794
358k
  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
358k
  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
358k
  amt = sizeof (combined_entry_type) * 10;
1828
358k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
358k
  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
358k
  native->is_sym = true;
1839
358k
  native->u.syment.n_type = T_NULL;
1840
358k
  native->u.syment.n_sclass = sclass;
1841
1842
358k
  coffsymbol (section->symbol)->native = native;
1843
1844
358k
  coff_set_custom_section_alignment (abfd, section,
1845
358k
             coff_section_alignment_table,
1846
358k
             coff_section_alignment_table_size);
1847
1848
358k
  return true;
1849
358k
}
coff-tic30.c:coff_new_section_hook
Line
Count
Source
1789
5.80M
{
1790
5.80M
  combined_entry_type *native;
1791
5.80M
  size_t amt;
1792
5.80M
  unsigned char sclass = C_STAT;
1793
1794
5.80M
  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
1795
1796
#ifdef RS6000COFF_C
1797
  if (bfd_xcoff_text_align_power (abfd) != 0
1798
      && strcmp (bfd_section_name (section), ".text") == 0)
1799
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
1800
  else if (bfd_xcoff_data_align_power (abfd) != 0
1801
      && strcmp (bfd_section_name (section), ".data") == 0)
1802
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
1803
  else
1804
    {
1805
      int i;
1806
1807
      for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
1808
  if (strcmp (bfd_section_name (section),
1809
        xcoff_dwsect_names[i].xcoff_name) == 0)
1810
    {
1811
      section->alignment_power = 0;
1812
      sclass = C_DWARF;
1813
      break;
1814
    }
1815
    }
1816
#endif
1817
1818
  /* Set up the section symbol.  */
1819
5.80M
  if (!_bfd_generic_new_section_hook (abfd, section))
1820
0
    return false;
1821
1822
  /* Allocate aux records for section symbols, to store size and
1823
     related info.
1824
1825
     @@ The 10 is a guess at a plausible maximum number of aux entries
1826
     (but shouldn't be a constant).  */
1827
5.80M
  amt = sizeof (combined_entry_type) * 10;
1828
5.80M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
5.80M
  if (native == NULL)
1830
0
    return false;
1831
1832
  /* We don't need to set up n_name, n_value, or n_scnum in the native
1833
     symbol information, since they'll be overridden by the BFD symbol
1834
     anyhow.  However, we do need to set the type and storage class,
1835
     in case this symbol winds up getting written out.  The value 0
1836
     for n_numaux is already correct.  */
1837
1838
5.80M
  native->is_sym = true;
1839
5.80M
  native->u.syment.n_type = T_NULL;
1840
5.80M
  native->u.syment.n_sclass = sclass;
1841
1842
5.80M
  coffsymbol (section->symbol)->native = native;
1843
1844
5.80M
  coff_set_custom_section_alignment (abfd, section,
1845
5.80M
             coff_section_alignment_table,
1846
5.80M
             coff_section_alignment_table_size);
1847
1848
5.80M
  return true;
1849
5.80M
}
Unexecuted instantiation: coff-tic4x.c:coff_new_section_hook
coff-tic54x.c:coff_new_section_hook
Line
Count
Source
1789
8.33M
{
1790
8.33M
  combined_entry_type *native;
1791
8.33M
  size_t amt;
1792
8.33M
  unsigned char sclass = C_STAT;
1793
1794
8.33M
  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
8.33M
  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
8.33M
  amt = sizeof (combined_entry_type) * 10;
1828
8.33M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
8.33M
  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
8.33M
  native->is_sym = true;
1839
8.33M
  native->u.syment.n_type = T_NULL;
1840
8.33M
  native->u.syment.n_sclass = sclass;
1841
1842
8.33M
  coffsymbol (section->symbol)->native = native;
1843
1844
8.33M
  coff_set_custom_section_alignment (abfd, section,
1845
8.33M
             coff_section_alignment_table,
1846
8.33M
             coff_section_alignment_table_size);
1847
1848
8.33M
  return true;
1849
8.33M
}
coff-z80.c:coff_new_section_hook
Line
Count
Source
1789
753k
{
1790
753k
  combined_entry_type *native;
1791
753k
  size_t amt;
1792
753k
  unsigned char sclass = C_STAT;
1793
1794
753k
  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
753k
  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
753k
  amt = sizeof (combined_entry_type) * 10;
1828
753k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
753k
  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
753k
  native->is_sym = true;
1839
753k
  native->u.syment.n_type = T_NULL;
1840
753k
  native->u.syment.n_sclass = sclass;
1841
1842
753k
  coffsymbol (section->symbol)->native = native;
1843
1844
753k
  coff_set_custom_section_alignment (abfd, section,
1845
753k
             coff_section_alignment_table,
1846
753k
             coff_section_alignment_table_size);
1847
1848
753k
  return true;
1849
753k
}
coff-z8k.c:coff_new_section_hook
Line
Count
Source
1789
8.88M
{
1790
8.88M
  combined_entry_type *native;
1791
8.88M
  size_t amt;
1792
8.88M
  unsigned char sclass = C_STAT;
1793
1794
8.88M
  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
8.88M
  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
8.88M
  amt = sizeof (combined_entry_type) * 10;
1828
8.88M
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
8.88M
  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
8.88M
  native->is_sym = true;
1839
8.88M
  native->u.syment.n_type = T_NULL;
1840
8.88M
  native->u.syment.n_sclass = sclass;
1841
1842
8.88M
  coffsymbol (section->symbol)->native = native;
1843
1844
8.88M
  coff_set_custom_section_alignment (abfd, section,
1845
8.88M
             coff_section_alignment_table,
1846
8.88M
             coff_section_alignment_table_size);
1847
1848
8.88M
  return true;
1849
8.88M
}
pe-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
42.1k
{
1790
42.1k
  combined_entry_type *native;
1791
42.1k
  size_t amt;
1792
42.1k
  unsigned char sclass = C_STAT;
1793
1794
42.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
42.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
42.1k
  amt = sizeof (combined_entry_type) * 10;
1828
42.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
42.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
42.1k
  native->is_sym = true;
1839
42.1k
  native->u.syment.n_type = T_NULL;
1840
42.1k
  native->u.syment.n_sclass = sclass;
1841
1842
42.1k
  coffsymbol (section->symbol)->native = native;
1843
1844
42.1k
  coff_set_custom_section_alignment (abfd, section,
1845
42.1k
             coff_section_alignment_table,
1846
42.1k
             coff_section_alignment_table_size);
1847
1848
42.1k
  return true;
1849
42.1k
}
pe-arm.c:coff_new_section_hook
Line
Count
Source
1789
42.1k
{
1790
42.1k
  combined_entry_type *native;
1791
42.1k
  size_t amt;
1792
42.1k
  unsigned char sclass = C_STAT;
1793
1794
42.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
42.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
42.1k
  amt = sizeof (combined_entry_type) * 10;
1828
42.1k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
42.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
42.1k
  native->is_sym = true;
1839
42.1k
  native->u.syment.n_type = T_NULL;
1840
42.1k
  native->u.syment.n_sclass = sclass;
1841
1842
42.1k
  coffsymbol (section->symbol)->native = native;
1843
1844
42.1k
  coff_set_custom_section_alignment (abfd, section,
1845
42.1k
             coff_section_alignment_table,
1846
42.1k
             coff_section_alignment_table_size);
1847
1848
42.1k
  return true;
1849
42.1k
}
pe-i386.c:coff_new_section_hook
Line
Count
Source
1789
113k
{
1790
113k
  combined_entry_type *native;
1791
113k
  size_t amt;
1792
113k
  unsigned char sclass = C_STAT;
1793
1794
113k
  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
113k
  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
113k
  amt = sizeof (combined_entry_type) * 10;
1828
113k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
113k
  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
113k
  native->is_sym = true;
1839
113k
  native->u.syment.n_type = T_NULL;
1840
113k
  native->u.syment.n_sclass = sclass;
1841
1842
113k
  coffsymbol (section->symbol)->native = native;
1843
1844
113k
  coff_set_custom_section_alignment (abfd, section,
1845
113k
             coff_section_alignment_table,
1846
113k
             coff_section_alignment_table_size);
1847
1848
113k
  return true;
1849
113k
}
pe-mcore.c:coff_new_section_hook
Line
Count
Source
1789
809k
{
1790
809k
  combined_entry_type *native;
1791
809k
  size_t amt;
1792
809k
  unsigned char sclass = C_STAT;
1793
1794
809k
  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
809k
  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
809k
  amt = sizeof (combined_entry_type) * 10;
1828
809k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
809k
  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
809k
  native->is_sym = true;
1839
809k
  native->u.syment.n_type = T_NULL;
1840
809k
  native->u.syment.n_sclass = sclass;
1841
1842
809k
  coffsymbol (section->symbol)->native = native;
1843
1844
809k
  coff_set_custom_section_alignment (abfd, section,
1845
809k
             coff_section_alignment_table,
1846
809k
             coff_section_alignment_table_size);
1847
1848
809k
  return true;
1849
809k
}
pe-sh.c:coff_new_section_hook
Line
Count
Source
1789
98.0k
{
1790
98.0k
  combined_entry_type *native;
1791
98.0k
  size_t amt;
1792
98.0k
  unsigned char sclass = C_STAT;
1793
1794
98.0k
  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
98.0k
  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
98.0k
  amt = sizeof (combined_entry_type) * 10;
1828
98.0k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
98.0k
  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
98.0k
  native->is_sym = true;
1839
98.0k
  native->u.syment.n_type = T_NULL;
1840
98.0k
  native->u.syment.n_sclass = sclass;
1841
1842
98.0k
  coffsymbol (section->symbol)->native = native;
1843
1844
98.0k
  coff_set_custom_section_alignment (abfd, section,
1845
98.0k
             coff_section_alignment_table,
1846
98.0k
             coff_section_alignment_table_size);
1847
1848
98.0k
  return true;
1849
98.0k
}
pei-arm-wince.c:coff_new_section_hook
Line
Count
Source
1789
200k
{
1790
200k
  combined_entry_type *native;
1791
200k
  size_t amt;
1792
200k
  unsigned char sclass = C_STAT;
1793
1794
200k
  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
200k
  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
200k
  amt = sizeof (combined_entry_type) * 10;
1828
200k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
200k
  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
200k
  native->is_sym = true;
1839
200k
  native->u.syment.n_type = T_NULL;
1840
200k
  native->u.syment.n_sclass = sclass;
1841
1842
200k
  coffsymbol (section->symbol)->native = native;
1843
1844
200k
  coff_set_custom_section_alignment (abfd, section,
1845
200k
             coff_section_alignment_table,
1846
200k
             coff_section_alignment_table_size);
1847
1848
200k
  return true;
1849
200k
}
pei-arm.c:coff_new_section_hook
Line
Count
Source
1789
792k
{
1790
792k
  combined_entry_type *native;
1791
792k
  size_t amt;
1792
792k
  unsigned char sclass = C_STAT;
1793
1794
792k
  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
792k
  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
792k
  amt = sizeof (combined_entry_type) * 10;
1828
792k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
792k
  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
792k
  native->is_sym = true;
1839
792k
  native->u.syment.n_type = T_NULL;
1840
792k
  native->u.syment.n_sclass = sclass;
1841
1842
792k
  coffsymbol (section->symbol)->native = native;
1843
1844
792k
  coff_set_custom_section_alignment (abfd, section,
1845
792k
             coff_section_alignment_table,
1846
792k
             coff_section_alignment_table_size);
1847
1848
792k
  return true;
1849
792k
}
pei-mcore.c:coff_new_section_hook
Line
Count
Source
1789
212k
{
1790
212k
  combined_entry_type *native;
1791
212k
  size_t amt;
1792
212k
  unsigned char sclass = C_STAT;
1793
1794
212k
  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
212k
  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
212k
  amt = sizeof (combined_entry_type) * 10;
1828
212k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
212k
  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
212k
  native->is_sym = true;
1839
212k
  native->u.syment.n_type = T_NULL;
1840
212k
  native->u.syment.n_sclass = sclass;
1841
1842
212k
  coffsymbol (section->symbol)->native = native;
1843
1844
212k
  coff_set_custom_section_alignment (abfd, section,
1845
212k
             coff_section_alignment_table,
1846
212k
             coff_section_alignment_table_size);
1847
1848
212k
  return true;
1849
212k
}
pei-sh.c:coff_new_section_hook
Line
Count
Source
1789
238k
{
1790
238k
  combined_entry_type *native;
1791
238k
  size_t amt;
1792
238k
  unsigned char sclass = C_STAT;
1793
1794
238k
  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
238k
  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
238k
  amt = sizeof (combined_entry_type) * 10;
1828
238k
  native = (combined_entry_type *) bfd_zalloc (abfd, amt);
1829
238k
  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
238k
  native->is_sym = true;
1839
238k
  native->u.syment.n_type = T_NULL;
1840
238k
  native->u.syment.n_sclass = sclass;
1841
1842
238k
  coffsymbol (section->symbol)->native = native;
1843
1844
238k
  coff_set_custom_section_alignment (abfd, section,
1845
238k
             coff_section_alignment_table,
1846
238k
             coff_section_alignment_table_size);
1847
1848
238k
  return true;
1849
238k
}
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
9.08M
{
1860
9.08M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
9.08M
  unsigned int i;
1862
1863
9.08M
#ifdef COFF_DECODE_ALIGNMENT
1864
9.08M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
9.08M
#endif
1866
9.08M
  section->alignment_power = i;
1867
1868
#ifdef coff_set_section_load_page
1869
8.33M
  coff_set_section_load_page (section, hdr->s_page);
1870
#endif
1871
9.08M
}
Unexecuted instantiation: coff-tic4x.c:coff_set_alignment_hook
coff-tic54x.c:coff_set_alignment_hook
Line
Count
Source
1859
8.33M
{
1860
8.33M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
8.33M
  unsigned int i;
1862
1863
8.33M
#ifdef COFF_DECODE_ALIGNMENT
1864
8.33M
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
8.33M
#endif
1866
8.33M
  section->alignment_power = i;
1867
1868
8.33M
#ifdef coff_set_section_load_page
1869
8.33M
  coff_set_section_load_page (section, hdr->s_page);
1870
8.33M
#endif
1871
8.33M
}
coff-z80.c:coff_set_alignment_hook
Line
Count
Source
1859
753k
{
1860
753k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1861
753k
  unsigned int i;
1862
1863
753k
#ifdef COFF_DECODE_ALIGNMENT
1864
753k
  i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
1865
753k
#endif
1866
753k
  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
753k
}
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
3.99M
{
1881
3.99M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
3.99M
  size_t amt;
1883
3.99M
  unsigned int alignment_power_const
1884
3.99M
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
3.99M
  switch (alignment_power_const)
1887
3.99M
    {
1888
91.3k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
111k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
168k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
185k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
275k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
307k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
424k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
465k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
573k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
637k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
714k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
794k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
938k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
985k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
985k
      section->alignment_power
1903
985k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
985k
      break;
1905
3.00M
    default:
1906
3.00M
      break;
1907
3.99M
    }
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
3.99M
  if (coff_section_data (abfd, section) == NULL)
1914
3.99M
    {
1915
3.99M
      amt = sizeof (struct coff_section_tdata);
1916
3.99M
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
3.99M
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
3.99M
    }
1921
1922
3.99M
  if (pei_section_data (abfd, section) == NULL)
1923
3.99M
    {
1924
3.99M
      amt = sizeof (struct pei_section_tdata);
1925
3.99M
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
3.99M
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
3.99M
    }
1930
3.99M
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
3.99M
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
3.99M
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
3.99M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
429k
    {
1938
429k
      struct external_reloc dst;
1939
429k
      struct internal_reloc n;
1940
429k
      file_ptr oldpos = bfd_tell (abfd);
1941
429k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
429k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
429k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
267k
  return;
1947
1948
162k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
162k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
162k
      if (n.r_vaddr < 0x10000)
1952
51.7k
  {
1953
51.7k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
51.7k
    bfd_set_error (bfd_error_bad_value);
1955
51.7k
    return;
1956
51.7k
  }
1957
110k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
110k
      section->rel_filepos += relsz;
1959
110k
    }
1960
3.56M
  else if (hdr->s_nreloc == 0xffff)
1961
21.6k
    _bfd_error_handler
1962
21.6k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
21.6k
       abfd);
1964
3.99M
}
pei-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
282k
{
1881
282k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
282k
  size_t amt;
1883
282k
  unsigned int alignment_power_const
1884
282k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
282k
  switch (alignment_power_const)
1887
282k
    {
1888
6.50k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
7.72k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
12.5k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
13.5k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
21.2k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
33.7k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
37.0k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
38.1k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
46.1k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
48.0k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
51.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
56.9k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
67.1k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
70.4k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
70.4k
      section->alignment_power
1903
70.4k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
70.4k
      break;
1905
211k
    default:
1906
211k
      break;
1907
282k
    }
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
282k
  if (coff_section_data (abfd, section) == NULL)
1914
282k
    {
1915
282k
      amt = sizeof (struct coff_section_tdata);
1916
282k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
282k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
282k
    }
1921
1922
282k
  if (pei_section_data (abfd, section) == NULL)
1923
282k
    {
1924
282k
      amt = sizeof (struct pei_section_tdata);
1925
282k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
282k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
282k
    }
1930
282k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
282k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
282k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
282k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
27.1k
    {
1938
27.1k
      struct external_reloc dst;
1939
27.1k
      struct internal_reloc n;
1940
27.1k
      file_ptr oldpos = bfd_tell (abfd);
1941
27.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
27.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
27.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
14.4k
  return;
1947
1948
12.7k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
12.7k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
12.7k
      if (n.r_vaddr < 0x10000)
1952
6.15k
  {
1953
6.15k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
6.15k
    bfd_set_error (bfd_error_bad_value);
1955
6.15k
    return;
1956
6.15k
  }
1957
6.55k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
6.55k
      section->rel_filepos += relsz;
1959
6.55k
    }
1960
255k
  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
282k
}
pe-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
318k
{
1881
318k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
318k
  size_t amt;
1883
318k
  unsigned int alignment_power_const
1884
318k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
318k
  switch (alignment_power_const)
1887
318k
    {
1888
2.36k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
4.97k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
11.0k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
11.6k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
18.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
20.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
28.9k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
35.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
50.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
58.8k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
84.4k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
101k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
117k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
124k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
124k
      section->alignment_power
1903
124k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
124k
      break;
1905
193k
    default:
1906
193k
      break;
1907
318k
    }
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
318k
  if (coff_section_data (abfd, section) == NULL)
1914
318k
    {
1915
318k
      amt = sizeof (struct coff_section_tdata);
1916
318k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
318k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
318k
    }
1921
1922
318k
  if (pei_section_data (abfd, section) == NULL)
1923
318k
    {
1924
318k
      amt = sizeof (struct pei_section_tdata);
1925
318k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
318k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
318k
    }
1930
318k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
318k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
318k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
318k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
39.5k
    {
1938
39.5k
      struct external_reloc dst;
1939
39.5k
      struct internal_reloc n;
1940
39.5k
      file_ptr oldpos = bfd_tell (abfd);
1941
39.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
39.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
39.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
29.9k
  return;
1947
1948
9.59k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
9.59k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
9.59k
      if (n.r_vaddr < 0x10000)
1952
1.65k
  {
1953
1.65k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1.65k
    bfd_set_error (bfd_error_bad_value);
1955
1.65k
    return;
1956
1.65k
  }
1957
7.93k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
7.93k
      section->rel_filepos += relsz;
1959
7.93k
    }
1960
278k
  else if (hdr->s_nreloc == 0xffff)
1961
8.56k
    _bfd_error_handler
1962
8.56k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
8.56k
       abfd);
1964
318k
}
pei-x86_64.c:coff_set_alignment_hook
Line
Count
Source
1880
212k
{
1881
212k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
212k
  size_t amt;
1883
212k
  unsigned int alignment_power_const
1884
212k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
212k
  switch (alignment_power_const)
1887
212k
    {
1888
8.54k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
9.32k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
16.1k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
18.0k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
21.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
22.9k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
26.7k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
28.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
34.1k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
52.7k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
60.7k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
66.1k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
79.4k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
91.6k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
91.6k
      section->alignment_power
1903
91.6k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
91.6k
      break;
1905
121k
    default:
1906
121k
      break;
1907
212k
    }
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
212k
  if (coff_section_data (abfd, section) == NULL)
1914
212k
    {
1915
212k
      amt = sizeof (struct coff_section_tdata);
1916
212k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
212k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
212k
    }
1921
1922
212k
  if (pei_section_data (abfd, section) == NULL)
1923
212k
    {
1924
212k
      amt = sizeof (struct pei_section_tdata);
1925
212k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
212k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
212k
    }
1930
212k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
212k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
212k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
212k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
22.5k
    {
1938
22.5k
      struct external_reloc dst;
1939
22.5k
      struct internal_reloc n;
1940
22.5k
      file_ptr oldpos = bfd_tell (abfd);
1941
22.5k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
22.5k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
22.5k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
14.9k
  return;
1947
1948
7.61k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
7.61k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
7.61k
      if (n.r_vaddr < 0x10000)
1952
2.11k
  {
1953
2.11k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
2.11k
    bfd_set_error (bfd_error_bad_value);
1955
2.11k
    return;
1956
2.11k
  }
1957
5.50k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
5.50k
      section->rel_filepos += relsz;
1959
5.50k
    }
1960
190k
  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
212k
}
pe-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
123k
{
1881
123k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
123k
  size_t amt;
1883
123k
  unsigned int alignment_power_const
1884
123k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
123k
  switch (alignment_power_const)
1887
123k
    {
1888
767
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
959
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
7.12k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
7.52k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
15.7k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
16.1k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
18.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
25.0k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
28.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
29.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
31.2k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
34.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
37.2k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
38.0k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
38.0k
      section->alignment_power
1903
38.0k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
38.0k
      break;
1905
85.0k
    default:
1906
85.0k
      break;
1907
123k
    }
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
123k
  if (coff_section_data (abfd, section) == NULL)
1914
123k
    {
1915
123k
      amt = sizeof (struct coff_section_tdata);
1916
123k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
123k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
123k
    }
1921
1922
123k
  if (pei_section_data (abfd, section) == NULL)
1923
123k
    {
1924
123k
      amt = sizeof (struct pei_section_tdata);
1925
123k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
123k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
123k
    }
1930
123k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
123k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
123k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
123k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
20.9k
    {
1938
20.9k
      struct external_reloc dst;
1939
20.9k
      struct internal_reloc n;
1940
20.9k
      file_ptr oldpos = bfd_tell (abfd);
1941
20.9k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
20.9k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
20.9k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
17.7k
  return;
1947
1948
3.23k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
3.23k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
3.23k
      if (n.r_vaddr < 0x10000)
1952
1.53k
  {
1953
1.53k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1.53k
    bfd_set_error (bfd_error_bad_value);
1955
1.53k
    return;
1956
1.53k
  }
1957
1.70k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
1.70k
      section->rel_filepos += relsz;
1959
1.70k
    }
1960
102k
  else if (hdr->s_nreloc == 0xffff)
1961
1.63k
    _bfd_error_handler
1962
1.63k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1.63k
       abfd);
1964
123k
}
pei-aarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
155k
{
1881
155k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
155k
  size_t amt;
1883
155k
  unsigned int alignment_power_const
1884
155k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
155k
  switch (alignment_power_const)
1887
155k
    {
1888
10.2k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
11.4k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
13.6k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
14.3k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
20.1k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
20.7k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
28.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
30.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
39.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
44.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
48.1k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
54.8k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
63.7k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
65.5k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
65.5k
      section->alignment_power
1903
65.5k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
65.5k
      break;
1905
90.3k
    default:
1906
90.3k
      break;
1907
155k
    }
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
155k
  if (coff_section_data (abfd, section) == NULL)
1914
155k
    {
1915
155k
      amt = sizeof (struct coff_section_tdata);
1916
155k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
155k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
155k
    }
1921
1922
155k
  if (pei_section_data (abfd, section) == NULL)
1923
155k
    {
1924
155k
      amt = sizeof (struct pei_section_tdata);
1925
155k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
155k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
155k
    }
1930
155k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
155k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
155k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
155k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
30.1k
    {
1938
30.1k
      struct external_reloc dst;
1939
30.1k
      struct internal_reloc n;
1940
30.1k
      file_ptr oldpos = bfd_tell (abfd);
1941
30.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
30.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
30.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
18.6k
  return;
1947
1948
11.5k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
11.5k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
11.5k
      if (n.r_vaddr < 0x10000)
1952
5.04k
  {
1953
5.04k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
5.04k
    bfd_set_error (bfd_error_bad_value);
1955
5.04k
    return;
1956
5.04k
  }
1957
6.49k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
6.49k
      section->rel_filepos += relsz;
1959
6.49k
    }
1960
125k
  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
155k
}
pei-ia64.c:coff_set_alignment_hook
Line
Count
Source
1880
221k
{
1881
221k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
221k
  size_t amt;
1883
221k
  unsigned int alignment_power_const
1884
221k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
221k
  switch (alignment_power_const)
1887
221k
    {
1888
9.08k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
9.93k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
14.1k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
16.2k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
19.0k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
20.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
25.9k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
29.6k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
36.3k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
39.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
42.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
49.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
65.2k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
68.5k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
68.5k
      section->alignment_power
1903
68.5k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
68.5k
      break;
1905
153k
    default:
1906
153k
      break;
1907
221k
    }
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
221k
  if (coff_section_data (abfd, section) == NULL)
1914
221k
    {
1915
221k
      amt = sizeof (struct coff_section_tdata);
1916
221k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
221k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
221k
    }
1921
1922
221k
  if (pei_section_data (abfd, section) == NULL)
1923
221k
    {
1924
221k
      amt = sizeof (struct pei_section_tdata);
1925
221k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
221k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
221k
    }
1930
221k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
221k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
221k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
221k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
34.1k
    {
1938
34.1k
      struct external_reloc dst;
1939
34.1k
      struct internal_reloc n;
1940
34.1k
      file_ptr oldpos = bfd_tell (abfd);
1941
34.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
34.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
34.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
18.8k
  return;
1947
1948
15.3k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
15.3k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
15.3k
      if (n.r_vaddr < 0x10000)
1952
5.59k
  {
1953
5.59k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
5.59k
    bfd_set_error (bfd_error_bad_value);
1955
5.59k
    return;
1956
5.59k
  }
1957
9.72k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
9.72k
      section->rel_filepos += relsz;
1959
9.72k
    }
1960
187k
  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
221k
}
pei-loongarch64.c:coff_set_alignment_hook
Line
Count
Source
1880
168k
{
1881
168k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
168k
  size_t amt;
1883
168k
  unsigned int alignment_power_const
1884
168k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
168k
  switch (alignment_power_const)
1887
168k
    {
1888
7.34k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
8.03k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
11.1k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
12.0k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
19.8k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
20.4k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
25.0k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
26.9k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
37.9k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
39.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
42.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
46.0k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
52.4k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
54.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
54.1k
      section->alignment_power
1903
54.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
54.1k
      break;
1905
114k
    default:
1906
114k
      break;
1907
168k
    }
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
168k
  if (coff_section_data (abfd, section) == NULL)
1914
168k
    {
1915
168k
      amt = sizeof (struct coff_section_tdata);
1916
168k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
168k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
168k
    }
1921
1922
168k
  if (pei_section_data (abfd, section) == NULL)
1923
168k
    {
1924
168k
      amt = sizeof (struct pei_section_tdata);
1925
168k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
168k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
168k
    }
1930
168k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
168k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
168k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
168k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
21.4k
    {
1938
21.4k
      struct external_reloc dst;
1939
21.4k
      struct internal_reloc n;
1940
21.4k
      file_ptr oldpos = bfd_tell (abfd);
1941
21.4k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
21.4k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
21.4k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
13.7k
  return;
1947
1948
7.70k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
7.70k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
7.70k
      if (n.r_vaddr < 0x10000)
1952
2.01k
  {
1953
2.01k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
2.01k
    bfd_set_error (bfd_error_bad_value);
1955
2.01k
    return;
1956
2.01k
  }
1957
5.68k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
5.68k
      section->rel_filepos += relsz;
1959
5.68k
    }
1960
147k
  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
168k
}
pe-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
40.6k
{
1881
40.6k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
40.6k
  size_t amt;
1883
40.6k
  unsigned int alignment_power_const
1884
40.6k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
40.6k
  switch (alignment_power_const)
1887
40.6k
    {
1888
1.61k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
1.78k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
1.98k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
3.18k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
5.06k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
5.62k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
6.88k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
7.38k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
8.32k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
11.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
12.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
12.9k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
14.8k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
16.4k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
16.4k
      section->alignment_power
1903
16.4k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
16.4k
      break;
1905
24.2k
    default:
1906
24.2k
      break;
1907
40.6k
    }
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
40.6k
  if (coff_section_data (abfd, section) == NULL)
1914
40.6k
    {
1915
40.6k
      amt = sizeof (struct coff_section_tdata);
1916
40.6k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
40.6k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
40.6k
    }
1921
1922
40.6k
  if (pei_section_data (abfd, section) == NULL)
1923
40.6k
    {
1924
40.6k
      amt = sizeof (struct pei_section_tdata);
1925
40.6k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
40.6k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
40.6k
    }
1930
40.6k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
40.6k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
40.6k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
40.6k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
6.80k
    {
1938
6.80k
      struct external_reloc dst;
1939
6.80k
      struct internal_reloc n;
1940
6.80k
      file_ptr oldpos = bfd_tell (abfd);
1941
6.80k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
6.80k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
6.80k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
4.15k
  return;
1947
1948
2.64k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
2.64k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
2.64k
      if (n.r_vaddr < 0x10000)
1952
424
  {
1953
424
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
424
    bfd_set_error (bfd_error_bad_value);
1955
424
    return;
1956
424
  }
1957
2.21k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
2.21k
      section->rel_filepos += relsz;
1959
2.21k
    }
1960
33.8k
  else if (hdr->s_nreloc == 0xffff)
1961
1.03k
    _bfd_error_handler
1962
1.03k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1.03k
       abfd);
1964
40.6k
}
pe-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
40.6k
{
1881
40.6k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
40.6k
  size_t amt;
1883
40.6k
  unsigned int alignment_power_const
1884
40.6k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
40.6k
  switch (alignment_power_const)
1887
40.6k
    {
1888
1.61k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
1.78k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
1.98k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
3.18k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
5.06k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
5.62k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
6.88k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
7.38k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
8.32k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
11.1k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
12.0k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
12.9k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
14.8k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
16.4k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
16.4k
      section->alignment_power
1903
16.4k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
16.4k
      break;
1905
24.2k
    default:
1906
24.2k
      break;
1907
40.6k
    }
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
40.6k
  if (coff_section_data (abfd, section) == NULL)
1914
40.6k
    {
1915
40.6k
      amt = sizeof (struct coff_section_tdata);
1916
40.6k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
40.6k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
40.6k
    }
1921
1922
40.6k
  if (pei_section_data (abfd, section) == NULL)
1923
40.6k
    {
1924
40.6k
      amt = sizeof (struct pei_section_tdata);
1925
40.6k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
40.6k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
40.6k
    }
1930
40.6k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
40.6k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
40.6k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
40.6k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
6.80k
    {
1938
6.80k
      struct external_reloc dst;
1939
6.80k
      struct internal_reloc n;
1940
6.80k
      file_ptr oldpos = bfd_tell (abfd);
1941
6.80k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
6.80k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
6.80k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
4.15k
  return;
1947
1948
2.64k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
2.64k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
2.64k
      if (n.r_vaddr < 0x10000)
1952
424
  {
1953
424
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
424
    bfd_set_error (bfd_error_bad_value);
1955
424
    return;
1956
424
  }
1957
2.21k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
2.21k
      section->rel_filepos += relsz;
1959
2.21k
    }
1960
33.8k
  else if (hdr->s_nreloc == 0xffff)
1961
1.03k
    _bfd_error_handler
1962
1.03k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1.03k
       abfd);
1964
40.6k
}
pe-i386.c:coff_set_alignment_hook
Line
Count
Source
1880
111k
{
1881
111k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
111k
  size_t amt;
1883
111k
  unsigned int alignment_power_const
1884
111k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
111k
  switch (alignment_power_const)
1887
111k
    {
1888
5.70k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
6.49k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
8.32k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
9.33k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
13.3k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
17.4k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
19.5k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
23.3k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
27.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
29.8k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
32.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
36.1k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
40.8k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
43.3k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
43.3k
      section->alignment_power
1903
43.3k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
43.3k
      break;
1905
68.0k
    default:
1906
68.0k
      break;
1907
111k
    }
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
111k
  if (coff_section_data (abfd, section) == NULL)
1914
111k
    {
1915
111k
      amt = sizeof (struct coff_section_tdata);
1916
111k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
111k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
111k
    }
1921
1922
111k
  if (pei_section_data (abfd, section) == NULL)
1923
111k
    {
1924
111k
      amt = sizeof (struct pei_section_tdata);
1925
111k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
111k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
111k
    }
1930
111k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
111k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
111k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
111k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
25.6k
    {
1938
25.6k
      struct external_reloc dst;
1939
25.6k
      struct internal_reloc n;
1940
25.6k
      file_ptr oldpos = bfd_tell (abfd);
1941
25.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
25.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
25.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
17.9k
  return;
1947
1948
7.77k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
7.77k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
7.77k
      if (n.r_vaddr < 0x10000)
1952
2.29k
  {
1953
2.29k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
2.29k
    bfd_set_error (bfd_error_bad_value);
1955
2.29k
    return;
1956
2.29k
  }
1957
5.47k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
5.47k
      section->rel_filepos += relsz;
1959
5.47k
    }
1960
85.7k
  else if (hdr->s_nreloc == 0xffff)
1961
3.85k
    _bfd_error_handler
1962
3.85k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
3.85k
       abfd);
1964
111k
}
pe-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
806k
{
1881
806k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
806k
  size_t amt;
1883
806k
  unsigned int alignment_power_const
1884
806k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
806k
  switch (alignment_power_const)
1887
806k
    {
1888
9.42k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
9.92k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
11.8k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
12.8k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
15.4k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
16.0k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
18.4k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
19.5k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
21.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
23.0k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
27.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
28.5k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
37.0k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
37.4k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
37.4k
      section->alignment_power
1903
37.4k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
37.4k
      break;
1905
769k
    default:
1906
769k
      break;
1907
806k
    }
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
806k
  if (coff_section_data (abfd, section) == NULL)
1914
806k
    {
1915
806k
      amt = sizeof (struct coff_section_tdata);
1916
806k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
806k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
806k
    }
1921
1922
806k
  if (pei_section_data (abfd, section) == NULL)
1923
806k
    {
1924
806k
      amt = sizeof (struct pei_section_tdata);
1925
806k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
806k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
806k
    }
1930
806k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
806k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
806k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
806k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
17.8k
    {
1938
17.8k
      struct external_reloc dst;
1939
17.8k
      struct internal_reloc n;
1940
17.8k
      file_ptr oldpos = bfd_tell (abfd);
1941
17.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
17.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
17.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
10.8k
  return;
1947
1948
7.04k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
7.04k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
7.04k
      if (n.r_vaddr < 0x10000)
1952
1.73k
  {
1953
1.73k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1.73k
    bfd_set_error (bfd_error_bad_value);
1955
1.73k
    return;
1956
1.73k
  }
1957
5.30k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
5.30k
      section->rel_filepos += relsz;
1959
5.30k
    }
1960
789k
  else if (hdr->s_nreloc == 0xffff)
1961
3.77k
    _bfd_error_handler
1962
3.77k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
3.77k
       abfd);
1964
806k
}
pe-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
95.8k
{
1881
95.8k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
95.8k
  size_t amt;
1883
95.8k
  unsigned int alignment_power_const
1884
95.8k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
95.8k
  switch (alignment_power_const)
1887
95.8k
    {
1888
2.30k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
3.51k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
4.93k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
5.42k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
6.85k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
8.49k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
10.6k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
12.8k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
20.1k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
23.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
25.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
28.3k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
38.5k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
40.1k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
40.1k
      section->alignment_power
1903
40.1k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
40.1k
      break;
1905
55.7k
    default:
1906
55.7k
      break;
1907
95.8k
    }
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
95.8k
  if (coff_section_data (abfd, section) == NULL)
1914
95.8k
    {
1915
95.8k
      amt = sizeof (struct coff_section_tdata);
1916
95.8k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
95.8k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
95.8k
    }
1921
1922
95.8k
  if (pei_section_data (abfd, section) == NULL)
1923
95.8k
    {
1924
95.8k
      amt = sizeof (struct pei_section_tdata);
1925
95.8k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
95.8k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
95.8k
    }
1930
95.8k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
95.8k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
95.8k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
95.8k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
18.1k
    {
1938
18.1k
      struct external_reloc dst;
1939
18.1k
      struct internal_reloc n;
1940
18.1k
      file_ptr oldpos = bfd_tell (abfd);
1941
18.1k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
18.1k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
18.1k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
13.3k
  return;
1947
1948
4.85k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
4.85k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
4.85k
      if (n.r_vaddr < 0x10000)
1952
1.25k
  {
1953
1.25k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
1.25k
    bfd_set_error (bfd_error_bad_value);
1955
1.25k
    return;
1956
1.25k
  }
1957
3.60k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
3.60k
      section->rel_filepos += relsz;
1959
3.60k
    }
1960
77.6k
  else if (hdr->s_nreloc == 0xffff)
1961
1.76k
    _bfd_error_handler
1962
1.76k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
1963
1.76k
       abfd);
1964
95.8k
}
pei-arm-wince.c:coff_set_alignment_hook
Line
Count
Source
1880
196k
{
1881
196k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
196k
  size_t amt;
1883
196k
  unsigned int alignment_power_const
1884
196k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
196k
  switch (alignment_power_const)
1887
196k
    {
1888
5.59k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
8.70k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
14.4k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
16.4k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
28.2k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
31.6k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
35.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
37.1k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
42.4k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
45.2k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
48.1k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
54.4k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
63.0k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
64.3k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
64.3k
      section->alignment_power
1903
64.3k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
64.3k
      break;
1905
132k
    default:
1906
132k
      break;
1907
196k
    }
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
196k
  if (coff_section_data (abfd, section) == NULL)
1914
196k
    {
1915
196k
      amt = sizeof (struct coff_section_tdata);
1916
196k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
196k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
196k
    }
1921
1922
196k
  if (pei_section_data (abfd, section) == NULL)
1923
196k
    {
1924
196k
      amt = sizeof (struct pei_section_tdata);
1925
196k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
196k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
196k
    }
1930
196k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
196k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
196k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
196k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
49.4k
    {
1938
49.4k
      struct external_reloc dst;
1939
49.4k
      struct internal_reloc n;
1940
49.4k
      file_ptr oldpos = bfd_tell (abfd);
1941
49.4k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
49.4k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
49.4k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
27.3k
  return;
1947
1948
22.1k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
22.1k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
22.1k
      if (n.r_vaddr < 0x10000)
1952
4.88k
  {
1953
4.88k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
4.88k
    bfd_set_error (bfd_error_bad_value);
1955
4.88k
    return;
1956
4.88k
  }
1957
17.2k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
17.2k
      section->rel_filepos += relsz;
1959
17.2k
    }
1960
147k
  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
196k
}
pei-arm.c:coff_set_alignment_hook
Line
Count
Source
1880
778k
{
1881
778k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
778k
  size_t amt;
1883
778k
  unsigned int alignment_power_const
1884
778k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
778k
  switch (alignment_power_const)
1887
778k
    {
1888
5.67k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
8.24k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
14.4k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
16.0k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
28.9k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
31.3k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
90.8k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
93.2k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
106k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
110k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
114k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
124k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
134k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
136k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
136k
      section->alignment_power
1903
136k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
136k
      break;
1905
641k
    default:
1906
641k
      break;
1907
778k
    }
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
778k
  if (coff_section_data (abfd, section) == NULL)
1914
778k
    {
1915
778k
      amt = sizeof (struct coff_section_tdata);
1916
778k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
778k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
778k
    }
1921
1922
778k
  if (pei_section_data (abfd, section) == NULL)
1923
778k
    {
1924
778k
      amt = sizeof (struct pei_section_tdata);
1925
778k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
778k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
778k
    }
1930
778k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
778k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
778k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
778k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
47.6k
    {
1938
47.6k
      struct external_reloc dst;
1939
47.6k
      struct internal_reloc n;
1940
47.6k
      file_ptr oldpos = bfd_tell (abfd);
1941
47.6k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
47.6k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
47.6k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
28.3k
  return;
1947
1948
19.3k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
19.3k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
19.3k
      if (n.r_vaddr < 0x10000)
1952
4.96k
  {
1953
4.96k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
4.96k
    bfd_set_error (bfd_error_bad_value);
1955
4.96k
    return;
1956
4.96k
  }
1957
14.4k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
14.4k
      section->rel_filepos += relsz;
1959
14.4k
    }
1960
730k
  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
778k
}
pei-mcore.c:coff_set_alignment_hook
Line
Count
Source
1880
209k
{
1881
209k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
209k
  size_t amt;
1883
209k
  unsigned int alignment_power_const
1884
209k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
209k
  switch (alignment_power_const)
1887
209k
    {
1888
5.79k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
9.16k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
11.9k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
12.8k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
17.4k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
17.9k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
23.1k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
25.7k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
31.6k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
35.3k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
38.3k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
41.6k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
54.3k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
56.6k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
56.6k
      section->alignment_power
1903
56.6k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
56.6k
      break;
1905
152k
    default:
1906
152k
      break;
1907
209k
    }
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
209k
  if (coff_section_data (abfd, section) == NULL)
1914
209k
    {
1915
209k
      amt = sizeof (struct coff_section_tdata);
1916
209k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
209k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
209k
    }
1921
1922
209k
  if (pei_section_data (abfd, section) == NULL)
1923
209k
    {
1924
209k
      amt = sizeof (struct pei_section_tdata);
1925
209k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
209k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
209k
    }
1930
209k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
209k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
209k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
209k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
31.0k
    {
1938
31.0k
      struct external_reloc dst;
1939
31.0k
      struct internal_reloc n;
1940
31.0k
      file_ptr oldpos = bfd_tell (abfd);
1941
31.0k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
31.0k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
31.0k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
17.3k
  return;
1947
1948
13.7k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
13.7k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
13.7k
      if (n.r_vaddr < 0x10000)
1952
4.89k
  {
1953
4.89k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
4.89k
    bfd_set_error (bfd_error_bad_value);
1955
4.89k
    return;
1956
4.89k
  }
1957
8.83k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
8.83k
      section->rel_filepos += relsz;
1959
8.83k
    }
1960
178k
  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
209k
}
pei-sh.c:coff_set_alignment_hook
Line
Count
Source
1880
226k
{
1881
226k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1882
226k
  size_t amt;
1883
226k
  unsigned int alignment_power_const
1884
226k
    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
1885
1886
226k
  switch (alignment_power_const)
1887
226k
    {
1888
8.76k
    case IMAGE_SCN_ALIGN_8192BYTES:
1889
9.47k
    case IMAGE_SCN_ALIGN_4096BYTES:
1890
12.6k
    case IMAGE_SCN_ALIGN_2048BYTES:
1891
13.1k
    case IMAGE_SCN_ALIGN_1024BYTES:
1892
18.6k
    case IMAGE_SCN_ALIGN_512BYTES:
1893
19.5k
    case IMAGE_SCN_ALIGN_256BYTES:
1894
21.7k
    case IMAGE_SCN_ALIGN_128BYTES:
1895
24.4k
    case IMAGE_SCN_ALIGN_64BYTES:
1896
33.5k
    case IMAGE_SCN_ALIGN_32BYTES:
1897
36.7k
    case IMAGE_SCN_ALIGN_16BYTES:
1898
41.8k
    case IMAGE_SCN_ALIGN_8BYTES:
1899
45.7k
    case IMAGE_SCN_ALIGN_4BYTES:
1900
57.0k
    case IMAGE_SCN_ALIGN_2BYTES:
1901
60.3k
    case IMAGE_SCN_ALIGN_1BYTES:
1902
60.3k
      section->alignment_power
1903
60.3k
  = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
1904
60.3k
      break;
1905
165k
    default:
1906
165k
      break;
1907
226k
    }
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
226k
  if (coff_section_data (abfd, section) == NULL)
1914
226k
    {
1915
226k
      amt = sizeof (struct coff_section_tdata);
1916
226k
      section->used_by_bfd = bfd_zalloc (abfd, amt);
1917
226k
      if (section->used_by_bfd == NULL)
1918
  /* FIXME: Return error.  */
1919
0
  abort ();
1920
226k
    }
1921
1922
226k
  if (pei_section_data (abfd, section) == NULL)
1923
226k
    {
1924
226k
      amt = sizeof (struct pei_section_tdata);
1925
226k
      coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
1926
226k
      if (coff_section_data (abfd, section)->tdata == NULL)
1927
  /* FIXME: Return error.  */
1928
0
  abort ();
1929
226k
    }
1930
226k
  pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
1931
226k
  pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
1932
1933
226k
  section->lma = hdr->s_vaddr;
1934
1935
  /* Check for extended relocs.  */
1936
226k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
1937
29.8k
    {
1938
29.8k
      struct external_reloc dst;
1939
29.8k
      struct internal_reloc n;
1940
29.8k
      file_ptr oldpos = bfd_tell (abfd);
1941
29.8k
      bfd_size_type relsz = bfd_coff_relsz (abfd);
1942
1943
29.8k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
1944
0
  return;
1945
29.8k
      if (bfd_read (& dst, relsz, abfd) != relsz)
1946
15.4k
  return;
1947
1948
14.3k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
1949
14.3k
      if (bfd_seek (abfd, oldpos, 0) != 0)
1950
0
  return;
1951
14.3k
      if (n.r_vaddr < 0x10000)
1952
6.79k
  {
1953
6.79k
    _bfd_error_handler (_("%pB: overflow reloc count too small"), abfd);
1954
6.79k
    bfd_set_error (bfd_error_bad_value);
1955
6.79k
    return;
1956
6.79k
  }
1957
7.52k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
1958
7.52k
      section->rel_filepos += relsz;
1959
7.52k
    }
1960
196k
  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
226k
}
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
30.1M
{
1978
30.1M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
30.1M
  asection *real_sec;
1980
1981
30.1M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
24.2M
    return;
1983
1984
5.95M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
5.95M
  if (real_sec == NULL)
1986
0
    return;
1987
1988
5.95M
  real_sec->reloc_count = hdr->s_paddr;
1989
5.95M
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
5.95M
  if (!bfd_section_removed_from_list (abfd, section))
1992
5.95M
    {
1993
5.95M
      bfd_section_list_remove (abfd, section);
1994
5.95M
      --abfd->section_count;
1995
5.95M
    }
1996
5.95M
}
coff64-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
4.62M
{
1978
4.62M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
4.62M
  asection *real_sec;
1980
1981
4.62M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
3.80M
    return;
1983
1984
816k
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
816k
  if (real_sec == NULL)
1986
0
    return;
1987
1988
816k
  real_sec->reloc_count = hdr->s_paddr;
1989
816k
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
816k
  if (!bfd_section_removed_from_list (abfd, section))
1992
816k
    {
1993
816k
      bfd_section_list_remove (abfd, section);
1994
816k
      --abfd->section_count;
1995
816k
    }
1996
816k
}
coff-rs6000.c:coff_set_alignment_hook
Line
Count
Source
1977
25.5M
{
1978
25.5M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
1979
25.5M
  asection *real_sec;
1980
1981
25.5M
  if ((hdr->s_flags & STYP_OVRFLO) == 0)
1982
20.4M
    return;
1983
1984
5.13M
  real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
1985
5.13M
  if (real_sec == NULL)
1986
0
    return;
1987
1988
5.13M
  real_sec->reloc_count = hdr->s_paddr;
1989
5.13M
  real_sec->lineno_count = hdr->s_vaddr;
1990
1991
5.13M
  if (!bfd_section_removed_from_list (abfd, section))
1992
5.13M
    {
1993
5.13M
      bfd_section_list_remove (abfd, section);
1994
5.13M
      --abfd->section_count;
1995
5.13M
    }
1996
5.13M
}
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
5.32M
{
2004
5.32M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
5.32M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
1.60M
    {
2009
1.60M
      struct external_reloc dst;
2010
1.60M
      struct internal_reloc n;
2011
1.60M
      const file_ptr oldpos = bfd_tell (abfd);
2012
1.60M
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
1.60M
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
1.60M
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
1.33M
  return;
2018
2019
268k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
268k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
268k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
268k
      section->rel_filepos += relsz;
2024
268k
    }
2025
3.71M
  else if (hdr->s_nreloc == 0xffff)
2026
85.7k
    _bfd_error_handler
2027
85.7k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
85.7k
       abfd);
2029
5.32M
}
coff-go32.c:coff_set_alignment_hook
Line
Count
Source
2003
4.96M
{
2004
4.96M
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
4.96M
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
1.49M
    {
2009
1.49M
      struct external_reloc dst;
2010
1.49M
      struct internal_reloc n;
2011
1.49M
      const file_ptr oldpos = bfd_tell (abfd);
2012
1.49M
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
1.49M
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
1.49M
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
1.24M
  return;
2018
2019
250k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
250k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
250k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
250k
      section->rel_filepos += relsz;
2024
250k
    }
2025
3.46M
  else if (hdr->s_nreloc == 0xffff)
2026
78.2k
    _bfd_error_handler
2027
78.2k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
78.2k
       abfd);
2029
4.96M
}
coff-stgo32.c:coff_set_alignment_hook
Line
Count
Source
2003
358k
{
2004
358k
  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
2005
2006
  /* Check for extended relocs.  */
2007
358k
  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
2008
104k
    {
2009
104k
      struct external_reloc dst;
2010
104k
      struct internal_reloc n;
2011
104k
      const file_ptr oldpos = bfd_tell (abfd);
2012
104k
      const bfd_size_type relsz = bfd_coff_relsz (abfd);
2013
2014
104k
      if (bfd_seek (abfd, hdr->s_relptr, 0) != 0)
2015
0
  return;
2016
104k
      if (bfd_read (& dst, relsz, abfd) != relsz)
2017
86.3k
  return;
2018
2019
18.2k
      bfd_coff_swap_reloc_in (abfd, &dst, &n);
2020
18.2k
      if (bfd_seek (abfd, oldpos, 0) != 0)
2021
0
  return;
2022
18.2k
      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
2023
18.2k
      section->rel_filepos += relsz;
2024
18.2k
    }
2025
254k
  else if (hdr->s_nreloc == 0xffff)
2026
7.50k
    _bfd_error_handler
2027
7.50k
      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
2028
7.50k
       abfd);
2029
358k
}
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
48.0M
{
2038
48.0M
}
coff-x86_64.c:coff_set_alignment_hook
Line
Count
Source
2037
9.32M
{
2038
9.32M
}
cf-i386lynx.c:coff_set_alignment_hook
Line
Count
Source
2037
6.05M
{
2038
6.05M
}
coff-i386.c:coff_set_alignment_hook
Line
Count
Source
2037
5.72M
{
2038
5.72M
}
coff-sh.c:coff_set_alignment_hook
Line
Count
Source
2037
12.2M
{
2038
12.2M
}
coff-tic30.c:coff_set_alignment_hook
Line
Count
Source
2037
5.80M
{
2038
5.80M
}
coff-z8k.c:coff_set_alignment_hook
Line
Count
Source
2037
8.88M
{
2038
8.88M
}
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
310k
{
2050
310k
  coff_data_type *coff;
2051
310k
  size_t amt = sizeof (coff_data_type);
2052
2053
310k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
310k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
310k
  coff = coff_data (abfd);
2058
310k
  coff->symbols = NULL;
2059
310k
  coff->conversion_table = NULL;
2060
310k
  coff->raw_syments = NULL;
2061
310k
  coff->relocbase = 0;
2062
310k
  coff->local_toc_sym_map = 0;
2063
2064
310k
  bfd_coff_long_section_names (abfd)
2065
310k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
310k
  return true;
2070
310k
}
coff-x86_64.c:coff_mkobject
Line
Count
Source
2049
73.5k
{
2050
73.5k
  coff_data_type *coff;
2051
73.5k
  size_t amt = sizeof (coff_data_type);
2052
2053
73.5k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
73.5k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
73.5k
  coff = coff_data (abfd);
2058
73.5k
  coff->symbols = NULL;
2059
73.5k
  coff->conversion_table = NULL;
2060
73.5k
  coff->raw_syments = NULL;
2061
73.5k
  coff->relocbase = 0;
2062
73.5k
  coff->local_toc_sym_map = 0;
2063
2064
73.5k
  bfd_coff_long_section_names (abfd)
2065
73.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
73.5k
  return true;
2070
73.5k
}
cf-i386lynx.c:coff_mkobject
Line
Count
Source
2049
34.6k
{
2050
34.6k
  coff_data_type *coff;
2051
34.6k
  size_t amt = sizeof (coff_data_type);
2052
2053
34.6k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
34.6k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
34.6k
  coff = coff_data (abfd);
2058
34.6k
  coff->symbols = NULL;
2059
34.6k
  coff->conversion_table = NULL;
2060
34.6k
  coff->raw_syments = NULL;
2061
34.6k
  coff->relocbase = 0;
2062
34.6k
  coff->local_toc_sym_map = 0;
2063
2064
34.6k
  bfd_coff_long_section_names (abfd)
2065
34.6k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
34.6k
  return true;
2070
34.6k
}
coff-i386.c:coff_mkobject
Line
Count
Source
2049
32.3k
{
2050
32.3k
  coff_data_type *coff;
2051
32.3k
  size_t amt = sizeof (coff_data_type);
2052
2053
32.3k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
32.3k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
32.3k
  coff = coff_data (abfd);
2058
32.3k
  coff->symbols = NULL;
2059
32.3k
  coff->conversion_table = NULL;
2060
32.3k
  coff->raw_syments = NULL;
2061
32.3k
  coff->relocbase = 0;
2062
32.3k
  coff->local_toc_sym_map = 0;
2063
2064
32.3k
  bfd_coff_long_section_names (abfd)
2065
32.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
32.3k
  return true;
2070
32.3k
}
coff-sh.c:coff_mkobject
Line
Count
Source
2049
49.2k
{
2050
49.2k
  coff_data_type *coff;
2051
49.2k
  size_t amt = sizeof (coff_data_type);
2052
2053
49.2k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
49.2k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
49.2k
  coff = coff_data (abfd);
2058
49.2k
  coff->symbols = NULL;
2059
49.2k
  coff->conversion_table = NULL;
2060
49.2k
  coff->raw_syments = NULL;
2061
49.2k
  coff->relocbase = 0;
2062
49.2k
  coff->local_toc_sym_map = 0;
2063
2064
49.2k
  bfd_coff_long_section_names (abfd)
2065
49.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
49.2k
  return true;
2070
49.2k
}
coff-tic30.c:coff_mkobject
Line
Count
Source
2049
27.2k
{
2050
27.2k
  coff_data_type *coff;
2051
27.2k
  size_t amt = sizeof (coff_data_type);
2052
2053
27.2k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
27.2k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
27.2k
  coff = coff_data (abfd);
2058
27.2k
  coff->symbols = NULL;
2059
27.2k
  coff->conversion_table = NULL;
2060
27.2k
  coff->raw_syments = NULL;
2061
27.2k
  coff->relocbase = 0;
2062
27.2k
  coff->local_toc_sym_map = 0;
2063
2064
27.2k
  bfd_coff_long_section_names (abfd)
2065
27.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
27.2k
  return true;
2070
27.2k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject
coff-tic54x.c:coff_mkobject
Line
Count
Source
2049
46.9k
{
2050
46.9k
  coff_data_type *coff;
2051
46.9k
  size_t amt = sizeof (coff_data_type);
2052
2053
46.9k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
46.9k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
46.9k
  coff = coff_data (abfd);
2058
46.9k
  coff->symbols = NULL;
2059
46.9k
  coff->conversion_table = NULL;
2060
46.9k
  coff->raw_syments = NULL;
2061
46.9k
  coff->relocbase = 0;
2062
46.9k
  coff->local_toc_sym_map = 0;
2063
2064
46.9k
  bfd_coff_long_section_names (abfd)
2065
46.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
46.9k
  return true;
2070
46.9k
}
coff-z80.c:coff_mkobject
Line
Count
Source
2049
22.0k
{
2050
22.0k
  coff_data_type *coff;
2051
22.0k
  size_t amt = sizeof (coff_data_type);
2052
2053
22.0k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
22.0k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
22.0k
  coff = coff_data (abfd);
2058
22.0k
  coff->symbols = NULL;
2059
22.0k
  coff->conversion_table = NULL;
2060
22.0k
  coff->raw_syments = NULL;
2061
22.0k
  coff->relocbase = 0;
2062
22.0k
  coff->local_toc_sym_map = 0;
2063
2064
22.0k
  bfd_coff_long_section_names (abfd)
2065
22.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
22.0k
  return true;
2070
22.0k
}
coff-z8k.c:coff_mkobject
Line
Count
Source
2049
24.6k
{
2050
24.6k
  coff_data_type *coff;
2051
24.6k
  size_t amt = sizeof (coff_data_type);
2052
2053
24.6k
  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
2054
24.6k
  if (abfd->tdata.coff_obj_data == NULL)
2055
0
    return false;
2056
2057
24.6k
  coff = coff_data (abfd);
2058
24.6k
  coff->symbols = NULL;
2059
24.6k
  coff->conversion_table = NULL;
2060
24.6k
  coff->raw_syments = NULL;
2061
24.6k
  coff->relocbase = 0;
2062
24.6k
  coff->local_toc_sym_map = 0;
2063
2064
24.6k
  bfd_coff_long_section_names (abfd)
2065
24.6k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
2066
2067
/*  make_abs_section(abfd);*/
2068
2069
24.6k
  return true;
2070
24.6k
}
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
452k
{
2081
452k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
452k
  coff_data_type *coff;
2083
2084
452k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
452k
  coff = coff_data (abfd);
2088
2089
452k
  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
452k
  coff->local_n_btmask = N_BTMASK;
2095
452k
  coff->local_n_btshft = N_BTSHFT;
2096
452k
  coff->local_n_tmask = N_TMASK;
2097
452k
  coff->local_n_tshift = N_TSHIFT;
2098
452k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
452k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
452k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
452k
  coff->timestamp = internal_f->f_timdat;
2103
2104
452k
  obj_raw_syment_count (abfd) =
2105
452k
    obj_conv_table_size (abfd) =
2106
452k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
106k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
50.6k
    abfd->flags |= DYNAMIC;
2111
106k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
29.9k
    {
2113
29.9k
      struct internal_aouthdr *internal_a =
2114
29.9k
  (struct internal_aouthdr *) aouthdr;
2115
29.9k
      struct xcoff_tdata *xcoff;
2116
2117
29.9k
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
19.7k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
29.9k
      xcoff->full_aouthdr = true;
2124
29.9k
      xcoff->toc = internal_a->o_toc;
2125
29.9k
      xcoff->sntoc = internal_a->o_sntoc;
2126
29.9k
      xcoff->snentry = internal_a->o_snentry;
2127
29.9k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
29.9k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
29.9k
      xcoff->modtype = internal_a->o_modtype;
2130
29.9k
      xcoff->cputype = internal_a->o_cputype;
2131
29.9k
      xcoff->maxdata = internal_a->o_maxdata;
2132
29.9k
      xcoff->maxstack = internal_a->o_maxstack;
2133
29.9k
    }
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
452k
  return coff;
2150
452k
}
coff-x86_64.c:coff_mkobject_hook
Line
Count
Source
2080
73.4k
{
2081
73.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
73.4k
  coff_data_type *coff;
2083
2084
73.4k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
73.4k
  coff = coff_data (abfd);
2088
2089
73.4k
  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
73.4k
  coff->local_n_btmask = N_BTMASK;
2095
73.4k
  coff->local_n_btshft = N_BTSHFT;
2096
73.4k
  coff->local_n_tmask = N_TMASK;
2097
73.4k
  coff->local_n_tshift = N_TSHIFT;
2098
73.4k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
73.4k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
73.4k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
73.4k
  coff->timestamp = internal_f->f_timdat;
2103
2104
73.4k
  obj_raw_syment_count (abfd) =
2105
73.4k
    obj_conv_table_size (abfd) =
2106
73.4k
      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
73.4k
  return coff;
2150
73.4k
}
coff64-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
54.5k
{
2081
54.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
54.5k
  coff_data_type *coff;
2083
2084
54.5k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
54.5k
  coff = coff_data (abfd);
2088
2089
54.5k
  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
54.5k
  coff->local_n_btmask = N_BTMASK;
2095
54.5k
  coff->local_n_btshft = N_BTSHFT;
2096
54.5k
  coff->local_n_tmask = N_TMASK;
2097
54.5k
  coff->local_n_tshift = N_TSHIFT;
2098
54.5k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
54.5k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
54.5k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
54.5k
  coff->timestamp = internal_f->f_timdat;
2103
2104
54.5k
  obj_raw_syment_count (abfd) =
2105
54.5k
    obj_conv_table_size (abfd) =
2106
54.5k
      internal_f->f_nsyms;
2107
2108
54.5k
#ifdef RS6000COFF_C
2109
54.5k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
24.0k
    abfd->flags |= DYNAMIC;
2111
54.5k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
19.7k
    {
2113
19.7k
      struct internal_aouthdr *internal_a =
2114
19.7k
  (struct internal_aouthdr *) aouthdr;
2115
19.7k
      struct xcoff_tdata *xcoff;
2116
2117
19.7k
      xcoff = xcoff_data (abfd);
2118
19.7k
# ifdef U803XTOCMAGIC
2119
19.7k
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
19.7k
      xcoff->full_aouthdr = true;
2124
19.7k
      xcoff->toc = internal_a->o_toc;
2125
19.7k
      xcoff->sntoc = internal_a->o_sntoc;
2126
19.7k
      xcoff->snentry = internal_a->o_snentry;
2127
19.7k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
19.7k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
19.7k
      xcoff->modtype = internal_a->o_modtype;
2130
19.7k
      xcoff->cputype = internal_a->o_cputype;
2131
19.7k
      xcoff->maxdata = internal_a->o_maxdata;
2132
19.7k
      xcoff->maxstack = internal_a->o_maxstack;
2133
19.7k
    }
2134
54.5k
#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
54.5k
  return coff;
2150
54.5k
}
cf-i386lynx.c:coff_mkobject_hook
Line
Count
Source
2080
34.6k
{
2081
34.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
34.6k
  coff_data_type *coff;
2083
2084
34.6k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
34.6k
  coff = coff_data (abfd);
2088
2089
34.6k
  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
34.6k
  coff->local_n_btmask = N_BTMASK;
2095
34.6k
  coff->local_n_btshft = N_BTSHFT;
2096
34.6k
  coff->local_n_tmask = N_TMASK;
2097
34.6k
  coff->local_n_tshift = N_TSHIFT;
2098
34.6k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
34.6k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
34.6k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
34.6k
  coff->timestamp = internal_f->f_timdat;
2103
2104
34.6k
  obj_raw_syment_count (abfd) =
2105
34.6k
    obj_conv_table_size (abfd) =
2106
34.6k
      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
34.6k
  return coff;
2150
34.6k
}
coff-go32.c:coff_mkobject_hook
Line
Count
Source
2080
32.3k
{
2081
32.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
32.3k
  coff_data_type *coff;
2083
2084
32.3k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
32.3k
  coff = coff_data (abfd);
2088
2089
32.3k
  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
32.3k
  coff->local_n_btmask = N_BTMASK;
2095
32.3k
  coff->local_n_btshft = N_BTSHFT;
2096
32.3k
  coff->local_n_tmask = N_TMASK;
2097
32.3k
  coff->local_n_tshift = N_TSHIFT;
2098
32.3k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
32.3k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
32.3k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
32.3k
  coff->timestamp = internal_f->f_timdat;
2103
2104
32.3k
  obj_raw_syment_count (abfd) =
2105
32.3k
    obj_conv_table_size (abfd) =
2106
32.3k
      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
32.3k
  return coff;
2150
32.3k
}
coff-i386.c:coff_mkobject_hook
Line
Count
Source
2080
32.3k
{
2081
32.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
32.3k
  coff_data_type *coff;
2083
2084
32.3k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
32.3k
  coff = coff_data (abfd);
2088
2089
32.3k
  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
32.3k
  coff->local_n_btmask = N_BTMASK;
2095
32.3k
  coff->local_n_btshft = N_BTSHFT;
2096
32.3k
  coff->local_n_tmask = N_TMASK;
2097
32.3k
  coff->local_n_tshift = N_TSHIFT;
2098
32.3k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
32.3k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
32.3k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
32.3k
  coff->timestamp = internal_f->f_timdat;
2103
2104
32.3k
  obj_raw_syment_count (abfd) =
2105
32.3k
    obj_conv_table_size (abfd) =
2106
32.3k
      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
32.3k
  return coff;
2150
32.3k
}
coff-rs6000.c:coff_mkobject_hook
Line
Count
Source
2080
52.4k
{
2081
52.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
52.4k
  coff_data_type *coff;
2083
2084
52.4k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
52.4k
  coff = coff_data (abfd);
2088
2089
52.4k
  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
52.4k
  coff->local_n_btmask = N_BTMASK;
2095
52.4k
  coff->local_n_btshft = N_BTSHFT;
2096
52.4k
  coff->local_n_tmask = N_TMASK;
2097
52.4k
  coff->local_n_tshift = N_TSHIFT;
2098
52.4k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
52.4k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
52.4k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
52.4k
  coff->timestamp = internal_f->f_timdat;
2103
2104
52.4k
  obj_raw_syment_count (abfd) =
2105
52.4k
    obj_conv_table_size (abfd) =
2106
52.4k
      internal_f->f_nsyms;
2107
2108
52.4k
#ifdef RS6000COFF_C
2109
52.4k
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
26.5k
    abfd->flags |= DYNAMIC;
2111
52.4k
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
10.1k
    {
2113
10.1k
      struct internal_aouthdr *internal_a =
2114
10.1k
  (struct internal_aouthdr *) aouthdr;
2115
10.1k
      struct xcoff_tdata *xcoff;
2116
2117
10.1k
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
10.1k
      xcoff->xcoff64 = 0;
2122
10.1k
# endif
2123
10.1k
      xcoff->full_aouthdr = true;
2124
10.1k
      xcoff->toc = internal_a->o_toc;
2125
10.1k
      xcoff->sntoc = internal_a->o_sntoc;
2126
10.1k
      xcoff->snentry = internal_a->o_snentry;
2127
10.1k
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
10.1k
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
10.1k
      xcoff->modtype = internal_a->o_modtype;
2130
10.1k
      xcoff->cputype = internal_a->o_cputype;
2131
10.1k
      xcoff->maxdata = internal_a->o_maxdata;
2132
10.1k
      xcoff->maxstack = internal_a->o_maxstack;
2133
10.1k
    }
2134
52.4k
#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
52.4k
  return coff;
2150
52.4k
}
coff-sh.c:coff_mkobject_hook
Line
Count
Source
2080
49.0k
{
2081
49.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
49.0k
  coff_data_type *coff;
2083
2084
49.0k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
49.0k
  coff = coff_data (abfd);
2088
2089
49.0k
  coff->sym_filepos = internal_f->f_symptr;
2090
2091
  /* These members communicate important constants about the symbol
2092
     table to GDB's symbol-reading code.  These `constants'
2093
     unfortunately vary among coff implementations...  */
2094
49.0k
  coff->local_n_btmask = N_BTMASK;
2095
49.0k
  coff->local_n_btshft = N_BTSHFT;
2096
49.0k
  coff->local_n_tmask = N_TMASK;
2097
49.0k
  coff->local_n_tshift = N_TSHIFT;
2098
49.0k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
49.0k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
49.0k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
49.0k
  coff->timestamp = internal_f->f_timdat;
2103
2104
49.0k
  obj_raw_syment_count (abfd) =
2105
49.0k
    obj_conv_table_size (abfd) =
2106
49.0k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
49.0k
  return coff;
2150
49.0k
}
coff-stgo32.c:coff_mkobject_hook
Line
Count
Source
2080
2.54k
{
2081
2.54k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
2.54k
  coff_data_type *coff;
2083
2084
2.54k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
2.54k
  coff = coff_data (abfd);
2088
2089
2.54k
  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.54k
  coff->local_n_btmask = N_BTMASK;
2095
2.54k
  coff->local_n_btshft = N_BTSHFT;
2096
2.54k
  coff->local_n_tmask = N_TMASK;
2097
2.54k
  coff->local_n_tshift = N_TSHIFT;
2098
2.54k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
2.54k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
2.54k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
2.54k
  coff->timestamp = internal_f->f_timdat;
2103
2104
2.54k
  obj_raw_syment_count (abfd) =
2105
2.54k
    obj_conv_table_size (abfd) =
2106
2.54k
      internal_f->f_nsyms;
2107
2108
#ifdef RS6000COFF_C
2109
  if ((internal_f->f_flags & F_SHROBJ) != 0)
2110
    abfd->flags |= DYNAMIC;
2111
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
2112
    {
2113
      struct internal_aouthdr *internal_a =
2114
  (struct internal_aouthdr *) aouthdr;
2115
      struct xcoff_tdata *xcoff;
2116
2117
      xcoff = xcoff_data (abfd);
2118
# ifdef U803XTOCMAGIC
2119
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
2120
# else
2121
      xcoff->xcoff64 = 0;
2122
# endif
2123
      xcoff->full_aouthdr = true;
2124
      xcoff->toc = internal_a->o_toc;
2125
      xcoff->sntoc = internal_a->o_sntoc;
2126
      xcoff->snentry = internal_a->o_snentry;
2127
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
2128
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
2129
      xcoff->modtype = internal_a->o_modtype;
2130
      xcoff->cputype = internal_a->o_cputype;
2131
      xcoff->maxdata = internal_a->o_maxdata;
2132
      xcoff->maxstack = internal_a->o_maxstack;
2133
    }
2134
#endif
2135
2136
#ifdef ARM
2137
  /* Set the flags field from the COFF header read in.  */
2138
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
2139
    coff->flags = 0;
2140
#endif
2141
2142
#ifdef COFF_WITH_PE
2143
  /* FIXME: I'm not sure this is ever executed, since peicode.h
2144
     defines coff_mkobject_hook.  */
2145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
2146
    abfd->flags |= HAS_DEBUG;
2147
#endif
2148
2149
2.54k
  return coff;
2150
2.54k
}
coff-tic30.c:coff_mkobject_hook
Line
Count
Source
2080
27.2k
{
2081
27.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
27.2k
  coff_data_type *coff;
2083
2084
27.2k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
27.2k
  coff = coff_data (abfd);
2088
2089
27.2k
  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
27.2k
  coff->local_n_btmask = N_BTMASK;
2095
27.2k
  coff->local_n_btshft = N_BTSHFT;
2096
27.2k
  coff->local_n_tmask = N_TMASK;
2097
27.2k
  coff->local_n_tshift = N_TSHIFT;
2098
27.2k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
27.2k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
27.2k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
27.2k
  coff->timestamp = internal_f->f_timdat;
2103
2104
27.2k
  obj_raw_syment_count (abfd) =
2105
27.2k
    obj_conv_table_size (abfd) =
2106
27.2k
      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
27.2k
  return coff;
2150
27.2k
}
Unexecuted instantiation: coff-tic4x.c:coff_mkobject_hook
coff-tic54x.c:coff_mkobject_hook
Line
Count
Source
2080
46.8k
{
2081
46.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
46.8k
  coff_data_type *coff;
2083
2084
46.8k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
46.8k
  coff = coff_data (abfd);
2088
2089
46.8k
  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
46.8k
  coff->local_n_btmask = N_BTMASK;
2095
46.8k
  coff->local_n_btshft = N_BTSHFT;
2096
46.8k
  coff->local_n_tmask = N_TMASK;
2097
46.8k
  coff->local_n_tshift = N_TSHIFT;
2098
46.8k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
46.8k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
46.8k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
46.8k
  coff->timestamp = internal_f->f_timdat;
2103
2104
46.8k
  obj_raw_syment_count (abfd) =
2105
46.8k
    obj_conv_table_size (abfd) =
2106
46.8k
      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
46.8k
  return coff;
2150
46.8k
}
coff-z80.c:coff_mkobject_hook
Line
Count
Source
2080
21.9k
{
2081
21.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
21.9k
  coff_data_type *coff;
2083
2084
21.9k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
21.9k
  coff = coff_data (abfd);
2088
2089
21.9k
  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
21.9k
  coff->local_n_btmask = N_BTMASK;
2095
21.9k
  coff->local_n_btshft = N_BTSHFT;
2096
21.9k
  coff->local_n_tmask = N_TMASK;
2097
21.9k
  coff->local_n_tshift = N_TSHIFT;
2098
21.9k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
21.9k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
21.9k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
21.9k
  coff->timestamp = internal_f->f_timdat;
2103
2104
21.9k
  obj_raw_syment_count (abfd) =
2105
21.9k
    obj_conv_table_size (abfd) =
2106
21.9k
      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
21.9k
  return coff;
2150
21.9k
}
coff-z8k.c:coff_mkobject_hook
Line
Count
Source
2080
24.6k
{
2081
24.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2082
24.6k
  coff_data_type *coff;
2083
2084
24.6k
  if (! coff_mkobject (abfd))
2085
0
    return NULL;
2086
2087
24.6k
  coff = coff_data (abfd);
2088
2089
24.6k
  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
24.6k
  coff->local_n_btmask = N_BTMASK;
2095
24.6k
  coff->local_n_btshft = N_BTSHFT;
2096
24.6k
  coff->local_n_tmask = N_TMASK;
2097
24.6k
  coff->local_n_tshift = N_TSHIFT;
2098
24.6k
  coff->local_symesz = bfd_coff_symesz (abfd);
2099
24.6k
  coff->local_auxesz = bfd_coff_auxesz (abfd);
2100
24.6k
  coff->local_linesz = bfd_coff_linesz (abfd);
2101
2102
24.6k
  coff->timestamp = internal_f->f_timdat;
2103
2104
24.6k
  obj_raw_syment_count (abfd) =
2105
24.6k
    obj_conv_table_size (abfd) =
2106
24.6k
      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
24.6k
  return coff;
2150
24.6k
}
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
1.26M
{
2163
1.26M
  unsigned long machine;
2164
1.26M
  enum bfd_architecture arch;
2165
1.26M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
1.26M
  machine = 0;
2169
1.26M
  switch (internal_f->f_magic)
2170
1.26M
    {
2171
#ifdef I386MAGIC
2172
111k
    case I386MAGIC:
2173
115k
    case I386PTXMAGIC:
2174
121k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
194k
    case LYNXCOFFMAGIC:
2176
198k
    case I386_APPLE_MAGIC:
2177
198k
    case I386_FREEBSD_MAGIC:
2178
198k
    case I386_LINUX_MAGIC:
2179
200k
    case I386_NETBSD_MAGIC:
2180
200k
      arch = bfd_arch_i386;
2181
200k
      break;
2182
0
#endif
2183
#ifdef AMD64MAGIC
2184
10.8k
    case AMD64MAGIC:
2185
209k
    case AMD64_APPLE_MAGIC:
2186
209k
    case AMD64_FREEBSD_MAGIC:
2187
241k
    case AMD64_LINUX_MAGIC:
2188
243k
    case AMD64_NETBSD_MAGIC:
2189
243k
      arch = bfd_arch_i386;
2190
243k
      machine = bfd_mach_x86_64;
2191
243k
      break;
2192
0
#endif
2193
#ifdef IA64MAGIC
2194
68.2k
    case IA64MAGIC:
2195
68.2k
      arch = bfd_arch_ia64;
2196
68.2k
      break;
2197
0
#endif
2198
#ifdef ARMMAGIC
2199
111k
    case ARMMAGIC:
2200
118k
    case ARMPEMAGIC:
2201
154k
    case THUMBPEMAGIC:
2202
154k
      arch = bfd_arch_arm;
2203
154k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
154k
      if (machine == bfd_mach_arm_unknown)
2205
154k
  {
2206
154k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
154k
      {
2208
8.53k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
7.93k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
5.53k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
88.4k
      default:
2212
91.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
11.2k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
13.5k
      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
15.6k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
154k
      }
2222
154k
  }
2223
154k
      break;
2224
154k
#endif
2225
#ifdef AARCH64MAGIC
2226
87.5k
    case AARCH64MAGIC:
2227
87.5k
      arch = bfd_arch_aarch64;
2228
87.5k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
87.5k
      break;
2230
0
#endif
2231
#ifdef LOONGARCH64MAGIC
2232
48.6k
    case LOONGARCH64MAGIC:
2233
48.6k
      arch = bfd_arch_loongarch;
2234
48.6k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
48.6k
      break;
2236
0
#endif
2237
#ifdef Z80MAGIC
2238
21.6k
    case Z80MAGIC:
2239
21.6k
      arch = bfd_arch_z80;
2240
21.6k
      switch (internal_f->f_flags & F_MACHMASK)
2241
21.6k
  {
2242
685
  case bfd_mach_z80strict << 12:
2243
3.86k
  case bfd_mach_z80 << 12:
2244
6.11k
  case bfd_mach_z80n << 12:
2245
8.58k
  case bfd_mach_z80full << 12:
2246
12.2k
  case bfd_mach_r800 << 12:
2247
14.0k
  case bfd_mach_gbz80 << 12:
2248
17.4k
  case bfd_mach_z180 << 12:
2249
18.4k
  case bfd_mach_ez80_z80 << 12:
2250
21.3k
  case bfd_mach_ez80_adl << 12:
2251
21.3k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
21.3k
    break;
2253
318
  default:
2254
318
    return false;
2255
21.6k
  }
2256
21.3k
      break;
2257
21.3k
#endif
2258
#ifdef Z8KMAGIC
2259
24.0k
    case Z8KMAGIC:
2260
24.0k
      arch = bfd_arch_z8k;
2261
24.0k
      switch (internal_f->f_flags & F_MACHMASK)
2262
24.0k
  {
2263
6.51k
  case F_Z8001:
2264
6.51k
    machine = bfd_mach_z8001;
2265
6.51k
    break;
2266
17.2k
  case F_Z8002:
2267
17.2k
    machine = bfd_mach_z8002;
2268
17.2k
    break;
2269
326
  default:
2270
326
    return false;
2271
24.0k
  }
2272
23.7k
      break;
2273
23.7k
#endif
2274
2275
#ifdef RS6000COFF_C
2276
#ifdef XCOFF64
2277
51.5k
    case U64_TOCMAGIC:
2278
54.0k
    case U803XTOCMAGIC:
2279
#else
2280
27.4k
    case U802ROMAGIC:
2281
32.7k
    case U802WRMAGIC:
2282
52.0k
    case U802TOCMAGIC:
2283
#endif
2284
52.0k
      {
2285
52.0k
  int cputype;
2286
2287
106k
  if (xcoff_data (abfd)->cputype != -1)
2288
29.4k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
76.6k
  else
2290
76.6k
    {
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
76.6k
      if (obj_raw_syment_count (abfd) == 0)
2296
31.7k
        cputype = 0;
2297
44.9k
      else
2298
44.9k
        {
2299
44.9k
    bfd_byte *buf;
2300
44.9k
    struct internal_syment sym;
2301
44.9k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
44.9k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
459
      return false;
2305
44.4k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
44.4k
    if (buf == NULL)
2307
738
      return false;
2308
43.7k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
43.7k
    if (sym.n_sclass == C_FILE)
2310
1.28k
      cputype = sym.n_type & 0xff;
2311
42.4k
    else
2312
42.4k
      cputype = 0;
2313
43.7k
    free (buf);
2314
43.7k
        }
2315
76.6k
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
104k
  switch (cputype)
2319
104k
    {
2320
18.2k
    default:
2321
97.7k
    case 0:
2322
97.7k
      arch = bfd_xcoff_architecture (abfd);
2323
97.7k
      machine = bfd_xcoff_machine (abfd);
2324
97.7k
      break;
2325
2326
2.65k
    case 1:
2327
2.65k
      arch = bfd_arch_powerpc;
2328
2.65k
      machine = bfd_mach_ppc_601;
2329
2.65k
      break;
2330
1.48k
    case 2: /* 64 bit PowerPC */
2331
1.48k
      arch = bfd_arch_powerpc;
2332
1.48k
      machine = bfd_mach_ppc_620;
2333
1.48k
      break;
2334
2.25k
    case 3:
2335
2.25k
      arch = bfd_arch_powerpc;
2336
2.25k
      machine = bfd_mach_ppc;
2337
2.25k
      break;
2338
720
    case 4:
2339
720
      arch = bfd_arch_rs6000;
2340
720
      machine = bfd_mach_rs6k;
2341
720
      break;
2342
104k
    }
2343
104k
      }
2344
104k
      break;
2345
104k
#endif
2346
2347
#ifdef SH_ARCH_MAGIC_BIG
2348
106k
    case SH_ARCH_MAGIC_BIG:
2349
109k
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
90.6k
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
90.6k
      arch = bfd_arch_sh;
2354
90.6k
      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
27.0k
    case TIC30MAGIC:
2374
27.0k
      arch = bfd_arch_tic30;
2375
27.0k
      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
39.5k
    case TICOFF0MAGIC:
2382
39.5k
      arch = TICOFF_TARGET_ARCH;
2383
39.5k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
39.5k
      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
3.49k
    case TICOFF1MAGIC:
2392
3.51k
    case TICOFF2MAGIC:
2393
3.51k
      switch (internal_f->f_target_id)
2394
3.51k
  {
2395
0
#ifdef TI_TARGET_ID
2396
3.51k
  case TI_TARGET_ID:
2397
3.51k
    arch = TICOFF_TARGET_ARCH;
2398
3.51k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
3.51k
    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
3.51k
  }
2408
3.51k
      break;
2409
3.51k
#endif
2410
2411
#ifdef MCOREMAGIC
2412
93.4k
    case MCOREMAGIC:
2413
93.4k
      arch = bfd_arch_mcore;
2414
93.4k
      break;
2415
0
#endif
2416
2417
15.2k
    default:      /* Unreadable input file type.  */
2418
15.2k
      arch = bfd_arch_obscure;
2419
15.2k
      break;
2420
1.26M
    }
2421
2422
1.26M
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
1.26M
  return true;
2424
1.26M
}
pei-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
62.7k
{
2163
62.7k
  unsigned long machine;
2164
62.7k
  enum bfd_architecture arch;
2165
62.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
62.7k
  machine = 0;
2169
62.7k
  switch (internal_f->f_magic)
2170
62.7k
    {
2171
0
#ifdef I386MAGIC
2172
37.0k
    case I386MAGIC:
2173
39.2k
    case I386PTXMAGIC:
2174
41.1k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
62.5k
    case LYNXCOFFMAGIC:
2176
62.5k
    case I386_APPLE_MAGIC:
2177
62.5k
    case I386_FREEBSD_MAGIC:
2178
62.5k
    case I386_LINUX_MAGIC:
2179
62.7k
    case I386_NETBSD_MAGIC:
2180
62.7k
      arch = bfd_arch_i386;
2181
62.7k
      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
62.7k
    }
2421
2422
62.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
62.7k
  return true;
2424
62.7k
}
pe-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
91.5k
{
2163
91.5k
  unsigned long machine;
2164
91.5k
  enum bfd_architecture arch;
2165
91.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
91.5k
  machine = 0;
2169
91.5k
  switch (internal_f->f_magic)
2170
91.5k
    {
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
848
    case AMD64MAGIC:
2185
90.7k
    case AMD64_APPLE_MAGIC:
2186
90.8k
    case AMD64_FREEBSD_MAGIC:
2187
90.8k
    case AMD64_LINUX_MAGIC:
2188
91.5k
    case AMD64_NETBSD_MAGIC:
2189
91.5k
      arch = bfd_arch_i386;
2190
91.5k
      machine = bfd_mach_x86_64;
2191
91.5k
      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
91.5k
    }
2421
2422
91.5k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
91.5k
  return true;
2424
91.5k
}
pei-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
78.3k
{
2163
78.3k
  unsigned long machine;
2164
78.3k
  enum bfd_architecture arch;
2165
78.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
78.3k
  machine = 0;
2169
78.3k
  switch (internal_f->f_magic)
2170
78.3k
    {
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
9.47k
    case AMD64MAGIC:
2185
45.8k
    case AMD64_APPLE_MAGIC:
2186
45.8k
    case AMD64_FREEBSD_MAGIC:
2187
78.3k
    case AMD64_LINUX_MAGIC:
2188
78.3k
    case AMD64_NETBSD_MAGIC:
2189
78.3k
      arch = bfd_arch_i386;
2190
78.3k
      machine = bfd_mach_x86_64;
2191
78.3k
      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
78.3k
    }
2421
2422
78.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
78.3k
  return true;
2424
78.3k
}
coff-x86_64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
73.0k
{
2163
73.0k
  unsigned long machine;
2164
73.0k
  enum bfd_architecture arch;
2165
73.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
73.0k
  machine = 0;
2169
73.0k
  switch (internal_f->f_magic)
2170
73.0k
    {
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
549
    case AMD64MAGIC:
2185
72.5k
    case AMD64_APPLE_MAGIC:
2186
72.5k
    case AMD64_FREEBSD_MAGIC:
2187
72.5k
    case AMD64_LINUX_MAGIC:
2188
73.0k
    case AMD64_NETBSD_MAGIC:
2189
73.0k
      arch = bfd_arch_i386;
2190
73.0k
      machine = bfd_mach_x86_64;
2191
73.0k
      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
73.0k
    }
2421
2422
73.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
73.0k
  return true;
2424
73.0k
}
coff64-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
54.0k
{
2163
54.0k
  unsigned long machine;
2164
54.0k
  enum bfd_architecture arch;
2165
54.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
54.0k
  machine = 0;
2169
54.0k
  switch (internal_f->f_magic)
2170
54.0k
    {
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
51.5k
    case U64_TOCMAGIC:
2278
54.0k
    case U803XTOCMAGIC:
2279
#else
2280
    case U802ROMAGIC:
2281
    case U802WRMAGIC:
2282
    case U802TOCMAGIC:
2283
#endif
2284
54.0k
      {
2285
54.0k
  int cputype;
2286
2287
54.0k
  if (xcoff_data (abfd)->cputype != -1)
2288
19.5k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
34.5k
  else
2290
34.5k
    {
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
34.5k
      if (obj_raw_syment_count (abfd) == 0)
2296
14.6k
        cputype = 0;
2297
19.8k
      else
2298
19.8k
        {
2299
19.8k
    bfd_byte *buf;
2300
19.8k
    struct internal_syment sym;
2301
19.8k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
19.8k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
459
      return false;
2305
19.4k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
19.4k
    if (buf == NULL)
2307
353
      return false;
2308
19.0k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
19.0k
    if (sym.n_sclass == C_FILE)
2310
361
      cputype = sym.n_type & 0xff;
2311
18.6k
    else
2312
18.6k
      cputype = 0;
2313
19.0k
    free (buf);
2314
19.0k
        }
2315
34.5k
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
53.2k
  switch (cputype)
2319
53.2k
    {
2320
11.7k
    default:
2321
48.3k
    case 0:
2322
48.3k
      arch = bfd_xcoff_architecture (abfd);
2323
48.3k
      machine = bfd_xcoff_machine (abfd);
2324
48.3k
      break;
2325
2326
1.79k
    case 1:
2327
1.79k
      arch = bfd_arch_powerpc;
2328
1.79k
      machine = bfd_mach_ppc_601;
2329
1.79k
      break;
2330
888
    case 2: /* 64 bit PowerPC */
2331
888
      arch = bfd_arch_powerpc;
2332
888
      machine = bfd_mach_ppc_620;
2333
888
      break;
2334
1.76k
    case 3:
2335
1.76k
      arch = bfd_arch_powerpc;
2336
1.76k
      machine = bfd_mach_ppc;
2337
1.76k
      break;
2338
464
    case 4:
2339
464
      arch = bfd_arch_rs6000;
2340
464
      machine = bfd_mach_rs6k;
2341
464
      break;
2342
53.2k
    }
2343
53.2k
      }
2344
53.2k
      break;
2345
53.2k
#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
53.2k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
54.0k
    }
2421
2422
53.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
53.2k
  return true;
2424
54.0k
}
pe-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
28.7k
{
2163
28.7k
  unsigned long machine;
2164
28.7k
  enum bfd_architecture arch;
2165
28.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
28.7k
  machine = 0;
2169
28.7k
  switch (internal_f->f_magic)
2170
28.7k
    {
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
28.7k
    case AARCH64MAGIC:
2227
28.7k
      arch = bfd_arch_aarch64;
2228
28.7k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
28.7k
      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
28.7k
    }
2421
2422
28.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
28.7k
  return true;
2424
28.7k
}
pei-aarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
58.8k
{
2163
58.8k
  unsigned long machine;
2164
58.8k
  enum bfd_architecture arch;
2165
58.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
58.8k
  machine = 0;
2169
58.8k
  switch (internal_f->f_magic)
2170
58.8k
    {
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
58.8k
    case AARCH64MAGIC:
2227
58.8k
      arch = bfd_arch_aarch64;
2228
58.8k
      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2229
58.8k
      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
58.8k
    }
2421
2422
58.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
58.8k
  return true;
2424
58.8k
}
pei-ia64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
68.2k
{
2163
68.2k
  unsigned long machine;
2164
68.2k
  enum bfd_architecture arch;
2165
68.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
68.2k
  machine = 0;
2169
68.2k
  switch (internal_f->f_magic)
2170
68.2k
    {
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
68.2k
    case IA64MAGIC:
2195
68.2k
      arch = bfd_arch_ia64;
2196
68.2k
      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
68.2k
    }
2421
2422
68.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
68.2k
  return true;
2424
68.2k
}
pei-loongarch64.c:coff_set_arch_mach_hook
Line
Count
Source
2162
48.6k
{
2163
48.6k
  unsigned long machine;
2164
48.6k
  enum bfd_architecture arch;
2165
48.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
48.6k
  machine = 0;
2169
48.6k
  switch (internal_f->f_magic)
2170
48.6k
    {
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
48.6k
    case LOONGARCH64MAGIC:
2233
48.6k
      arch = bfd_arch_loongarch;
2234
48.6k
      machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
2235
48.6k
      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
48.6k
    }
2421
2422
48.6k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
48.6k
  return true;
2424
48.6k
}
cf-i386lynx.c:coff_set_arch_mach_hook
Line
Count
Source
2162
33.2k
{
2163
33.2k
  unsigned long machine;
2164
33.2k
  enum bfd_architecture arch;
2165
33.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
33.2k
  machine = 0;
2169
33.2k
  switch (internal_f->f_magic)
2170
33.2k
    {
2171
0
#ifdef I386MAGIC
2172
18.4k
    case I386MAGIC:
2173
19.0k
    case I386PTXMAGIC:
2174
19.5k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
32.4k
    case LYNXCOFFMAGIC:
2176
32.6k
    case I386_APPLE_MAGIC:
2177
32.6k
    case I386_FREEBSD_MAGIC:
2178
32.6k
    case I386_LINUX_MAGIC:
2179
33.2k
    case I386_NETBSD_MAGIC:
2180
33.2k
      arch = bfd_arch_i386;
2181
33.2k
      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
33.2k
    }
2421
2422
33.2k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
33.2k
  return true;
2424
33.2k
}
coff-go32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
30.9k
{
2163
30.9k
  unsigned long machine;
2164
30.9k
  enum bfd_architecture arch;
2165
30.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
30.9k
  machine = 0;
2169
30.9k
  switch (internal_f->f_magic)
2170
30.9k
    {
2171
0
#ifdef I386MAGIC
2172
17.2k
    case I386MAGIC:
2173
17.4k
    case I386PTXMAGIC:
2174
17.8k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
30.6k
    case LYNXCOFFMAGIC:
2176
30.8k
    case I386_APPLE_MAGIC:
2177
30.8k
    case I386_FREEBSD_MAGIC:
2178
30.8k
    case I386_LINUX_MAGIC:
2179
30.9k
    case I386_NETBSD_MAGIC:
2180
30.9k
      arch = bfd_arch_i386;
2181
30.9k
      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
30.9k
    }
2421
2422
30.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
30.9k
  return true;
2424
30.9k
}
coff-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
30.9k
{
2163
30.9k
  unsigned long machine;
2164
30.9k
  enum bfd_architecture arch;
2165
30.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
30.9k
  machine = 0;
2169
30.9k
  switch (internal_f->f_magic)
2170
30.9k
    {
2171
0
#ifdef I386MAGIC
2172
17.2k
    case I386MAGIC:
2173
17.4k
    case I386PTXMAGIC:
2174
17.8k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
30.6k
    case LYNXCOFFMAGIC:
2176
30.8k
    case I386_APPLE_MAGIC:
2177
30.8k
    case I386_FREEBSD_MAGIC:
2178
30.8k
    case I386_LINUX_MAGIC:
2179
30.9k
    case I386_NETBSD_MAGIC:
2180
30.9k
      arch = bfd_arch_i386;
2181
30.9k
      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
30.9k
    }
2421
2422
30.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
30.9k
  return true;
2424
30.9k
}
coff-rs6000.c:coff_set_arch_mach_hook
Line
Count
Source
2162
52.0k
{
2163
52.0k
  unsigned long machine;
2164
52.0k
  enum bfd_architecture arch;
2165
52.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
52.0k
  machine = 0;
2169
52.0k
  switch (internal_f->f_magic)
2170
52.0k
    {
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
27.4k
    case U802ROMAGIC:
2281
32.7k
    case U802WRMAGIC:
2282
52.0k
    case U802TOCMAGIC:
2283
52.0k
#endif
2284
52.0k
      {
2285
52.0k
  int cputype;
2286
2287
52.0k
  if (xcoff_data (abfd)->cputype != -1)
2288
9.89k
    cputype = xcoff_data (abfd)->cputype & 0xff;
2289
42.1k
  else
2290
42.1k
    {
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
42.1k
      if (obj_raw_syment_count (abfd) == 0)
2296
17.0k
        cputype = 0;
2297
25.0k
      else
2298
25.0k
        {
2299
25.0k
    bfd_byte *buf;
2300
25.0k
    struct internal_syment sym;
2301
25.0k
    bfd_size_type amt = bfd_coff_symesz (abfd);
2302
2303
25.0k
    if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
2304
0
      return false;
2305
25.0k
    buf = _bfd_malloc_and_read (abfd, amt, amt);
2306
25.0k
    if (buf == NULL)
2307
385
      return false;
2308
24.6k
    bfd_coff_swap_sym_in (abfd, buf, & sym);
2309
24.6k
    if (sym.n_sclass == C_FILE)
2310
922
      cputype = sym.n_type & 0xff;
2311
23.7k
    else
2312
23.7k
      cputype = 0;
2313
24.6k
    free (buf);
2314
24.6k
        }
2315
42.1k
    }
2316
2317
  /* FIXME: We don't handle all cases here.  */
2318
51.6k
  switch (cputype)
2319
51.6k
    {
2320
6.46k
    default:
2321
49.4k
    case 0:
2322
49.4k
      arch = bfd_xcoff_architecture (abfd);
2323
49.4k
      machine = bfd_xcoff_machine (abfd);
2324
49.4k
      break;
2325
2326
856
    case 1:
2327
856
      arch = bfd_arch_powerpc;
2328
856
      machine = bfd_mach_ppc_601;
2329
856
      break;
2330
595
    case 2: /* 64 bit PowerPC */
2331
595
      arch = bfd_arch_powerpc;
2332
595
      machine = bfd_mach_ppc_620;
2333
595
      break;
2334
497
    case 3:
2335
497
      arch = bfd_arch_powerpc;
2336
497
      machine = bfd_mach_ppc;
2337
497
      break;
2338
256
    case 4:
2339
256
      arch = bfd_arch_rs6000;
2340
256
      machine = bfd_mach_rs6k;
2341
256
      break;
2342
51.6k
    }
2343
51.6k
      }
2344
51.6k
      break;
2345
51.6k
#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
51.6k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
52.0k
    }
2421
2422
51.6k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
51.6k
  return true;
2424
52.0k
}
coff-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
47.3k
{
2163
47.3k
  unsigned long machine;
2164
47.3k
  enum bfd_architecture arch;
2165
47.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
47.3k
  machine = 0;
2169
47.3k
  switch (internal_f->f_magic)
2170
47.3k
    {
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
40.6k
    case SH_ARCH_MAGIC_BIG:
2349
42.6k
    case SH_ARCH_MAGIC_LITTLE:
2350
#ifdef COFF_WITH_PE
2351
    case SH_ARCH_MAGIC_WINCE:
2352
#endif
2353
42.6k
      arch = bfd_arch_sh;
2354
42.6k
      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
4.63k
    default:      /* Unreadable input file type.  */
2418
4.63k
      arch = bfd_arch_obscure;
2419
4.63k
      break;
2420
47.3k
    }
2421
2422
47.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
47.3k
  return true;
2424
47.3k
}
coff-stgo32.c:coff_set_arch_mach_hook
Line
Count
Source
2162
2.50k
{
2163
2.50k
  unsigned long machine;
2164
2.50k
  enum bfd_architecture arch;
2165
2.50k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
2.50k
  machine = 0;
2169
2.50k
  switch (internal_f->f_magic)
2170
2.50k
    {
2171
0
#ifdef I386MAGIC
2172
1.25k
    case I386MAGIC:
2173
1.64k
    case I386PTXMAGIC:
2174
1.82k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
1.90k
    case LYNXCOFFMAGIC:
2176
1.91k
    case I386_APPLE_MAGIC:
2177
1.91k
    case I386_FREEBSD_MAGIC:
2178
1.91k
    case I386_LINUX_MAGIC:
2179
2.50k
    case I386_NETBSD_MAGIC:
2180
2.50k
      arch = bfd_arch_i386;
2181
2.50k
      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
2.50k
    }
2421
2422
2.50k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
2.50k
  return true;
2424
2.50k
}
coff-tic30.c:coff_set_arch_mach_hook
Line
Count
Source
2162
27.0k
{
2163
27.0k
  unsigned long machine;
2164
27.0k
  enum bfd_architecture arch;
2165
27.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
27.0k
  machine = 0;
2169
27.0k
  switch (internal_f->f_magic)
2170
27.0k
    {
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
27.0k
    case TIC30MAGIC:
2374
27.0k
      arch = bfd_arch_tic30;
2375
27.0k
      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
27.0k
    }
2421
2422
27.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
27.0k
  return true;
2424
27.0k
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach_hook
coff-tic54x.c:coff_set_arch_mach_hook
Line
Count
Source
2162
43.0k
{
2163
43.0k
  unsigned long machine;
2164
43.0k
  enum bfd_architecture arch;
2165
43.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
43.0k
  machine = 0;
2169
43.0k
  switch (internal_f->f_magic)
2170
43.0k
    {
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
39.5k
    case TICOFF0MAGIC:
2382
39.5k
      arch = TICOFF_TARGET_ARCH;
2383
39.5k
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2384
39.5k
      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
3.49k
    case TICOFF1MAGIC:
2392
3.51k
    case TICOFF2MAGIC:
2393
3.51k
      switch (internal_f->f_target_id)
2394
3.51k
  {
2395
0
#ifdef TI_TARGET_ID
2396
3.51k
  case TI_TARGET_ID:
2397
3.51k
    arch = TICOFF_TARGET_ARCH;
2398
3.51k
    machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
2399
3.51k
    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
3.51k
  }
2408
3.51k
      break;
2409
3.51k
#endif
2410
2411
#ifdef MCOREMAGIC
2412
    case MCOREMAGIC:
2413
      arch = bfd_arch_mcore;
2414
      break;
2415
#endif
2416
2417
3.51k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
43.0k
    }
2421
2422
43.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
43.0k
  return true;
2424
43.0k
}
coff-z80.c:coff_set_arch_mach_hook
Line
Count
Source
2162
21.6k
{
2163
21.6k
  unsigned long machine;
2164
21.6k
  enum bfd_architecture arch;
2165
21.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
21.6k
  machine = 0;
2169
21.6k
  switch (internal_f->f_magic)
2170
21.6k
    {
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
21.6k
    case Z80MAGIC:
2239
21.6k
      arch = bfd_arch_z80;
2240
21.6k
      switch (internal_f->f_flags & F_MACHMASK)
2241
21.6k
  {
2242
685
  case bfd_mach_z80strict << 12:
2243
3.86k
  case bfd_mach_z80 << 12:
2244
6.11k
  case bfd_mach_z80n << 12:
2245
8.58k
  case bfd_mach_z80full << 12:
2246
12.2k
  case bfd_mach_r800 << 12:
2247
14.0k
  case bfd_mach_gbz80 << 12:
2248
17.4k
  case bfd_mach_z180 << 12:
2249
18.4k
  case bfd_mach_ez80_z80 << 12:
2250
21.3k
  case bfd_mach_ez80_adl << 12:
2251
21.3k
    machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
2252
21.3k
    break;
2253
318
  default:
2254
318
    return false;
2255
21.6k
  }
2256
21.3k
      break;
2257
21.3k
#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
21.3k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
21.6k
    }
2421
2422
21.3k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
21.3k
  return true;
2424
21.6k
}
coff-z8k.c:coff_set_arch_mach_hook
Line
Count
Source
2162
24.0k
{
2163
24.0k
  unsigned long machine;
2164
24.0k
  enum bfd_architecture arch;
2165
24.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
24.0k
  machine = 0;
2169
24.0k
  switch (internal_f->f_magic)
2170
24.0k
    {
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
24.0k
    case Z8KMAGIC:
2260
24.0k
      arch = bfd_arch_z8k;
2261
24.0k
      switch (internal_f->f_flags & F_MACHMASK)
2262
24.0k
  {
2263
6.51k
  case F_Z8001:
2264
6.51k
    machine = bfd_mach_z8001;
2265
6.51k
    break;
2266
17.2k
  case F_Z8002:
2267
17.2k
    machine = bfd_mach_z8002;
2268
17.2k
    break;
2269
326
  default:
2270
326
    return false;
2271
24.0k
  }
2272
23.7k
      break;
2273
23.7k
#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
23.7k
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
24.0k
    }
2421
2422
23.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
23.7k
  return true;
2424
24.0k
}
pe-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
12.0k
{
2163
12.0k
  unsigned long machine;
2164
12.0k
  enum bfd_architecture arch;
2165
12.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
12.0k
  machine = 0;
2169
12.0k
  switch (internal_f->f_magic)
2170
12.0k
    {
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
10.1k
    case ARMMAGIC:
2200
11.0k
    case ARMPEMAGIC:
2201
11.2k
    case THUMBPEMAGIC:
2202
11.2k
      arch = bfd_arch_arm;
2203
11.2k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
11.2k
      if (machine == bfd_mach_arm_unknown)
2205
11.2k
  {
2206
11.2k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
11.2k
      {
2208
1.52k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
313
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
800
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
6.61k
      default:
2212
6.72k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
1.10k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
296
      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
515
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
11.2k
      }
2222
11.2k
  }
2223
11.2k
      break;
2224
11.2k
#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
11.2k
    default:      /* Unreadable input file type.  */
2418
791
      arch = bfd_arch_obscure;
2419
791
      break;
2420
12.0k
    }
2421
2422
12.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
12.0k
  return true;
2424
12.0k
}
pe-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
12.0k
{
2163
12.0k
  unsigned long machine;
2164
12.0k
  enum bfd_architecture arch;
2165
12.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
12.0k
  machine = 0;
2169
12.0k
  switch (internal_f->f_magic)
2170
12.0k
    {
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
10.1k
    case ARMMAGIC:
2200
11.0k
    case ARMPEMAGIC:
2201
11.2k
    case THUMBPEMAGIC:
2202
11.2k
      arch = bfd_arch_arm;
2203
11.2k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
11.2k
      if (machine == bfd_mach_arm_unknown)
2205
11.2k
  {
2206
11.2k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
11.2k
      {
2208
1.52k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
313
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
800
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
6.61k
      default:
2212
6.72k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
1.10k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
296
      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
515
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
11.2k
      }
2222
11.2k
  }
2223
11.2k
      break;
2224
11.2k
#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
11.2k
    default:      /* Unreadable input file type.  */
2418
791
      arch = bfd_arch_obscure;
2419
791
      break;
2420
12.0k
    }
2421
2422
12.0k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
12.0k
  return true;
2424
12.0k
}
pe-i386.c:coff_set_arch_mach_hook
Line
Count
Source
2162
39.8k
{
2163
39.8k
  unsigned long machine;
2164
39.8k
  enum bfd_architecture arch;
2165
39.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
39.8k
  machine = 0;
2169
39.8k
  switch (internal_f->f_magic)
2170
39.8k
    {
2171
0
#ifdef I386MAGIC
2172
19.9k
    case I386MAGIC:
2173
20.6k
    case I386PTXMAGIC:
2174
22.7k
    case I386AIXMAGIC:   /* Danbury PS/2 AIX C Compiler.  */
2175
36.5k
    case LYNXCOFFMAGIC:
2176
39.2k
    case I386_APPLE_MAGIC:
2177
39.2k
    case I386_FREEBSD_MAGIC:
2178
39.3k
    case I386_LINUX_MAGIC:
2179
39.8k
    case I386_NETBSD_MAGIC:
2180
39.8k
      arch = bfd_arch_i386;
2181
39.8k
      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
39.8k
    }
2421
2422
39.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
39.8k
  return true;
2424
39.8k
}
pe-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
29.9k
{
2163
29.9k
  unsigned long machine;
2164
29.9k
  enum bfd_architecture arch;
2165
29.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
29.9k
  machine = 0;
2169
29.9k
  switch (internal_f->f_magic)
2170
29.9k
    {
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
29.9k
    case MCOREMAGIC:
2413
29.9k
      arch = bfd_arch_mcore;
2414
29.9k
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
29.9k
    }
2421
2422
29.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
29.9k
  return true;
2424
29.9k
}
pe-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
33.7k
{
2163
33.7k
  unsigned long machine;
2164
33.7k
  enum bfd_architecture arch;
2165
33.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
33.7k
  machine = 0;
2169
33.7k
  switch (internal_f->f_magic)
2170
33.7k
    {
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
29.5k
    case SH_ARCH_MAGIC_BIG:
2349
30.6k
    case SH_ARCH_MAGIC_LITTLE:
2350
30.6k
#ifdef COFF_WITH_PE
2351
33.7k
    case SH_ARCH_MAGIC_WINCE:
2352
33.7k
#endif
2353
33.7k
      arch = bfd_arch_sh;
2354
33.7k
      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
33.7k
    }
2421
2422
33.7k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
33.7k
  return true;
2424
33.7k
}
pei-arm-wince.c:coff_set_arch_mach_hook
Line
Count
Source
2162
62.8k
{
2163
62.8k
  unsigned long machine;
2164
62.8k
  enum bfd_architecture arch;
2165
62.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
62.8k
  machine = 0;
2169
62.8k
  switch (internal_f->f_magic)
2170
62.8k
    {
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
42.6k
    case ARMMAGIC:
2200
43.7k
    case ARMPEMAGIC:
2201
59.9k
    case THUMBPEMAGIC:
2202
59.9k
      arch = bfd_arch_arm;
2203
59.9k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
59.9k
      if (machine == bfd_mach_arm_unknown)
2205
59.9k
  {
2206
59.9k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
59.9k
      {
2208
1.75k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
3.21k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
1.72k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
35.6k
      default:
2212
36.5k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
3.66k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
6.76k
      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
6.23k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
59.9k
      }
2222
59.9k
  }
2223
59.9k
      break;
2224
59.9k
#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
59.9k
    default:      /* Unreadable input file type.  */
2418
2.96k
      arch = bfd_arch_obscure;
2419
2.96k
      break;
2420
62.8k
    }
2421
2422
62.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
62.8k
  return true;
2424
62.8k
}
pei-arm.c:coff_set_arch_mach_hook
Line
Count
Source
2162
77.8k
{
2163
77.8k
  unsigned long machine;
2164
77.8k
  enum bfd_architecture arch;
2165
77.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
77.8k
  machine = 0;
2169
77.8k
  switch (internal_f->f_magic)
2170
77.8k
    {
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
48.6k
    case ARMMAGIC:
2200
52.3k
    case ARMPEMAGIC:
2201
71.8k
    case THUMBPEMAGIC:
2202
71.8k
      arch = bfd_arch_arm;
2203
71.8k
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
2204
71.8k
      if (machine == bfd_mach_arm_unknown)
2205
71.8k
  {
2206
71.8k
    switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
2207
71.8k
      {
2208
3.72k
      case F_ARM_2:  machine = bfd_mach_arm_2;  break;
2209
4.09k
      case F_ARM_2a: machine = bfd_mach_arm_2a; break;
2210
2.21k
      case F_ARM_3:  machine = bfd_mach_arm_3;  break;
2211
39.5k
      default:
2212
41.9k
      case F_ARM_3M: machine = bfd_mach_arm_3M; break;
2213
5.33k
      case F_ARM_4:  machine = bfd_mach_arm_4;  break;
2214
6.15k
      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
8.35k
      case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
2221
71.8k
      }
2222
71.8k
  }
2223
71.8k
      break;
2224
71.8k
#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
71.8k
    default:      /* Unreadable input file type.  */
2418
6.06k
      arch = bfd_arch_obscure;
2419
6.06k
      break;
2420
77.8k
    }
2421
2422
77.8k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
77.8k
  return true;
2424
77.8k
}
pei-mcore.c:coff_set_arch_mach_hook
Line
Count
Source
2162
63.4k
{
2163
63.4k
  unsigned long machine;
2164
63.4k
  enum bfd_architecture arch;
2165
63.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
63.4k
  machine = 0;
2169
63.4k
  switch (internal_f->f_magic)
2170
63.4k
    {
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
63.4k
    case MCOREMAGIC:
2413
63.4k
      arch = bfd_arch_mcore;
2414
63.4k
      break;
2415
0
#endif
2416
2417
0
    default:      /* Unreadable input file type.  */
2418
0
      arch = bfd_arch_obscure;
2419
0
      break;
2420
63.4k
    }
2421
2422
63.4k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
63.4k
  return true;
2424
63.4k
}
pei-sh.c:coff_set_arch_mach_hook
Line
Count
Source
2162
56.9k
{
2163
56.9k
  unsigned long machine;
2164
56.9k
  enum bfd_architecture arch;
2165
56.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
2166
2167
  /* Zero selects the default machine for an arch.  */
2168
56.9k
  machine = 0;
2169
56.9k
  switch (internal_f->f_magic)
2170
56.9k
    {
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
35.9k
    case SH_ARCH_MAGIC_BIG:
2349
36.3k
    case SH_ARCH_MAGIC_LITTLE:
2350
36.3k
#ifdef COFF_WITH_PE
2351
56.9k
    case SH_ARCH_MAGIC_WINCE:
2352
56.9k
#endif
2353
56.9k
      arch = bfd_arch_sh;
2354
56.9k
      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
56.9k
    }
2421
2422
56.9k
  bfd_default_set_arch_mach (abfd, arch, machine);
2423
56.9k
  return true;
2424
56.9k
}
2425
2426
static bool
2427
symname_in_debug_hook (bfd *abfd ATTRIBUTE_UNUSED,
2428
           struct internal_syment *sym ATTRIBUTE_UNUSED)
2429
834k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
232k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
834k
}
pei-i386.c:symname_in_debug_hook
Line
Count
Source
2429
14.9k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
14.9k
  return false;
2434
14.9k
#endif
2435
14.9k
}
pe-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
39.1k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
39.1k
  return false;
2434
39.1k
#endif
2435
39.1k
}
pei-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
18.0k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
18.0k
  return false;
2434
18.0k
#endif
2435
18.0k
}
coff-x86_64.c:symname_in_debug_hook
Line
Count
Source
2429
25.7k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
25.7k
  return false;
2434
25.7k
#endif
2435
25.7k
}
coff64-rs6000.c:symname_in_debug_hook
Line
Count
Source
2429
146k
{
2430
146k
#ifdef SYMNAME_IN_DEBUG
2431
146k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
146k
}
pe-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
36.8k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
36.8k
  return false;
2434
36.8k
#endif
2435
36.8k
}
pei-aarch64.c:symname_in_debug_hook
Line
Count
Source
2429
26.2k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
26.2k
  return false;
2434
26.2k
#endif
2435
26.2k
}
pei-ia64.c:symname_in_debug_hook
Line
Count
Source
2429
28.0k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
28.0k
  return false;
2434
28.0k
#endif
2435
28.0k
}
pei-loongarch64.c:symname_in_debug_hook
Line
Count
Source
2429
40.4k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
40.4k
  return false;
2434
40.4k
#endif
2435
40.4k
}
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
85.9k
{
2430
85.9k
#ifdef SYMNAME_IN_DEBUG
2431
85.9k
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
  return false;
2434
#endif
2435
85.9k
}
coff-sh.c:symname_in_debug_hook
Line
Count
Source
2429
34.9k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
34.9k
  return false;
2434
34.9k
#endif
2435
34.9k
}
Unexecuted instantiation: coff-stgo32.c:symname_in_debug_hook
coff-tic30.c:symname_in_debug_hook
Line
Count
Source
2429
23.1k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
23.1k
  return false;
2434
23.1k
#endif
2435
23.1k
}
Unexecuted instantiation: coff-tic4x.c:symname_in_debug_hook
coff-tic54x.c:symname_in_debug_hook
Line
Count
Source
2429
44.5k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
44.5k
  return false;
2434
44.5k
#endif
2435
44.5k
}
coff-z80.c:symname_in_debug_hook
Line
Count
Source
2429
21.7k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
21.7k
  return false;
2434
21.7k
#endif
2435
21.7k
}
coff-z8k.c:symname_in_debug_hook
Line
Count
Source
2429
46.2k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
46.2k
  return false;
2434
46.2k
#endif
2435
46.2k
}
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
46.4k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
46.4k
  return false;
2434
46.4k
#endif
2435
46.4k
}
pe-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
47.1k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
47.1k
  return false;
2434
47.1k
#endif
2435
47.1k
}
pe-sh.c:symname_in_debug_hook
Line
Count
Source
2429
30.0k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
30.0k
  return false;
2434
30.0k
#endif
2435
30.0k
}
pei-arm-wince.c:symname_in_debug_hook
Line
Count
Source
2429
13.6k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
13.6k
  return false;
2434
13.6k
#endif
2435
13.6k
}
pei-arm.c:symname_in_debug_hook
Line
Count
Source
2429
17.1k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
17.1k
  return false;
2434
17.1k
#endif
2435
17.1k
}
pei-mcore.c:symname_in_debug_hook
Line
Count
Source
2429
13.5k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
13.5k
  return false;
2434
13.5k
#endif
2435
13.5k
}
pei-sh.c:symname_in_debug_hook
Line
Count
Source
2429
33.9k
{
2430
#ifdef SYMNAME_IN_DEBUG
2431
  return SYMNAME_IN_DEBUG (sym) != 0;
2432
#else
2433
33.9k
  return false;
2434
33.9k
#endif
2435
33.9k
}
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
5.58M
{
2452
5.58M
  BFD_ASSERT (symbol->is_sym);
2453
5.58M
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
5.58M
  if (CSECT_SYM_P (n_sclass)
2456
5.58M
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
10.2k
    {
2458
10.2k
      BFD_ASSERT (! aux->is_sym);
2459
10.2k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
10.2k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
2.63k
  {
2462
2.63k
    aux->u.auxent.x_csect.x_scnlen.p =
2463
2.63k
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
2.63k
    aux->fix_scnlen = 1;
2465
2.63k
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
10.2k
      return true;
2470
10.2k
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
5.57M
  return false;
2475
5.58M
}
coff64-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
1.49M
{
2452
1.49M
  BFD_ASSERT (symbol->is_sym);
2453
1.49M
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
1.49M
  if (CSECT_SYM_P (n_sclass)
2456
1.49M
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
4.50k
    {
2458
4.50k
      BFD_ASSERT (! aux->is_sym);
2459
4.50k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
4.50k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
3
  {
2462
3
    aux->u.auxent.x_csect.x_scnlen.p =
2463
3
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
3
    aux->fix_scnlen = 1;
2465
3
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
4.50k
      return true;
2470
4.50k
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
1.49M
  return false;
2475
1.49M
}
coff-rs6000.c:coff_pointerize_aux_hook
Line
Count
Source
2451
4.08M
{
2452
4.08M
  BFD_ASSERT (symbol->is_sym);
2453
4.08M
  int n_sclass = symbol->u.syment.n_sclass;
2454
2455
4.08M
  if (CSECT_SYM_P (n_sclass)
2456
4.08M
      && indaux + 1 == symbol->u.syment.n_numaux)
2457
5.75k
    {
2458
5.75k
      BFD_ASSERT (! aux->is_sym);
2459
5.75k
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD
2460
5.75k
    && aux->u.auxent.x_csect.x_scnlen.u64 < obj_raw_syment_count (abfd))
2461
2.62k
  {
2462
2.62k
    aux->u.auxent.x_csect.x_scnlen.p =
2463
2.62k
      table_base + aux->u.auxent.x_csect.x_scnlen.u64;
2464
2.62k
    aux->fix_scnlen = 1;
2465
2.62k
  }
2466
2467
      /* Return TRUE to indicate that the caller should not do any
2468
   further work on this auxent.  */
2469
5.75k
      return true;
2470
5.75k
    }
2471
2472
  /* Return FALSE to indicate that this auxent should be handled by
2473
     the caller.  */
2474
4.07M
  return false;
2475
4.08M
}
2476
2477
#else
2478
#define coff_pointerize_aux_hook 0
2479
#endif /* ! RS6000COFF_C */
2480
2481
/* Print an aux entry.  This returns TRUE if it has printed it.  */
2482
2483
static bool
2484
coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
2485
    FILE *file ATTRIBUTE_UNUSED,
2486
    combined_entry_type *table_base ATTRIBUTE_UNUSED,
2487
    combined_entry_type *symbol ATTRIBUTE_UNUSED,
2488
    combined_entry_type *aux ATTRIBUTE_UNUSED,
2489
    unsigned int indaux ATTRIBUTE_UNUSED)
2490
0
{
2491
0
  BFD_ASSERT (symbol->is_sym);
2492
0
  BFD_ASSERT (! aux->is_sym);
2493
#ifdef RS6000COFF_C
2494
0
  if (CSECT_SYM_P (symbol->u.syment.n_sclass)
2495
0
      && indaux + 1 == symbol->u.syment.n_numaux)
2496
0
    {
2497
      /* This is a csect entry.  */
2498
0
      fprintf (file, "AUX ");
2499
0
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
2500
0
  {
2501
0
    BFD_ASSERT (! aux->fix_scnlen);
2502
0
    fprintf (file, "val %5" PRIu64,
2503
0
       aux->u.auxent.x_csect.x_scnlen.u64);
2504
0
  }
2505
0
      else
2506
0
  {
2507
0
    fprintf (file, "indx ");
2508
0
    if (! aux->fix_scnlen)
2509
0
      fprintf (file, "%4" PRIu64,
2510
0
         aux->u.auxent.x_csect.x_scnlen.u64);
2511
0
    else
2512
0
      fprintf (file, "%4ld",
2513
0
         (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
2514
0
  }
2515
0
      fprintf (file,
2516
0
         " prmhsh %u snhsh %u typ %d algn %d clss %u stb %u snstb %u",
2517
0
         aux->u.auxent.x_csect.x_parmhash,
2518
0
         (unsigned int) aux->u.auxent.x_csect.x_snhash,
2519
0
         SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
2520
0
         SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
2521
0
         (unsigned int) aux->u.auxent.x_csect.x_smclas,
2522
0
         aux->u.auxent.x_csect.x_stab,
2523
0
         (unsigned int) aux->u.auxent.x_csect.x_snstab);
2524
0
      return true;
2525
0
    }
2526
0
#endif
2527
2528
  /* Return FALSE to indicate that no special action was taken.  */
2529
0
  return false;
2530
0
}
Unexecuted instantiation: pei-i386.c:coff_print_aux
Unexecuted instantiation: pe-x86_64.c:coff_print_aux
Unexecuted instantiation: pei-x86_64.c:coff_print_aux
Unexecuted instantiation: coff-x86_64.c:coff_print_aux
Unexecuted instantiation: coff64-rs6000.c:coff_print_aux
Unexecuted instantiation: pe-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-aarch64.c:coff_print_aux
Unexecuted instantiation: pei-ia64.c:coff_print_aux
Unexecuted instantiation: pei-loongarch64.c:coff_print_aux
Unexecuted instantiation: cf-i386lynx.c:coff_print_aux
Unexecuted instantiation: coff-go32.c:coff_print_aux
Unexecuted instantiation: coff-i386.c:coff_print_aux
Unexecuted instantiation: coff-rs6000.c:coff_print_aux
Unexecuted instantiation: coff-sh.c:coff_print_aux
Unexecuted instantiation: coff-stgo32.c:coff_print_aux
Unexecuted instantiation: coff-tic30.c:coff_print_aux
Unexecuted instantiation: coff-tic4x.c:coff_print_aux
Unexecuted instantiation: coff-tic54x.c:coff_print_aux
Unexecuted instantiation: coff-z80.c:coff_print_aux
Unexecuted instantiation: coff-z8k.c:coff_print_aux
Unexecuted instantiation: pe-arm-wince.c:coff_print_aux
Unexecuted instantiation: pe-arm.c:coff_print_aux
Unexecuted instantiation: pe-i386.c:coff_print_aux
Unexecuted instantiation: pe-mcore.c:coff_print_aux
Unexecuted instantiation: pe-sh.c:coff_print_aux
Unexecuted instantiation: pei-arm-wince.c:coff_print_aux
Unexecuted instantiation: pei-arm.c:coff_print_aux
Unexecuted instantiation: pei-mcore.c:coff_print_aux
Unexecuted instantiation: pei-sh.c:coff_print_aux
2531
2532
/*
2533
SUBSUBSECTION
2534
  Writing relocations
2535
2536
  To write relocations, the back end steps though the
2537
  canonical relocation table and create an
2538
  @code{internal_reloc}. The symbol index to use is removed from
2539
  the @code{offset} field in the symbol table supplied.  The
2540
  address comes directly from the sum of the section base
2541
  address and the relocation offset; the type is dug directly
2542
  from the howto field.  Then the @code{internal_reloc} is
2543
  swapped into the shape of an @code{external_reloc} and written
2544
  out to disk.
2545
2546
*/
2547
2548
#ifdef TARG_AUX
2549
2550
2551
/* AUX's ld wants relocations to be sorted.  */
2552
static int
2553
compare_arelent_ptr (const void * x, const void * y)
2554
{
2555
  const arelent **a = (const arelent **) x;
2556
  const arelent **b = (const arelent **) y;
2557
  bfd_size_type aadr = (*a)->address;
2558
  bfd_size_type badr = (*b)->address;
2559
2560
  return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2561
}
2562
2563
#endif /* TARG_AUX */
2564
2565
static bool
2566
coff_write_relocs (bfd * abfd, int first_undef)
2567
7
{
2568
7
  asection *s;
2569
2570
581
  for (s = abfd->sections; s != NULL; s = s->next)
2571
574
    {
2572
574
      unsigned int i;
2573
574
      struct external_reloc dst;
2574
574
      arelent **p;
2575
2576
574
#ifndef TARG_AUX
2577
574
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
574
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
574
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
574
#endif
2617
2618
574
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
0
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
0
    n.r_offset = q->addend;
2693
0
#endif
2694
2695
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
0
    if (q->howto)
2701
0
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
574
    }
2714
2715
7
  return true;
2716
7
}
Unexecuted instantiation: pei-i386.c:coff_write_relocs
Unexecuted instantiation: pe-x86_64.c:coff_write_relocs
pei-x86_64.c:coff_write_relocs
Line
Count
Source
2567
3
{
2568
3
  asection *s;
2569
2570
72
  for (s = abfd->sections; s != NULL; s = s->next)
2571
69
    {
2572
69
      unsigned int i;
2573
69
      struct external_reloc dst;
2574
69
      arelent **p;
2575
2576
69
#ifndef TARG_AUX
2577
69
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
69
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
69
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
69
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
69
#endif
2617
2618
69
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
69
    }
2714
2715
3
  return true;
2716
3
}
Unexecuted instantiation: coff-x86_64.c:coff_write_relocs
Unexecuted instantiation: coff64-rs6000.c:coff_write_relocs
pe-aarch64.c:coff_write_relocs
Line
Count
Source
2567
1
{
2568
1
  asection *s;
2569
2570
2
  for (s = abfd->sections; s != NULL; s = s->next)
2571
1
    {
2572
1
      unsigned int i;
2573
1
      struct external_reloc dst;
2574
1
      arelent **p;
2575
2576
1
#ifndef TARG_AUX
2577
1
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
1
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
1
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
1
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
1
#endif
2617
2618
1
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
1
    }
2714
2715
1
  return true;
2716
1
}
Unexecuted instantiation: pei-aarch64.c:coff_write_relocs
Unexecuted instantiation: pei-ia64.c:coff_write_relocs
Unexecuted instantiation: pei-loongarch64.c:coff_write_relocs
Unexecuted instantiation: cf-i386lynx.c:coff_write_relocs
Unexecuted instantiation: coff-go32.c:coff_write_relocs
Unexecuted instantiation: coff-i386.c:coff_write_relocs
Unexecuted instantiation: coff-rs6000.c:coff_write_relocs
Unexecuted instantiation: coff-sh.c:coff_write_relocs
Unexecuted instantiation: coff-stgo32.c:coff_write_relocs
Unexecuted instantiation: coff-tic30.c:coff_write_relocs
Unexecuted instantiation: coff-tic4x.c:coff_write_relocs
Unexecuted instantiation: coff-tic54x.c:coff_write_relocs
Unexecuted instantiation: coff-z80.c:coff_write_relocs
Unexecuted instantiation: coff-z8k.c:coff_write_relocs
Unexecuted instantiation: pe-arm-wince.c:coff_write_relocs
Unexecuted instantiation: pe-arm.c:coff_write_relocs
pe-i386.c:coff_write_relocs
Line
Count
Source
2567
1
{
2568
1
  asection *s;
2569
2570
498
  for (s = abfd->sections; s != NULL; s = s->next)
2571
497
    {
2572
497
      unsigned int i;
2573
497
      struct external_reloc dst;
2574
497
      arelent **p;
2575
2576
497
#ifndef TARG_AUX
2577
497
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
497
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
497
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
497
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
497
#endif
2617
2618
497
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
#ifdef SWAP_OUT_RELOC_OFFSET
2692
    n.r_offset = q->addend;
2693
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
497
    }
2714
2715
1
  return true;
2716
1
}
pe-mcore.c:coff_write_relocs
Line
Count
Source
2567
2
{
2568
2
  asection *s;
2569
2570
9
  for (s = abfd->sections; s != NULL; s = s->next)
2571
7
    {
2572
7
      unsigned int i;
2573
7
      struct external_reloc dst;
2574
7
      arelent **p;
2575
2576
7
#ifndef TARG_AUX
2577
7
      p = s->orelocation;
2578
#else
2579
      {
2580
  /* Sort relocations before we write them out.  */
2581
  bfd_size_type amt;
2582
2583
  amt = s->reloc_count;
2584
  amt *= sizeof (arelent *);
2585
  p = bfd_malloc (amt);
2586
  if (p == NULL)
2587
    {
2588
      if (s->reloc_count > 0)
2589
        return false;
2590
    }
2591
  else
2592
    {
2593
      memcpy (p, s->orelocation, (size_t) amt);
2594
      qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
2595
    }
2596
      }
2597
#endif
2598
2599
7
      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
2600
0
  return false;
2601
2602
7
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
2603
7
      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
2604
0
  {
2605
    /* Encode real count here as first reloc.  */
2606
0
    struct internal_reloc n;
2607
2608
0
    memset (& n, 0, sizeof (n));
2609
    /* Add one to count *this* reloc (grr).  */
2610
0
    n.r_vaddr = s->reloc_count + 1;
2611
0
    coff_swap_reloc_out (abfd, &n, &dst);
2612
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2613
0
        != bfd_coff_relsz (abfd))
2614
0
      return false;
2615
0
  }
2616
7
#endif
2617
2618
7
      for (i = 0; i < s->reloc_count; i++)
2619
0
  {
2620
0
    struct internal_reloc n;
2621
0
    arelent *q = p[i];
2622
2623
0
    memset (& n, 0, sizeof (n));
2624
2625
    /* Now we've renumbered the symbols we know where the
2626
       undefined symbols live in the table.  Check the reloc
2627
       entries for symbols who's output bfd isn't the right one.
2628
       This is because the symbol was undefined (which means
2629
       that all the pointers are never made to point to the same
2630
       place). This is a bad thing,'cause the symbols attached
2631
       to the output bfd are indexed, so that the relocation
2632
       entries know which symbol index they point to.  So we
2633
       have to look up the output symbol here.  */
2634
2635
0
    if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
2636
0
      {
2637
0
        int j;
2638
0
        const char *sname = q->sym_ptr_ptr[0]->name;
2639
0
        asymbol **outsyms = abfd->outsymbols;
2640
2641
0
        for (j = first_undef; outsyms[j]; j++)
2642
0
    {
2643
0
      const char *intable = outsyms[j]->name;
2644
2645
0
      if (strcmp (intable, sname) == 0)
2646
0
        {
2647
          /* Got a hit, so repoint the reloc.  */
2648
0
          q->sym_ptr_ptr = outsyms + j;
2649
0
          break;
2650
0
        }
2651
0
    }
2652
0
      }
2653
2654
0
    n.r_vaddr = q->address + s->vma;
2655
2656
#ifdef R_IHCONST
2657
    /* The 29k const/consth reloc pair is a real kludge.  The consth
2658
       part doesn't have a symbol; it has an offset.  So rebuilt
2659
       that here.  */
2660
    if (q->howto->type == R_IHCONST)
2661
      n.r_symndx = q->addend;
2662
    else
2663
#endif
2664
0
      if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
2665
0
        {
2666
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
2667
    if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
2668
#else
2669
0
    if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
2670
0
        && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
2671
0
#endif
2672
      /* This is a relocation relative to the absolute symbol.  */
2673
0
      n.r_symndx = -1;
2674
0
    else
2675
0
      {
2676
0
        n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
2677
        /* Check to see if the symbol reloc points to a symbol
2678
           we don't have in our symbol table.  */
2679
0
        if (n.r_symndx > obj_conv_table_size (abfd))
2680
0
          {
2681
0
      bfd_set_error (bfd_error_bad_value);
2682
      /* xgettext:c-format */
2683
0
      _bfd_error_handler (_("%pB: reloc against a non-existent"
2684
0
                " symbol index: %ld"),
2685
0
              abfd, n.r_symndx);
2686
0
      return false;
2687
0
          }
2688
0
      }
2689
0
        }
2690
2691
0
#ifdef SWAP_OUT_RELOC_OFFSET
2692
0
    n.r_offset = q->addend;
2693
0
#endif
2694
2695
0
#ifdef SELECT_RELOC
2696
    /* Work out reloc type from what is required.  */
2697
0
    if (q->howto)
2698
0
      SELECT_RELOC (n, q->howto);
2699
#else
2700
    if (q->howto)
2701
      n.r_type = q->howto->type;
2702
#endif
2703
0
    coff_swap_reloc_out (abfd, &n, &dst);
2704
2705
0
    if (bfd_write (&dst, bfd_coff_relsz (abfd), abfd)
2706
0
        != bfd_coff_relsz (abfd))
2707
0
      return false;
2708
0
  }
2709
2710
#ifdef TARG_AUX
2711
      free (p);
2712
#endif
2713
7
    }
2714
2715
2
  return true;
2716
2
}
Unexecuted instantiation: pe-sh.c:coff_write_relocs
Unexecuted instantiation: pei-arm-wince.c:coff_write_relocs
Unexecuted instantiation: pei-arm.c:coff_write_relocs
Unexecuted instantiation: pei-mcore.c:coff_write_relocs
Unexecuted instantiation: pei-sh.c:coff_write_relocs
2717
2718
/* Set flags and magic number of a coff file from architecture and machine
2719
   type.  Result is TRUE if we can represent the arch&type, FALSE if not.  */
2720
2721
static bool
2722
coff_set_flags (bfd * abfd,
2723
    unsigned int *magicp ATTRIBUTE_UNUSED,
2724
    unsigned short *flagsp ATTRIBUTE_UNUSED)
2725
1.21k
{
2726
1.21k
  switch (bfd_get_arch (abfd))
2727
1.21k
    {
2728
#ifdef Z80MAGIC
2729
42
    case bfd_arch_z80:
2730
42
      *magicp = Z80MAGIC;
2731
42
      switch (bfd_get_mach (abfd))
2732
42
  {
2733
0
  case bfd_mach_z80strict:
2734
0
  case bfd_mach_z80:
2735
0
  case bfd_mach_z80n:
2736
0
  case bfd_mach_z80full:
2737
0
  case bfd_mach_r800:
2738
0
  case bfd_mach_gbz80:
2739
6
  case bfd_mach_z180:
2740
40
  case bfd_mach_ez80_z80:
2741
42
  case bfd_mach_ez80_adl:
2742
42
    *flagsp = bfd_get_mach (abfd) << 12;
2743
42
    break;
2744
0
  default:
2745
0
    return false;
2746
42
  }
2747
42
      return true;
2748
0
#endif
2749
2750
#ifdef Z8KMAGIC
2751
52
    case bfd_arch_z8k:
2752
52
      *magicp = Z8KMAGIC;
2753
2754
52
      switch (bfd_get_mach (abfd))
2755
52
  {
2756
11
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
41
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
0
  default:       return false;
2759
52
  }
2760
52
      return true;
2761
0
#endif
2762
2763
#ifdef TIC30MAGIC
2764
40
    case bfd_arch_tic30:
2765
40
      *magicp = TIC30MAGIC;
2766
40
      return true;
2767
0
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
68
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
68
      if (!abfd->xvec )
2773
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
68
      else
2775
68
  {
2776
    /* We may want to output in a different COFF version.  */
2777
68
    switch (abfd->xvec->name[4])
2778
68
      {
2779
68
      case '0':
2780
68
        *magicp = TICOFF0MAGIC;
2781
68
        break;
2782
0
      case '1':
2783
0
        *magicp = TICOFF1MAGIC;
2784
0
        break;
2785
0
      case '2':
2786
0
        *magicp = TICOFF2MAGIC;
2787
0
        break;
2788
0
      default:
2789
0
        return false;
2790
68
      }
2791
68
  }
2792
68
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
68
      return true;
2794
0
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
69
    case bfd_arch_aarch64:
2798
69
      * magicp = AARCH64MAGIC;
2799
69
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
92
    case bfd_arch_loongarch:
2804
92
      * magicp = LOONGARCH64MAGIC;
2805
92
      return true;
2806
0
#endif
2807
2808
#ifdef ARMMAGIC
2809
13
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
13
      * magicp = ARMMAGIC;
2814
13
#endif
2815
13
      * flagsp = 0;
2816
13
      if (APCS_SET (abfd))
2817
1
  {
2818
1
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
1
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
1
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
1
  }
2827
13
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
13
      switch (bfd_get_mach (abfd))
2830
13
  {
2831
3
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
1
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
9
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
13
  }
2844
13
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
278
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
113
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
0
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
165
      *magicp = AMD64MAGIC;
2858
#endif
2859
278
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
63
    case bfd_arch_ia64:
2864
63
      *magicp = IA64MAGIC;
2865
63
      return true;
2866
0
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
206
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
21
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
185
      if (bfd_big_endian (abfd))
2874
7
  *magicp = SH_ARCH_MAGIC_BIG;
2875
178
      else
2876
178
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
206
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
133
    case bfd_arch_rs6000:
2899
250
    case bfd_arch_powerpc:
2900
250
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
250
      *magicp = bfd_xcoff_magic_number (abfd);
2902
250
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
44
    case bfd_arch_mcore:
2907
44
      * magicp = MCOREMAGIC;
2908
44
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
1.21k
    }
2914
2915
0
  return false;
2916
1.21k
}
pei-i386.c:coff_set_flags
Line
Count
Source
2725
59
{
2726
59
  switch (bfd_get_arch (abfd))
2727
59
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
59
    case bfd_arch_i386:
2849
59
#if defined(I386MAGIC)
2850
59
      *magicp = I386MAGIC;
2851
59
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
59
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
59
    }
2914
2915
0
  return false;
2916
59
}
pe-x86_64.c:coff_set_flags
Line
Count
Source
2725
43
{
2726
43
  switch (bfd_get_arch (abfd))
2727
43
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
43
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
43
#if defined AMD64MAGIC
2857
43
      *magicp = AMD64MAGIC;
2858
43
#endif
2859
43
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
43
    }
2914
2915
0
  return false;
2916
43
}
pei-x86_64.c:coff_set_flags
Line
Count
Source
2725
61
{
2726
61
  switch (bfd_get_arch (abfd))
2727
61
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
61
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
61
#if defined AMD64MAGIC
2857
61
      *magicp = AMD64MAGIC;
2858
61
#endif
2859
61
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
61
    }
2914
2915
0
  return false;
2916
61
}
coff-x86_64.c:coff_set_flags
Line
Count
Source
2725
61
{
2726
61
  switch (bfd_get_arch (abfd))
2727
61
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
61
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
61
#if defined AMD64MAGIC
2857
61
      *magicp = AMD64MAGIC;
2858
61
#endif
2859
61
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
61
    }
2914
2915
0
  return false;
2916
61
}
coff64-rs6000.c:coff_set_flags
Line
Count
Source
2725
117
{
2726
117
  switch (bfd_get_arch (abfd))
2727
117
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
0
#ifdef RS6000COFF_C
2898
0
    case bfd_arch_rs6000:
2899
117
    case bfd_arch_powerpc:
2900
117
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
117
      *magicp = bfd_xcoff_magic_number (abfd);
2902
117
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
117
    }
2914
2915
0
  return false;
2916
117
}
pe-aarch64.c:coff_set_flags
Line
Count
Source
2725
40
{
2726
40
  switch (bfd_get_arch (abfd))
2727
40
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
0
#ifdef AARCH64MAGIC
2797
40
    case bfd_arch_aarch64:
2798
40
      * magicp = AARCH64MAGIC;
2799
40
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
40
    }
2914
2915
0
  return false;
2916
40
}
pei-aarch64.c:coff_set_flags
Line
Count
Source
2725
29
{
2726
29
  switch (bfd_get_arch (abfd))
2727
29
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
0
#ifdef AARCH64MAGIC
2797
29
    case bfd_arch_aarch64:
2798
29
      * magicp = AARCH64MAGIC;
2799
29
      return true;
2800
0
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
29
    }
2914
2915
0
  return false;
2916
29
}
pei-ia64.c:coff_set_flags
Line
Count
Source
2725
63
{
2726
63
  switch (bfd_get_arch (abfd))
2727
63
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
0
#ifdef IA64MAGIC
2863
63
    case bfd_arch_ia64:
2864
63
      *magicp = IA64MAGIC;
2865
63
      return true;
2866
0
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
63
    }
2914
2915
0
  return false;
2916
63
}
pei-loongarch64.c:coff_set_flags
Line
Count
Source
2725
92
{
2726
92
  switch (bfd_get_arch (abfd))
2727
92
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
0
#ifdef LOONGARCH64MAGIC
2803
92
    case bfd_arch_loongarch:
2804
92
      * magicp = LOONGARCH64MAGIC;
2805
92
      return true;
2806
0
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
92
    }
2914
2915
0
  return false;
2916
92
}
Unexecuted instantiation: cf-i386lynx.c:coff_set_flags
Unexecuted instantiation: coff-go32.c:coff_set_flags
Unexecuted instantiation: coff-i386.c:coff_set_flags
coff-rs6000.c:coff_set_flags
Line
Count
Source
2725
133
{
2726
133
  switch (bfd_get_arch (abfd))
2727
133
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
0
#ifdef RS6000COFF_C
2898
133
    case bfd_arch_rs6000:
2899
133
    case bfd_arch_powerpc:
2900
133
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
133
      *magicp = bfd_xcoff_magic_number (abfd);
2902
133
      return true;
2903
0
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
133
    }
2914
2915
0
  return false;
2916
133
}
coff-sh.c:coff_set_flags
Line
Count
Source
2725
153
{
2726
153
  switch (bfd_get_arch (abfd))
2727
153
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
153
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
153
      if (bfd_big_endian (abfd))
2874
7
  *magicp = SH_ARCH_MAGIC_BIG;
2875
146
      else
2876
146
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
153
#endif
2878
153
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
153
    }
2914
2915
0
  return false;
2916
153
}
Unexecuted instantiation: coff-stgo32.c:coff_set_flags
coff-tic30.c:coff_set_flags
Line
Count
Source
2725
40
{
2726
40
  switch (bfd_get_arch (abfd))
2727
40
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
0
#ifdef TIC30MAGIC
2764
40
    case bfd_arch_tic30:
2765
40
      *magicp = TIC30MAGIC;
2766
40
      return true;
2767
0
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
40
    }
2914
2915
0
  return false;
2916
40
}
Unexecuted instantiation: coff-tic4x.c:coff_set_flags
coff-tic54x.c:coff_set_flags
Line
Count
Source
2725
68
{
2726
68
  switch (bfd_get_arch (abfd))
2727
68
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
0
#ifdef TICOFF_DEFAULT_MAGIC
2770
68
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
68
      if (!abfd->xvec )
2773
0
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
68
      else
2775
68
  {
2776
    /* We may want to output in a different COFF version.  */
2777
68
    switch (abfd->xvec->name[4])
2778
68
      {
2779
68
      case '0':
2780
68
        *magicp = TICOFF0MAGIC;
2781
68
        break;
2782
0
      case '1':
2783
0
        *magicp = TICOFF1MAGIC;
2784
0
        break;
2785
0
      case '2':
2786
0
        *magicp = TICOFF2MAGIC;
2787
0
        break;
2788
0
      default:
2789
0
        return false;
2790
68
      }
2791
68
  }
2792
68
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
68
      return true;
2794
0
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
68
    }
2914
2915
0
  return false;
2916
68
}
coff-z80.c:coff_set_flags
Line
Count
Source
2725
42
{
2726
42
  switch (bfd_get_arch (abfd))
2727
42
    {
2728
0
#ifdef Z80MAGIC
2729
42
    case bfd_arch_z80:
2730
42
      *magicp = Z80MAGIC;
2731
42
      switch (bfd_get_mach (abfd))
2732
42
  {
2733
0
  case bfd_mach_z80strict:
2734
0
  case bfd_mach_z80:
2735
0
  case bfd_mach_z80n:
2736
0
  case bfd_mach_z80full:
2737
0
  case bfd_mach_r800:
2738
0
  case bfd_mach_gbz80:
2739
6
  case bfd_mach_z180:
2740
40
  case bfd_mach_ez80_z80:
2741
42
  case bfd_mach_ez80_adl:
2742
42
    *flagsp = bfd_get_mach (abfd) << 12;
2743
42
    break;
2744
0
  default:
2745
0
    return false;
2746
42
  }
2747
42
      return true;
2748
0
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
42
    }
2914
2915
0
  return false;
2916
42
}
coff-z8k.c:coff_set_flags
Line
Count
Source
2725
52
{
2726
52
  switch (bfd_get_arch (abfd))
2727
52
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
0
#ifdef Z8KMAGIC
2751
52
    case bfd_arch_z8k:
2752
52
      *magicp = Z8KMAGIC;
2753
2754
52
      switch (bfd_get_mach (abfd))
2755
52
  {
2756
11
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
41
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
0
  default:       return false;
2759
52
  }
2760
52
      return true;
2761
0
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
52
    }
2914
2915
0
  return false;
2916
52
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_flags
Unexecuted instantiation: pe-arm.c:coff_set_flags
pe-i386.c:coff_set_flags
Line
Count
Source
2725
54
{
2726
54
  switch (bfd_get_arch (abfd))
2727
54
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
0
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
54
    case bfd_arch_i386:
2849
54
#if defined(I386MAGIC)
2850
54
      *magicp = I386MAGIC;
2851
54
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
54
      return true;
2860
0
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
54
    }
2914
2915
0
  return false;
2916
54
}
pe-mcore.c:coff_set_flags
Line
Count
Source
2725
39
{
2726
39
  switch (bfd_get_arch (abfd))
2727
39
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
0
#ifdef MCOREMAGIC
2906
39
    case bfd_arch_mcore:
2907
39
      * magicp = MCOREMAGIC;
2908
39
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
39
    }
2914
2915
0
  return false;
2916
39
}
pe-sh.c:coff_set_flags
Line
Count
Source
2725
32
{
2726
32
  switch (bfd_get_arch (abfd))
2727
32
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
32
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
32
      if (bfd_big_endian (abfd))
2874
0
  *magicp = SH_ARCH_MAGIC_BIG;
2875
32
      else
2876
32
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
32
#endif
2878
32
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
32
    }
2914
2915
0
  return false;
2916
32
}
pei-arm-wince.c:coff_set_flags
Line
Count
Source
2725
6
{
2726
6
  switch (bfd_get_arch (abfd))
2727
6
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
0
#ifdef ARMMAGIC
2809
6
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
6
      * magicp = ARMMAGIC;
2814
6
#endif
2815
6
      * flagsp = 0;
2816
6
      if (APCS_SET (abfd))
2817
1
  {
2818
1
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
1
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
1
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
1
  }
2827
6
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
6
      switch (bfd_get_mach (abfd))
2830
6
  {
2831
2
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
0
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
4
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
6
  }
2844
6
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
6
    }
2914
2915
0
  return false;
2916
6
}
pei-arm.c:coff_set_flags
Line
Count
Source
2725
7
{
2726
7
  switch (bfd_get_arch (abfd))
2727
7
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
0
#ifdef ARMMAGIC
2809
7
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
7
      * magicp = ARMMAGIC;
2814
7
#endif
2815
7
      * flagsp = 0;
2816
7
      if (APCS_SET (abfd))
2817
0
  {
2818
0
    if (APCS_26_FLAG (abfd))
2819
0
      * flagsp |= F_APCS26;
2820
2821
0
    if (APCS_FLOAT_FLAG (abfd))
2822
0
      * flagsp |= F_APCS_FLOAT;
2823
2824
0
    if (PIC_FLAG (abfd))
2825
0
      * flagsp |= F_PIC;
2826
0
  }
2827
7
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
0
  * flagsp |= F_INTERWORK;
2829
7
      switch (bfd_get_mach (abfd))
2830
7
  {
2831
1
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
0
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
0
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
1
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
0
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
0
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
0
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
0
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
0
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
5
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
7
  }
2844
7
      return true;
2845
0
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
7
    }
2914
2915
0
  return false;
2916
7
}
pei-mcore.c:coff_set_flags
Line
Count
Source
2725
5
{
2726
5
  switch (bfd_get_arch (abfd))
2727
5
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
#ifdef SH_ARCH_MAGIC_BIG
2869
    case bfd_arch_sh:
2870
#ifdef COFF_IMAGE_WITH_PE
2871
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
      return true;
2879
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
0
#ifdef MCOREMAGIC
2906
5
    case bfd_arch_mcore:
2907
5
      * magicp = MCOREMAGIC;
2908
5
      return true;
2909
0
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
5
    }
2914
2915
0
  return false;
2916
5
}
pei-sh.c:coff_set_flags
Line
Count
Source
2725
21
{
2726
21
  switch (bfd_get_arch (abfd))
2727
21
    {
2728
#ifdef Z80MAGIC
2729
    case bfd_arch_z80:
2730
      *magicp = Z80MAGIC;
2731
      switch (bfd_get_mach (abfd))
2732
  {
2733
  case bfd_mach_z80strict:
2734
  case bfd_mach_z80:
2735
  case bfd_mach_z80n:
2736
  case bfd_mach_z80full:
2737
  case bfd_mach_r800:
2738
  case bfd_mach_gbz80:
2739
  case bfd_mach_z180:
2740
  case bfd_mach_ez80_z80:
2741
  case bfd_mach_ez80_adl:
2742
    *flagsp = bfd_get_mach (abfd) << 12;
2743
    break;
2744
  default:
2745
    return false;
2746
  }
2747
      return true;
2748
#endif
2749
2750
#ifdef Z8KMAGIC
2751
    case bfd_arch_z8k:
2752
      *magicp = Z8KMAGIC;
2753
2754
      switch (bfd_get_mach (abfd))
2755
  {
2756
  case bfd_mach_z8001: *flagsp = F_Z8001; break;
2757
  case bfd_mach_z8002: *flagsp = F_Z8002; break;
2758
  default:       return false;
2759
  }
2760
      return true;
2761
#endif
2762
2763
#ifdef TIC30MAGIC
2764
    case bfd_arch_tic30:
2765
      *magicp = TIC30MAGIC;
2766
      return true;
2767
#endif
2768
2769
#ifdef TICOFF_DEFAULT_MAGIC
2770
    case TICOFF_TARGET_ARCH:
2771
      /* If there's no indication of which version we want, use the default.  */
2772
      if (!abfd->xvec )
2773
  *magicp = TICOFF_DEFAULT_MAGIC;
2774
      else
2775
  {
2776
    /* We may want to output in a different COFF version.  */
2777
    switch (abfd->xvec->name[4])
2778
      {
2779
      case '0':
2780
        *magicp = TICOFF0MAGIC;
2781
        break;
2782
      case '1':
2783
        *magicp = TICOFF1MAGIC;
2784
        break;
2785
      case '2':
2786
        *magicp = TICOFF2MAGIC;
2787
        break;
2788
      default:
2789
        return false;
2790
      }
2791
  }
2792
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
2793
      return true;
2794
#endif
2795
2796
#ifdef AARCH64MAGIC
2797
    case bfd_arch_aarch64:
2798
      * magicp = AARCH64MAGIC;
2799
      return true;
2800
#endif
2801
2802
#ifdef LOONGARCH64MAGIC
2803
    case bfd_arch_loongarch:
2804
      * magicp = LOONGARCH64MAGIC;
2805
      return true;
2806
#endif
2807
2808
#ifdef ARMMAGIC
2809
    case bfd_arch_arm:
2810
#ifdef ARM_WINCE
2811
      * magicp = ARMPEMAGIC;
2812
#else
2813
      * magicp = ARMMAGIC;
2814
#endif
2815
      * flagsp = 0;
2816
      if (APCS_SET (abfd))
2817
  {
2818
    if (APCS_26_FLAG (abfd))
2819
      * flagsp |= F_APCS26;
2820
2821
    if (APCS_FLOAT_FLAG (abfd))
2822
      * flagsp |= F_APCS_FLOAT;
2823
2824
    if (PIC_FLAG (abfd))
2825
      * flagsp |= F_PIC;
2826
  }
2827
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
2828
  * flagsp |= F_INTERWORK;
2829
      switch (bfd_get_mach (abfd))
2830
  {
2831
  case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
2832
  case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
2833
  case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
2834
  case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
2835
  case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
2836
  case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
2837
  case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
2838
    /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
2839
       See also the comment in coff_set_arch_mach_hook().  */
2840
  case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
2841
  case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
2842
  case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
2843
  }
2844
      return true;
2845
#endif
2846
2847
#if defined(I386MAGIC) || defined(AMD64MAGIC)
2848
    case bfd_arch_i386:
2849
#if defined(I386MAGIC)
2850
      *magicp = I386MAGIC;
2851
#endif
2852
#if defined LYNXOS
2853
      /* Just overwrite the usual value if we're doing Lynx.  */
2854
      *magicp = LYNXCOFFMAGIC;
2855
#endif
2856
#if defined AMD64MAGIC
2857
      *magicp = AMD64MAGIC;
2858
#endif
2859
      return true;
2860
#endif
2861
2862
#ifdef IA64MAGIC
2863
    case bfd_arch_ia64:
2864
      *magicp = IA64MAGIC;
2865
      return true;
2866
#endif
2867
2868
0
#ifdef SH_ARCH_MAGIC_BIG
2869
21
    case bfd_arch_sh:
2870
21
#ifdef COFF_IMAGE_WITH_PE
2871
21
      *magicp = SH_ARCH_MAGIC_WINCE;
2872
#else
2873
      if (bfd_big_endian (abfd))
2874
  *magicp = SH_ARCH_MAGIC_BIG;
2875
      else
2876
  *magicp = SH_ARCH_MAGIC_LITTLE;
2877
#endif
2878
21
      return true;
2879
0
#endif
2880
2881
#ifdef MIPS_ARCH_MAGIC_WINCE
2882
    case bfd_arch_mips:
2883
      *magicp = MIPS_ARCH_MAGIC_WINCE;
2884
      return true;
2885
#endif
2886
2887
#ifdef SPARCMAGIC
2888
    case bfd_arch_sparc:
2889
      *magicp = SPARCMAGIC;
2890
#ifdef LYNXOS
2891
      /* Just overwrite the usual value if we're doing Lynx.  */
2892
      *magicp = LYNXCOFFMAGIC;
2893
#endif
2894
      return true;
2895
#endif
2896
2897
#ifdef RS6000COFF_C
2898
    case bfd_arch_rs6000:
2899
    case bfd_arch_powerpc:
2900
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
2901
      *magicp = bfd_xcoff_magic_number (abfd);
2902
      return true;
2903
#endif
2904
2905
#ifdef MCOREMAGIC
2906
    case bfd_arch_mcore:
2907
      * magicp = MCOREMAGIC;
2908
      return true;
2909
#endif
2910
2911
0
    default:      /* Unknown architecture.  */
2912
0
      break;
2913
21
    }
2914
2915
0
  return false;
2916
21
}
2917
2918
static bool
2919
coff_set_arch_mach (bfd * abfd,
2920
        enum bfd_architecture arch,
2921
        unsigned long machine)
2922
1.19k
{
2923
1.19k
  unsigned dummy1;
2924
1.19k
  unsigned short dummy2;
2925
2926
1.19k
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
3
    return false;
2928
2929
1.18k
  if (arch != bfd_arch_unknown
2930
1.18k
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
1.18k
  return true;     /* We're easy...  */
2934
1.18k
}
pei-i386.c:coff_set_arch_mach
Line
Count
Source
2922
56
{
2923
56
  unsigned dummy1;
2924
56
  unsigned short dummy2;
2925
2926
56
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
56
  if (arch != bfd_arch_unknown
2930
56
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
56
  return true;     /* We're easy...  */
2934
56
}
pe-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
42
{
2923
42
  unsigned dummy1;
2924
42
  unsigned short dummy2;
2925
2926
42
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
42
  if (arch != bfd_arch_unknown
2930
42
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
42
  return true;     /* We're easy...  */
2934
42
}
pei-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
53
{
2923
53
  unsigned dummy1;
2924
53
  unsigned short dummy2;
2925
2926
53
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
53
  if (arch != bfd_arch_unknown
2930
53
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
53
  return true;     /* We're easy...  */
2934
53
}
coff-x86_64.c:coff_set_arch_mach
Line
Count
Source
2922
59
{
2923
59
  unsigned dummy1;
2924
59
  unsigned short dummy2;
2925
2926
59
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
59
  if (arch != bfd_arch_unknown
2930
59
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
59
  return true;     /* We're easy...  */
2934
59
}
coff64-rs6000.c:coff_set_arch_mach
Line
Count
Source
2922
116
{
2923
116
  unsigned dummy1;
2924
116
  unsigned short dummy2;
2925
2926
116
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
116
  if (arch != bfd_arch_unknown
2930
116
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
116
  return true;     /* We're easy...  */
2934
116
}
pe-aarch64.c:coff_set_arch_mach
Line
Count
Source
2922
39
{
2923
39
  unsigned dummy1;
2924
39
  unsigned short dummy2;
2925
2926
39
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
39
  if (arch != bfd_arch_unknown
2930
39
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
39
  return true;     /* We're easy...  */
2934
39
}
pei-aarch64.c:coff_set_arch_mach
Line
Count
Source
2922
27
{
2923
27
  unsigned dummy1;
2924
27
  unsigned short dummy2;
2925
2926
27
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
27
  if (arch != bfd_arch_unknown
2930
27
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
27
  return true;     /* We're easy...  */
2934
27
}
pei-ia64.c:coff_set_arch_mach
Line
Count
Source
2922
63
{
2923
63
  unsigned dummy1;
2924
63
  unsigned short dummy2;
2925
2926
63
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
63
  if (arch != bfd_arch_unknown
2930
63
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
63
  return true;     /* We're easy...  */
2934
63
}
pei-loongarch64.c:coff_set_arch_mach
Line
Count
Source
2922
95
{
2923
95
  unsigned dummy1;
2924
95
  unsigned short dummy2;
2925
2926
95
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
3
    return false;
2928
2929
92
  if (arch != bfd_arch_unknown
2930
92
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
92
  return true;     /* We're easy...  */
2934
92
}
Unexecuted instantiation: cf-i386lynx.c:coff_set_arch_mach
Unexecuted instantiation: coff-go32.c:coff_set_arch_mach
Unexecuted instantiation: coff-i386.c:coff_set_arch_mach
coff-rs6000.c:coff_set_arch_mach
Line
Count
Source
2922
133
{
2923
133
  unsigned dummy1;
2924
133
  unsigned short dummy2;
2925
2926
133
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
133
  if (arch != bfd_arch_unknown
2930
133
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
133
  return true;     /* We're easy...  */
2934
133
}
coff-sh.c:coff_set_arch_mach
Line
Count
Source
2922
152
{
2923
152
  unsigned dummy1;
2924
152
  unsigned short dummy2;
2925
2926
152
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
152
  if (arch != bfd_arch_unknown
2930
152
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
152
  return true;     /* We're easy...  */
2934
152
}
Unexecuted instantiation: coff-stgo32.c:coff_set_arch_mach
coff-tic30.c:coff_set_arch_mach
Line
Count
Source
2922
40
{
2923
40
  unsigned dummy1;
2924
40
  unsigned short dummy2;
2925
2926
40
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
40
  if (arch != bfd_arch_unknown
2930
40
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
40
  return true;     /* We're easy...  */
2934
40
}
Unexecuted instantiation: coff-tic4x.c:coff_set_arch_mach
coff-tic54x.c:coff_set_arch_mach
Line
Count
Source
2922
68
{
2923
68
  unsigned dummy1;
2924
68
  unsigned short dummy2;
2925
2926
68
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
68
  if (arch != bfd_arch_unknown
2930
68
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
68
  return true;     /* We're easy...  */
2934
68
}
coff-z80.c:coff_set_arch_mach
Line
Count
Source
2922
42
{
2923
42
  unsigned dummy1;
2924
42
  unsigned short dummy2;
2925
2926
42
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
42
  if (arch != bfd_arch_unknown
2930
42
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
42
  return true;     /* We're easy...  */
2934
42
}
coff-z8k.c:coff_set_arch_mach
Line
Count
Source
2922
49
{
2923
49
  unsigned dummy1;
2924
49
  unsigned short dummy2;
2925
2926
49
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
49
  if (arch != bfd_arch_unknown
2930
49
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
49
  return true;     /* We're easy...  */
2934
49
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_arch_mach
Unexecuted instantiation: pe-arm.c:coff_set_arch_mach
pe-i386.c:coff_set_arch_mach
Line
Count
Source
2922
51
{
2923
51
  unsigned dummy1;
2924
51
  unsigned short dummy2;
2925
2926
51
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
51
  if (arch != bfd_arch_unknown
2930
51
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
51
  return true;     /* We're easy...  */
2934
51
}
pe-mcore.c:coff_set_arch_mach
Line
Count
Source
2922
37
{
2923
37
  unsigned dummy1;
2924
37
  unsigned short dummy2;
2925
2926
37
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
37
  if (arch != bfd_arch_unknown
2930
37
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
37
  return true;     /* We're easy...  */
2934
37
}
pe-sh.c:coff_set_arch_mach
Line
Count
Source
2922
32
{
2923
32
  unsigned dummy1;
2924
32
  unsigned short dummy2;
2925
2926
32
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
32
  if (arch != bfd_arch_unknown
2930
32
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
32
  return true;     /* We're easy...  */
2934
32
}
pei-arm-wince.c:coff_set_arch_mach
Line
Count
Source
2922
5
{
2923
5
  unsigned dummy1;
2924
5
  unsigned short dummy2;
2925
2926
5
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
5
  if (arch != bfd_arch_unknown
2930
5
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
5
  return true;     /* We're easy...  */
2934
5
}
pei-arm.c:coff_set_arch_mach
Line
Count
Source
2922
7
{
2923
7
  unsigned dummy1;
2924
7
  unsigned short dummy2;
2925
2926
7
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
7
  if (arch != bfd_arch_unknown
2930
7
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
7
  return true;     /* We're easy...  */
2934
7
}
pei-mcore.c:coff_set_arch_mach
Line
Count
Source
2922
5
{
2923
5
  unsigned dummy1;
2924
5
  unsigned short dummy2;
2925
2926
5
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
5
  if (arch != bfd_arch_unknown
2930
5
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
5
  return true;     /* We're easy...  */
2934
5
}
pei-sh.c:coff_set_arch_mach
Line
Count
Source
2922
20
{
2923
20
  unsigned dummy1;
2924
20
  unsigned short dummy2;
2925
2926
20
  if (! bfd_default_set_arch_mach (abfd, arch, machine))
2927
0
    return false;
2928
2929
20
  if (arch != bfd_arch_unknown
2930
20
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
2931
0
    return false;   /* We can't represent this type.  */
2932
2933
20
  return true;     /* We're easy...  */
2934
20
}
2935
2936
#ifdef COFF_IMAGE_WITH_PE
2937
2938
/* This is used to sort sections by VMA, as required by PE image
2939
   files.  */
2940
2941
static int
2942
sort_by_secaddr (const void * arg1, const void * arg2)
2943
212
{
2944
212
  const asection *a = *(const asection **) arg1;
2945
212
  const asection *b = *(const asection **) arg2;
2946
2947
212
  if (a->vma < b->vma)
2948
140
    return -1;
2949
72
  else if (a->vma > b->vma)
2950
63
    return 1;
2951
2952
9
  return 0;
2953
212
}
pei-i386.c:sort_by_secaddr
Line
Count
Source
2943
17
{
2944
17
  const asection *a = *(const asection **) arg1;
2945
17
  const asection *b = *(const asection **) arg2;
2946
2947
17
  if (a->vma < b->vma)
2948
17
    return -1;
2949
0
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
0
  return 0;
2953
17
}
pei-x86_64.c:sort_by_secaddr
Line
Count
Source
2943
192
{
2944
192
  const asection *a = *(const asection **) arg1;
2945
192
  const asection *b = *(const asection **) arg2;
2946
2947
192
  if (a->vma < b->vma)
2948
123
    return -1;
2949
69
  else if (a->vma > b->vma)
2950
63
    return 1;
2951
2952
6
  return 0;
2953
192
}
pei-aarch64.c:sort_by_secaddr
Line
Count
Source
2943
2
{
2944
2
  const asection *a = *(const asection **) arg1;
2945
2
  const asection *b = *(const asection **) arg2;
2946
2947
2
  if (a->vma < b->vma)
2948
0
    return -1;
2949
2
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
2
  return 0;
2953
2
}
Unexecuted instantiation: pei-ia64.c:sort_by_secaddr
Unexecuted instantiation: pei-loongarch64.c:sort_by_secaddr
pei-arm-wince.c:sort_by_secaddr
Line
Count
Source
2943
1
{
2944
1
  const asection *a = *(const asection **) arg1;
2945
1
  const asection *b = *(const asection **) arg2;
2946
2947
1
  if (a->vma < b->vma)
2948
0
    return -1;
2949
1
  else if (a->vma > b->vma)
2950
0
    return 1;
2951
2952
1
  return 0;
2953
1
}
Unexecuted instantiation: pei-arm.c:sort_by_secaddr
Unexecuted instantiation: pei-mcore.c:sort_by_secaddr
Unexecuted instantiation: pei-sh.c:sort_by_secaddr
2954
2955
#endif /* COFF_IMAGE_WITH_PE */
2956
2957
/* Calculate the file position for each section.  */
2958
2959
#define ALIGN_SECTIONS_IN_FILE
2960
#ifdef TICOFF
2961
#undef ALIGN_SECTIONS_IN_FILE
2962
#endif
2963
2964
static bool
2965
coff_compute_section_file_positions (bfd * abfd)
2966
32
{
2967
32
  asection *current;
2968
32
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
32
  bool align_adjust;
2970
32
  unsigned int target_index;
2971
#ifdef ALIGN_SECTIONS_IN_FILE
2972
  asection *previous = NULL;
2973
  file_ptr old_sofar;
2974
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
15
  if (coff_data (abfd)->link_info
2980
15
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
13
    {
2982
13
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
13
      if (page_size == 0)
2987
0
  page_size = 1;
2988
13
    }
2989
2
  else
2990
2
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
9
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
1
  if (bfd_get_symcount (abfd) > 0)
3000
0
    {
3001
0
      bfd_size_type sz;
3002
0
      bfd_size_type i, symcount;
3003
0
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
0
  {
3009
0
    coff_symbol_type *cf;
3010
3011
0
    cf = coff_symbol_from (*symp);
3012
0
    if (cf != NULL
3013
0
        && cf->native != NULL
3014
0
        && cf->native->is_sym
3015
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
0
      {
3017
0
        size_t len;
3018
3019
0
        len = strlen (bfd_asymbol_name (*symp));
3020
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
0
      }
3023
0
  }
3024
0
      if (sz > 0)
3025
0
  {
3026
0
    asection *dsec;
3027
3028
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
0
    if (dsec == NULL)
3030
0
      abort ();
3031
0
    dsec->size = sz;
3032
0
    dsec->flags |= SEC_HAS_CONTENTS;
3033
0
  }
3034
0
    }
3035
1
#endif
3036
3037
32
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
5
    abfd->flags |= EXEC_P;
3041
3042
32
  if (abfd->flags & EXEC_P)
3043
20
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
1
  else if (xcoff_data (abfd)->full_aouthdr)
3046
0
    sofar += bfd_coff_aoutsz (abfd);
3047
1
  else
3048
1
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
32
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
1
  for (current = abfd->sections; current != NULL; current = current->next)
3057
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
0
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
32
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
15
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
15
       || page_size < COFF_PAGE_SIZE)
3082
14
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
109
    for (current = abfd->sections; current != NULL; current = current->next)
3087
94
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
15
    if (section_list == NULL)
3093
0
      return false;
3094
3095
15
    i = 0;
3096
109
    for (current = abfd->sections; current != NULL; current = current->next)
3097
94
      {
3098
94
  section_list[i] = current;
3099
94
  ++i;
3100
94
      }
3101
15
    section_list[i] = NULL;
3102
3103
15
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
15
    target_index = 1;
3108
15
    abfd->sections = NULL;
3109
15
    abfd->section_last = NULL;
3110
109
    for (i = 0; i < count; i++)
3111
94
      {
3112
94
  current = section_list[i];
3113
94
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
94
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
94
  else
3130
94
    current->target_index = target_index++;
3131
94
      }
3132
3133
15
    free (section_list);
3134
15
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
1.54k
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1.52k
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
32
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
32
  align_adjust = false;
3154
32
  for (current = abfd->sections;
3155
1.64k
       current != NULL;
3156
1.61k
       current = current->next)
3157
1.61k
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
94
      if (coff_section_data (abfd, current) == NULL)
3162
12
  {
3163
12
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
12
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
12
  }
3169
94
      if (pei_section_data (abfd, current) == NULL)
3170
12
  {
3171
12
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
12
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
12
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
12
  }
3177
94
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
12
  pei_section_data (abfd, current)->virt_size = current->size;
3179
94
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1.61k
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1.50k
  continue;
3184
3185
109
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
90
      if (current->size == 0)
3190
0
  continue;
3191
90
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
#ifdef ALIGN_SECTIONS_IN_FILE
3196
109
      if ((abfd->flags & EXEC_P) != 0)
3197
99
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
99
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
84
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
0
    if ((current->flags & SEC_LOAD) != 0
3232
0
        && (!strcmp (current->name, _TEXT)
3233
0
      || !strcmp (current->name, _DATA))
3234
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
0
      {
3236
0
        bfd_vma align = 4096;
3237
0
        bfd_vma sofar_off = sofar % align;
3238
0
        bfd_vma vma_off = current->vma % align;
3239
3240
0
        if (vma_off > sofar_off)
3241
0
    sofar += vma_off - sofar_off;
3242
0
        else if (vma_off < sofar_off)
3243
0
    sofar += align + vma_off - sofar_off;
3244
0
      }
3245
#endif
3246
99
    if (previous != NULL
3247
99
        && (previous->flags & SEC_LOAD) != 0)
3248
60
      previous->size += sofar - old_sofar;
3249
99
  }
3250
3251
90
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
94
      if ((abfd->flags & D_PAGED) != 0
3257
94
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
90
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
90
      sofar += current->size;
3268
3269
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
109
      if ((abfd->flags & EXEC_P) == 0)
3272
10
  {
3273
10
    bfd_size_type old_size;
3274
3275
10
    old_size = current->size;
3276
10
    current->size = BFD_ALIGN (current->size,
3277
10
             (bfd_vma) 1 << current->alignment_power);
3278
10
    align_adjust = current->size != old_size;
3279
10
    sofar += current->size - old_size;
3280
10
  }
3281
99
      else
3282
99
  {
3283
99
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
84
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
99
    align_adjust = sofar != old_sofar;
3290
99
    current->size += sofar - old_sofar;
3291
99
  }
3292
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
90
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
68
  align_adjust = true;
3300
#endif
3301
3302
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
109
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
#endif
3309
3310
#ifdef ALIGN_SECTIONS_IN_FILE
3311
      previous = current;
3312
#endif
3313
90
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
32
  if (align_adjust)
3321
9
    {
3322
9
      bfd_byte b;
3323
3324
9
      b = 0;
3325
9
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
9
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
9
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
32
  sofar = BFD_ALIGN (sofar,
3334
32
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
32
  obj_relocbase (abfd) = sofar;
3337
32
  abfd->output_has_begun = true;
3338
3339
32
  return true;
3340
15
}
pei-i386.c:coff_compute_section_file_positions
Line
Count
Source
2966
3
{
2967
3
  asection *current;
2968
3
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
3
  bool align_adjust;
2970
3
  unsigned int target_index;
2971
3
#ifdef ALIGN_SECTIONS_IN_FILE
2972
3
  asection *previous = NULL;
2973
3
  file_ptr old_sofar;
2974
3
#endif
2975
2976
3
#ifdef COFF_IMAGE_WITH_PE
2977
3
  unsigned int page_size;
2978
2979
3
  if (coff_data (abfd)->link_info
2980
3
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
3
    {
2982
3
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
3
      if (page_size == 0)
2987
0
  page_size = 1;
2988
3
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
3
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
2
    abfd->flags |= EXEC_P;
3041
3042
3
  if (abfd->flags & EXEC_P)
3043
3
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
3
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
3
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
3
#ifdef COFF_IMAGE_WITH_PE
3065
3
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
3
    unsigned int count;
3073
3
    asection **section_list;
3074
3
    unsigned int i;
3075
3
    bfd_size_type amt;
3076
3077
3
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
3
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
3
       || page_size < COFF_PAGE_SIZE)
3082
2
     abfd->flags &= ~D_PAGED;
3083
3
#endif
3084
3085
3
    count = 0;
3086
16
    for (current = abfd->sections; current != NULL; current = current->next)
3087
13
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
3
    amt = sizeof (struct asection *) * (count + 1);
3091
3
    section_list = (asection **) bfd_malloc (amt);
3092
3
    if (section_list == NULL)
3093
0
      return false;
3094
3095
3
    i = 0;
3096
16
    for (current = abfd->sections; current != NULL; current = current->next)
3097
13
      {
3098
13
  section_list[i] = current;
3099
13
  ++i;
3100
13
      }
3101
3
    section_list[i] = NULL;
3102
3103
3
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
3
    target_index = 1;
3108
3
    abfd->sections = NULL;
3109
3
    abfd->section_last = NULL;
3110
16
    for (i = 0; i < count; i++)
3111
13
      {
3112
13
  current = section_list[i];
3113
13
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
13
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
13
  else
3130
13
    current->target_index = target_index++;
3131
13
      }
3132
3133
3
    free (section_list);
3134
3
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
3
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
3
  align_adjust = false;
3154
3
  for (current = abfd->sections;
3155
16
       current != NULL;
3156
13
       current = current->next)
3157
13
    {
3158
13
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
13
      if (coff_section_data (abfd, current) == NULL)
3162
0
  {
3163
0
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
0
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
0
  }
3169
13
      if (pei_section_data (abfd, current) == NULL)
3170
0
  {
3171
0
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
0
  }
3177
13
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
0
  pei_section_data (abfd, current)->virt_size = current->size;
3179
13
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
13
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1
  continue;
3184
3185
12
      current->rawsize = current->size;
3186
3187
12
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
12
      if (current->size == 0)
3190
0
  continue;
3191
12
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
12
#ifdef ALIGN_SECTIONS_IN_FILE
3196
12
      if ((abfd->flags & EXEC_P) != 0)
3197
12
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
12
    old_sofar = sofar;
3201
3202
12
#ifdef COFF_IMAGE_WITH_PE
3203
12
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
12
    if (previous != NULL
3247
12
        && (previous->flags & SEC_LOAD) != 0)
3248
10
      previous->size += sofar - old_sofar;
3249
12
  }
3250
3251
12
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
12
#ifdef COFF_PAGE_SIZE
3256
12
      if ((abfd->flags & D_PAGED) != 0
3257
12
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
12
#endif
3260
12
      current->filepos = sofar;
3261
3262
12
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
12
      current->size = (current->size + page_size - 1) & -page_size;
3265
12
#endif
3266
3267
12
      sofar += current->size;
3268
3269
12
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
12
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
12
      else
3282
12
  {
3283
12
    old_sofar = sofar;
3284
12
#ifdef COFF_IMAGE_WITH_PE
3285
12
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
12
    align_adjust = sofar != old_sofar;
3290
12
    current->size += sofar - old_sofar;
3291
12
  }
3292
12
#endif
3293
3294
12
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
12
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
12
  align_adjust = true;
3300
12
#endif
3301
3302
12
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
12
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
12
#endif
3309
3310
12
#ifdef ALIGN_SECTIONS_IN_FILE
3311
12
      previous = current;
3312
12
#endif
3313
12
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
3
  if (align_adjust)
3321
2
    {
3322
2
      bfd_byte b;
3323
3324
2
      b = 0;
3325
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
2
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
2
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
3
  sofar = BFD_ALIGN (sofar,
3334
3
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
3
  obj_relocbase (abfd) = sofar;
3337
3
  abfd->output_has_begun = true;
3338
3339
3
  return true;
3340
3
}
pe-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
1
#ifdef COFF_PAGE_SIZE
2993
1
  unsigned int page_size = COFF_PAGE_SIZE;
2994
1
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pei-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
8
{
2967
8
  asection *current;
2968
8
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
8
  bool align_adjust;
2970
8
  unsigned int target_index;
2971
8
#ifdef ALIGN_SECTIONS_IN_FILE
2972
8
  asection *previous = NULL;
2973
8
  file_ptr old_sofar;
2974
8
#endif
2975
2976
8
#ifdef COFF_IMAGE_WITH_PE
2977
8
  unsigned int page_size;
2978
2979
8
  if (coff_data (abfd)->link_info
2980
8
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
8
    {
2982
8
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
8
      if (page_size == 0)
2987
0
  page_size = 1;
2988
8
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
8
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
3
    abfd->flags |= EXEC_P;
3041
3042
8
  if (abfd->flags & EXEC_P)
3043
8
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
8
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
8
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
8
#ifdef COFF_IMAGE_WITH_PE
3065
8
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
8
    unsigned int count;
3073
8
    asection **section_list;
3074
8
    unsigned int i;
3075
8
    bfd_size_type amt;
3076
3077
8
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
8
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
8
       || page_size < COFF_PAGE_SIZE)
3082
8
     abfd->flags &= ~D_PAGED;
3083
8
#endif
3084
3085
8
    count = 0;
3086
83
    for (current = abfd->sections; current != NULL; current = current->next)
3087
75
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
8
    amt = sizeof (struct asection *) * (count + 1);
3091
8
    section_list = (asection **) bfd_malloc (amt);
3092
8
    if (section_list == NULL)
3093
0
      return false;
3094
3095
8
    i = 0;
3096
83
    for (current = abfd->sections; current != NULL; current = current->next)
3097
75
      {
3098
75
  section_list[i] = current;
3099
75
  ++i;
3100
75
      }
3101
8
    section_list[i] = NULL;
3102
3103
8
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
8
    target_index = 1;
3108
8
    abfd->sections = NULL;
3109
8
    abfd->section_last = NULL;
3110
83
    for (i = 0; i < count; i++)
3111
75
      {
3112
75
  current = section_list[i];
3113
75
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
75
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
75
  else
3130
75
    current->target_index = target_index++;
3131
75
      }
3132
3133
8
    free (section_list);
3134
8
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
8
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
8
  align_adjust = false;
3154
8
  for (current = abfd->sections;
3155
83
       current != NULL;
3156
75
       current = current->next)
3157
75
    {
3158
75
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
75
      if (coff_section_data (abfd, current) == NULL)
3162
6
  {
3163
6
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
6
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
6
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
6
  }
3169
75
      if (pei_section_data (abfd, current) == NULL)
3170
6
  {
3171
6
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
6
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
6
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
6
  }
3177
75
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
6
  pei_section_data (abfd, current)->virt_size = current->size;
3179
75
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
75
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
3
  continue;
3184
3185
72
      current->rawsize = current->size;
3186
3187
72
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
72
      if (current->size == 0)
3190
0
  continue;
3191
72
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
72
#ifdef ALIGN_SECTIONS_IN_FILE
3196
72
      if ((abfd->flags & EXEC_P) != 0)
3197
72
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
72
    old_sofar = sofar;
3201
3202
72
#ifdef COFF_IMAGE_WITH_PE
3203
72
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
72
    if (previous != NULL
3247
72
        && (previous->flags & SEC_LOAD) != 0)
3248
39
      previous->size += sofar - old_sofar;
3249
72
  }
3250
3251
72
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
72
#ifdef COFF_PAGE_SIZE
3256
72
      if ((abfd->flags & D_PAGED) != 0
3257
72
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
72
#endif
3260
72
      current->filepos = sofar;
3261
3262
72
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
72
      current->size = (current->size + page_size - 1) & -page_size;
3265
72
#endif
3266
3267
72
      sofar += current->size;
3268
3269
72
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
72
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
72
      else
3282
72
  {
3283
72
    old_sofar = sofar;
3284
72
#ifdef COFF_IMAGE_WITH_PE
3285
72
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
72
    align_adjust = sofar != old_sofar;
3290
72
    current->size += sofar - old_sofar;
3291
72
  }
3292
72
#endif
3293
3294
72
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
72
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
52
  align_adjust = true;
3300
72
#endif
3301
3302
72
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
72
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
72
#endif
3309
3310
72
#ifdef ALIGN_SECTIONS_IN_FILE
3311
72
      previous = current;
3312
72
#endif
3313
72
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
8
  if (align_adjust)
3321
4
    {
3322
4
      bfd_byte b;
3323
3324
4
      b = 0;
3325
4
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
4
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
4
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
8
  sofar = BFD_ALIGN (sofar,
3334
8
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
8
  obj_relocbase (abfd) = sofar;
3337
8
  abfd->output_has_begun = true;
3338
3339
8
  return true;
3340
8
}
coff-x86_64.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
2
#ifdef COFF_PAGE_SIZE
2993
2
  unsigned int page_size = COFF_PAGE_SIZE;
2994
2
#endif
2995
2
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
2
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
2
  {
3137
    /* Set the target_index field.  */
3138
2
    target_index = 1;
3139
2
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
2
  }
3142
2
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
2
       current != NULL;
3156
2
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
coff64-rs6000.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
1
#endif
2996
2997
1
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
1
  if (bfd_get_symcount (abfd) > 0)
3000
0
    {
3001
0
      bfd_size_type sz;
3002
0
      bfd_size_type i, symcount;
3003
0
      asymbol **symp;
3004
3005
0
      sz = 0;
3006
0
      symcount = bfd_get_symcount (abfd);
3007
0
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
0
  {
3009
0
    coff_symbol_type *cf;
3010
3011
0
    cf = coff_symbol_from (*symp);
3012
0
    if (cf != NULL
3013
0
        && cf->native != NULL
3014
0
        && cf->native->is_sym
3015
0
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
0
      {
3017
0
        size_t len;
3018
3019
0
        len = strlen (bfd_asymbol_name (*symp));
3020
0
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
0
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
0
      }
3023
0
  }
3024
0
      if (sz > 0)
3025
0
  {
3026
0
    asection *dsec;
3027
3028
0
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
0
    if (dsec == NULL)
3030
0
      abort ();
3031
0
    dsec->size = sz;
3032
0
    dsec->flags |= SEC_HAS_CONTENTS;
3033
0
  }
3034
0
    }
3035
1
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
1
#ifdef RS6000COFF_C
3045
1
  else if (xcoff_data (abfd)->full_aouthdr)
3046
0
    sofar += bfd_coff_aoutsz (abfd);
3047
1
  else
3048
1
    sofar += SMALL_AOUTSZ;
3049
1
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
1
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
1
  for (current = abfd->sections; current != NULL; current = current->next)
3057
0
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
0
      sofar += bfd_coff_scnhsz (abfd);
3059
1
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
0
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
0
    if ((current->flags & SEC_LOAD) != 0
3232
0
        && (!strcmp (current->name, _TEXT)
3233
0
      || !strcmp (current->name, _DATA))
3234
0
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
0
      {
3236
0
        bfd_vma align = 4096;
3237
0
        bfd_vma sofar_off = sofar % align;
3238
0
        bfd_vma vma_off = current->vma % align;
3239
3240
0
        if (vma_off > sofar_off)
3241
0
    sofar += vma_off - sofar_off;
3242
0
        else if (vma_off < sofar_off)
3243
0
    sofar += align + vma_off - sofar_off;
3244
0
      }
3245
0
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
      if (strcmp (current->name, _LIB) == 0)
3307
  bfd_set_section_vma (current, 0);
3308
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pe-aarch64.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
1
#ifdef COFF_PAGE_SIZE
2993
1
  unsigned int page_size = COFF_PAGE_SIZE;
2994
1
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
2
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
2
       current != NULL;
3156
1
       current = current->next)
3157
1
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
1
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
1
#ifdef ALIGN_SECTIONS_IN_FILE
3196
1
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
1
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
1
#ifdef COFF_PAGE_SIZE
3256
1
      if ((abfd->flags & D_PAGED) != 0
3257
1
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
1
#endif
3260
1
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
1
      sofar += current->size;
3268
3269
1
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
1
      if ((abfd->flags & EXEC_P) == 0)
3272
1
  {
3273
1
    bfd_size_type old_size;
3274
3275
1
    old_size = current->size;
3276
1
    current->size = BFD_ALIGN (current->size,
3277
1
             (bfd_vma) 1 << current->alignment_power);
3278
1
    align_adjust = current->size != old_size;
3279
1
    sofar += current->size - old_size;
3280
1
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
1
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
1
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
1
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
1
#endif
3309
3310
1
#ifdef ALIGN_SECTIONS_IN_FILE
3311
1
      previous = current;
3312
1
#endif
3313
1
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
pei-aarch64.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
2
#ifdef COFF_IMAGE_WITH_PE
2977
2
  unsigned int page_size;
2978
2979
2
  if (coff_data (abfd)->link_info
2980
2
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
0
    {
2982
0
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
0
      if (page_size == 0)
2987
0
  page_size = 1;
2988
0
    }
2989
2
  else
2990
2
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
2
#ifdef COFF_IMAGE_WITH_PE
3065
2
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
2
    unsigned int count;
3073
2
    asection **section_list;
3074
2
    unsigned int i;
3075
2
    bfd_size_type amt;
3076
3077
2
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
2
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
2
       || page_size < COFF_PAGE_SIZE)
3082
2
     abfd->flags &= ~D_PAGED;
3083
2
#endif
3084
3085
2
    count = 0;
3086
6
    for (current = abfd->sections; current != NULL; current = current->next)
3087
4
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
2
    amt = sizeof (struct asection *) * (count + 1);
3091
2
    section_list = (asection **) bfd_malloc (amt);
3092
2
    if (section_list == NULL)
3093
0
      return false;
3094
3095
2
    i = 0;
3096
6
    for (current = abfd->sections; current != NULL; current = current->next)
3097
4
      {
3098
4
  section_list[i] = current;
3099
4
  ++i;
3100
4
      }
3101
2
    section_list[i] = NULL;
3102
3103
2
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
2
    target_index = 1;
3108
2
    abfd->sections = NULL;
3109
2
    abfd->section_last = NULL;
3110
6
    for (i = 0; i < count; i++)
3111
4
      {
3112
4
  current = section_list[i];
3113
4
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
4
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
4
  else
3130
4
    current->target_index = target_index++;
3131
4
      }
3132
3133
2
    free (section_list);
3134
2
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
6
       current != NULL;
3156
4
       current = current->next)
3157
4
    {
3158
4
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
4
      if (coff_section_data (abfd, current) == NULL)
3162
4
  {
3163
4
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
4
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
4
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
4
  }
3169
4
      if (pei_section_data (abfd, current) == NULL)
3170
4
  {
3171
4
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
4
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
4
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
4
  }
3177
4
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
4
  pei_section_data (abfd, current)->virt_size = current->size;
3179
4
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
4
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
4
      current->rawsize = current->size;
3186
3187
4
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
4
      if (current->size == 0)
3190
0
  continue;
3191
4
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
4
#ifdef ALIGN_SECTIONS_IN_FILE
3196
4
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
4
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
4
#ifdef COFF_PAGE_SIZE
3256
4
      if ((abfd->flags & D_PAGED) != 0
3257
4
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
4
#endif
3260
4
      current->filepos = sofar;
3261
3262
4
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
4
      current->size = (current->size + page_size - 1) & -page_size;
3265
4
#endif
3266
3267
4
      sofar += current->size;
3268
3269
4
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
4
      if ((abfd->flags & EXEC_P) == 0)
3272
4
  {
3273
4
    bfd_size_type old_size;
3274
3275
4
    old_size = current->size;
3276
4
    current->size = BFD_ALIGN (current->size,
3277
4
             (bfd_vma) 1 << current->alignment_power);
3278
4
    align_adjust = current->size != old_size;
3279
4
    sofar += current->size - old_size;
3280
4
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
4
#endif
3293
3294
4
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
4
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
4
  align_adjust = true;
3300
4
#endif
3301
3302
4
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
4
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
4
#endif
3309
3310
4
#ifdef ALIGN_SECTIONS_IN_FILE
3311
4
      previous = current;
3312
4
#endif
3313
4
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
2
    {
3322
2
      bfd_byte b;
3323
3324
2
      b = 0;
3325
2
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
2
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
2
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
Unexecuted instantiation: pei-ia64.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-loongarch64.c:coff_compute_section_file_positions
Unexecuted instantiation: cf-i386lynx.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-go32.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-i386.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-rs6000.c:coff_compute_section_file_positions
coff-sh.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
1
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
1
  {
3137
    /* Set the target_index field.  */
3138
1
    target_index = 1;
3139
1
    for (current = abfd->sections; current != NULL; current = current->next)
3140
0
      current->target_index = target_index++;
3141
1
  }
3142
1
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
Unexecuted instantiation: coff-stgo32.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic30.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic4x.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-tic54x.c:coff_compute_section_file_positions
Unexecuted instantiation: coff-z80.c:coff_compute_section_file_positions
coff-z8k.c:coff_compute_section_file_positions
Line
Count
Source
2966
6
{
2967
6
  asection *current;
2968
6
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
6
  bool align_adjust;
2970
6
  unsigned int target_index;
2971
6
#ifdef ALIGN_SECTIONS_IN_FILE
2972
6
  asection *previous = NULL;
2973
6
  file_ptr old_sofar;
2974
6
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
6
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
6
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
6
  if (abfd->flags & EXEC_P)
3043
6
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
6
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
6
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
6
  {
3137
    /* Set the target_index field.  */
3138
6
    target_index = 1;
3139
1.02k
    for (current = abfd->sections; current != NULL; current = current->next)
3140
1.01k
      current->target_index = target_index++;
3141
6
  }
3142
6
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
6
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
6
  align_adjust = false;
3154
6
  for (current = abfd->sections;
3155
1.02k
       current != NULL;
3156
1.01k
       current = current->next)
3157
1.01k
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
1.01k
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
1.00k
  continue;
3184
3185
15
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
15
#ifdef ALIGN_SECTIONS_IN_FILE
3196
15
      if ((abfd->flags & EXEC_P) != 0)
3197
15
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
15
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
15
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
15
    if (previous != NULL
3247
15
        && (previous->flags & SEC_LOAD) != 0)
3248
11
      previous->size += sofar - old_sofar;
3249
15
  }
3250
3251
15
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
#ifdef COFF_PAGE_SIZE
3256
      if ((abfd->flags & D_PAGED) != 0
3257
    && (current->flags & SEC_ALLOC) != 0)
3258
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
#endif
3260
15
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
15
      sofar += current->size;
3268
3269
15
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
15
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
15
      else
3282
15
  {
3283
15
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
15
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
15
#endif
3289
15
    align_adjust = sofar != old_sofar;
3290
15
    current->size += sofar - old_sofar;
3291
15
  }
3292
15
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
15
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
15
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
15
#endif
3309
3310
15
#ifdef ALIGN_SECTIONS_IN_FILE
3311
15
      previous = current;
3312
15
#endif
3313
15
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
6
  if (align_adjust)
3321
1
    {
3322
1
      bfd_byte b;
3323
3324
1
      b = 0;
3325
1
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
1
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
1
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
6
  sofar = BFD_ALIGN (sofar,
3334
6
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
6
  obj_relocbase (abfd) = sofar;
3337
6
  abfd->output_has_begun = true;
3338
3339
6
  return true;
3340
6
}
Unexecuted instantiation: pe-arm-wince.c:coff_compute_section_file_positions
Unexecuted instantiation: pe-arm.c:coff_compute_section_file_positions
pe-i386.c:coff_compute_section_file_positions
Line
Count
Source
2966
3
{
2967
3
  asection *current;
2968
3
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
3
  bool align_adjust;
2970
3
  unsigned int target_index;
2971
3
#ifdef ALIGN_SECTIONS_IN_FILE
2972
3
  asection *previous = NULL;
2973
3
  file_ptr old_sofar;
2974
3
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
3
#ifdef COFF_PAGE_SIZE
2993
3
  unsigned int page_size = COFF_PAGE_SIZE;
2994
3
#endif
2995
3
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
3
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
3
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
3
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
3
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
3
  {
3137
    /* Set the target_index field.  */
3138
3
    target_index = 1;
3139
502
    for (current = abfd->sections; current != NULL; current = current->next)
3140
499
      current->target_index = target_index++;
3141
3
  }
3142
3
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
3
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
3
  align_adjust = false;
3154
3
  for (current = abfd->sections;
3155
502
       current != NULL;
3156
499
       current = current->next)
3157
499
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
499
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
496
  continue;
3184
3185
3
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
3
#ifdef ALIGN_SECTIONS_IN_FILE
3196
3
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
3
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
3
#ifdef COFF_PAGE_SIZE
3256
3
      if ((abfd->flags & D_PAGED) != 0
3257
3
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
3
#endif
3260
3
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
3
      sofar += current->size;
3268
3269
3
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
3
      if ((abfd->flags & EXEC_P) == 0)
3272
3
  {
3273
3
    bfd_size_type old_size;
3274
3275
3
    old_size = current->size;
3276
3
    current->size = BFD_ALIGN (current->size,
3277
3
             (bfd_vma) 1 << current->alignment_power);
3278
3
    align_adjust = current->size != old_size;
3279
3
    sofar += current->size - old_size;
3280
3
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
3
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
3
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
3
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
3
#endif
3309
3310
3
#ifdef ALIGN_SECTIONS_IN_FILE
3311
3
      previous = current;
3312
3
#endif
3313
3
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
3
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
3
  sofar = BFD_ALIGN (sofar,
3334
3
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
3
  obj_relocbase (abfd) = sofar;
3337
3
  abfd->output_has_begun = true;
3338
3339
3
  return true;
3340
3
}
pe-mcore.c:coff_compute_section_file_positions
Line
Count
Source
2966
2
{
2967
2
  asection *current;
2968
2
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
2
  bool align_adjust;
2970
2
  unsigned int target_index;
2971
2
#ifdef ALIGN_SECTIONS_IN_FILE
2972
2
  asection *previous = NULL;
2973
2
  file_ptr old_sofar;
2974
2
#endif
2975
2976
#ifdef COFF_IMAGE_WITH_PE
2977
  unsigned int page_size;
2978
2979
  if (coff_data (abfd)->link_info
2980
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
    {
2982
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
      if (page_size == 0)
2987
  page_size = 1;
2988
    }
2989
  else
2990
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
2
#ifdef COFF_PAGE_SIZE
2993
2
  unsigned int page_size = COFF_PAGE_SIZE;
2994
2
#endif
2995
2
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
2
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
2
  if (abfd->flags & EXEC_P)
3043
1
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
2
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
2
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
#ifdef COFF_IMAGE_WITH_PE
3065
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
    unsigned int count;
3073
    asection **section_list;
3074
    unsigned int i;
3075
    bfd_size_type amt;
3076
3077
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
       || page_size < COFF_PAGE_SIZE)
3082
     abfd->flags &= ~D_PAGED;
3083
#endif
3084
3085
    count = 0;
3086
    for (current = abfd->sections; current != NULL; current = current->next)
3087
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
    amt = sizeof (struct asection *) * (count + 1);
3091
    section_list = (asection **) bfd_malloc (amt);
3092
    if (section_list == NULL)
3093
      return false;
3094
3095
    i = 0;
3096
    for (current = abfd->sections; current != NULL; current = current->next)
3097
      {
3098
  section_list[i] = current;
3099
  ++i;
3100
      }
3101
    section_list[i] = NULL;
3102
3103
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
    target_index = 1;
3108
    abfd->sections = NULL;
3109
    abfd->section_last = NULL;
3110
    for (i = 0; i < count; i++)
3111
      {
3112
  current = section_list[i];
3113
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
  if (current->size == 0)
3121
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
      current->target_index = 1;
3128
    }
3129
  else
3130
    current->target_index = target_index++;
3131
      }
3132
3133
    free (section_list);
3134
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
2
  {
3137
    /* Set the target_index field.  */
3138
2
    target_index = 1;
3139
9
    for (current = abfd->sections; current != NULL; current = current->next)
3140
7
      current->target_index = target_index++;
3141
2
  }
3142
2
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
2
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
2
  align_adjust = false;
3154
2
  for (current = abfd->sections;
3155
9
       current != NULL;
3156
7
       current = current->next)
3157
7
    {
3158
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
      if (coff_section_data (abfd, current) == NULL)
3162
  {
3163
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
    if (current->used_by_bfd == NULL)
3167
      return false;
3168
  }
3169
      if (pei_section_data (abfd, current) == NULL)
3170
  {
3171
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
      return false;
3176
  }
3177
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
  pei_section_data (abfd, current)->virt_size = current->size;
3179
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
7
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
7
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
      if (current->size == 0)
3190
  continue;
3191
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
#ifdef COFF_IMAGE_WITH_PE
3203
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
0
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
      current->size = (current->size + page_size - 1) & -page_size;
3265
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
#ifdef COFF_IMAGE_WITH_PE
3285
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
0
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
0
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
  align_adjust = true;
3300
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
2
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
2
  sofar = BFD_ALIGN (sofar,
3334
2
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
2
  obj_relocbase (abfd) = sofar;
3337
2
  abfd->output_has_begun = true;
3338
3339
2
  return true;
3340
2
}
Unexecuted instantiation: pe-sh.c:coff_compute_section_file_positions
pei-arm-wince.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
1
#ifdef COFF_IMAGE_WITH_PE
2977
1
  unsigned int page_size;
2978
2979
1
  if (coff_data (abfd)->link_info
2980
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
1
    {
2982
1
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
1
      if (page_size == 0)
2987
0
  page_size = 1;
2988
1
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
1
#ifdef COFF_IMAGE_WITH_PE
3065
1
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
1
    unsigned int count;
3073
1
    asection **section_list;
3074
1
    unsigned int i;
3075
1
    bfd_size_type amt;
3076
3077
1
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
1
       || page_size < COFF_PAGE_SIZE)
3082
1
     abfd->flags &= ~D_PAGED;
3083
1
#endif
3084
3085
1
    count = 0;
3086
3
    for (current = abfd->sections; current != NULL; current = current->next)
3087
2
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
1
    amt = sizeof (struct asection *) * (count + 1);
3091
1
    section_list = (asection **) bfd_malloc (amt);
3092
1
    if (section_list == NULL)
3093
0
      return false;
3094
3095
1
    i = 0;
3096
3
    for (current = abfd->sections; current != NULL; current = current->next)
3097
2
      {
3098
2
  section_list[i] = current;
3099
2
  ++i;
3100
2
      }
3101
1
    section_list[i] = NULL;
3102
3103
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
1
    target_index = 1;
3108
1
    abfd->sections = NULL;
3109
1
    abfd->section_last = NULL;
3110
3
    for (i = 0; i < count; i++)
3111
2
      {
3112
2
  current = section_list[i];
3113
2
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
2
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
2
  else
3130
2
    current->target_index = target_index++;
3131
2
      }
3132
3133
1
    free (section_list);
3134
1
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
3
       current != NULL;
3156
2
       current = current->next)
3157
2
    {
3158
2
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
2
      if (coff_section_data (abfd, current) == NULL)
3162
2
  {
3163
2
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
2
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
2
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
2
  }
3169
2
      if (pei_section_data (abfd, current) == NULL)
3170
2
  {
3171
2
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
2
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
2
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
2
  }
3177
2
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
2
  pei_section_data (abfd, current)->virt_size = current->size;
3179
2
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
2
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
2
      current->rawsize = current->size;
3186
3187
2
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
2
      if (current->size == 0)
3190
0
  continue;
3191
2
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
2
#ifdef ALIGN_SECTIONS_IN_FILE
3196
2
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
2
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
2
#ifdef COFF_PAGE_SIZE
3256
2
      if ((abfd->flags & D_PAGED) != 0
3257
2
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
2
#endif
3260
2
      current->filepos = sofar;
3261
3262
2
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
2
      current->size = (current->size + page_size - 1) & -page_size;
3265
2
#endif
3266
3267
2
      sofar += current->size;
3268
3269
2
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
2
      if ((abfd->flags & EXEC_P) == 0)
3272
2
  {
3273
2
    bfd_size_type old_size;
3274
3275
2
    old_size = current->size;
3276
2
    current->size = BFD_ALIGN (current->size,
3277
2
             (bfd_vma) 1 << current->alignment_power);
3278
2
    align_adjust = current->size != old_size;
3279
2
    sofar += current->size - old_size;
3280
2
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
2
#endif
3293
3294
2
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
2
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
0
  align_adjust = true;
3300
2
#endif
3301
3302
2
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
2
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
2
#endif
3309
3310
2
#ifdef ALIGN_SECTIONS_IN_FILE
3311
2
      previous = current;
3312
2
#endif
3313
2
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
Unexecuted instantiation: pei-arm.c:coff_compute_section_file_positions
Unexecuted instantiation: pei-mcore.c:coff_compute_section_file_positions
pei-sh.c:coff_compute_section_file_positions
Line
Count
Source
2966
1
{
2967
1
  asection *current;
2968
1
  file_ptr sofar = bfd_coff_filhsz (abfd);
2969
1
  bool align_adjust;
2970
1
  unsigned int target_index;
2971
1
#ifdef ALIGN_SECTIONS_IN_FILE
2972
1
  asection *previous = NULL;
2973
1
  file_ptr old_sofar;
2974
1
#endif
2975
2976
1
#ifdef COFF_IMAGE_WITH_PE
2977
1
  unsigned int page_size;
2978
2979
1
  if (coff_data (abfd)->link_info
2980
1
      || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
2981
1
    {
2982
1
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
2983
2984
      /* If no file alignment has been set, default to one.
2985
   This repairs 'ld -r' for arm-wince-pe target.  */
2986
1
      if (page_size == 0)
2987
0
  page_size = 1;
2988
1
    }
2989
0
  else
2990
0
    page_size = PE_DEF_FILE_ALIGNMENT;
2991
#else
2992
#ifdef COFF_PAGE_SIZE
2993
  unsigned int page_size = COFF_PAGE_SIZE;
2994
#endif
2995
#endif
2996
2997
#ifdef RS6000COFF_C
2998
  /* On XCOFF, if we have symbols, set up the .debug section.  */
2999
  if (bfd_get_symcount (abfd) > 0)
3000
    {
3001
      bfd_size_type sz;
3002
      bfd_size_type i, symcount;
3003
      asymbol **symp;
3004
3005
      sz = 0;
3006
      symcount = bfd_get_symcount (abfd);
3007
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
3008
  {
3009
    coff_symbol_type *cf;
3010
3011
    cf = coff_symbol_from (*symp);
3012
    if (cf != NULL
3013
        && cf->native != NULL
3014
        && cf->native->is_sym
3015
        && SYMNAME_IN_DEBUG (&cf->native->u.syment))
3016
      {
3017
        size_t len;
3018
3019
        len = strlen (bfd_asymbol_name (*symp));
3020
        if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
3021
    sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
3022
      }
3023
  }
3024
      if (sz > 0)
3025
  {
3026
    asection *dsec;
3027
3028
    dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
3029
    if (dsec == NULL)
3030
      abort ();
3031
    dsec->size = sz;
3032
    dsec->flags |= SEC_HAS_CONTENTS;
3033
  }
3034
    }
3035
#endif
3036
3037
1
  if (bfd_get_start_address (abfd))
3038
    /*  A start address may have been added to the original file. In this
3039
  case it will need an optional header to record it.  */
3040
0
    abfd->flags |= EXEC_P;
3041
3042
1
  if (abfd->flags & EXEC_P)
3043
0
    sofar += bfd_coff_aoutsz (abfd);
3044
#ifdef RS6000COFF_C
3045
  else if (xcoff_data (abfd)->full_aouthdr)
3046
    sofar += bfd_coff_aoutsz (abfd);
3047
  else
3048
    sofar += SMALL_AOUTSZ;
3049
#endif
3050
3051
1
  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
3052
3053
#ifdef RS6000COFF_C
3054
  /* XCOFF handles overflows in the reloc and line number count fields
3055
     by allocating a new section header to hold the correct counts.  */
3056
  for (current = abfd->sections; current != NULL; current = current->next)
3057
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3058
      sofar += bfd_coff_scnhsz (abfd);
3059
#endif
3060
3061
1
  if (coff_data (abfd)->section_by_target_index)
3062
0
    htab_empty (coff_data (abfd)->section_by_target_index);
3063
3064
1
#ifdef COFF_IMAGE_WITH_PE
3065
1
  {
3066
    /* PE requires the sections to be in memory order when listed in
3067
       the section headers.  It also does not like empty loadable
3068
       sections.  The sections apparently do not have to be in the
3069
       right order in the image file itself, but we do need to get the
3070
       target_index values right.  */
3071
3072
1
    unsigned int count;
3073
1
    asection **section_list;
3074
1
    unsigned int i;
3075
1
    bfd_size_type amt;
3076
3077
1
#ifdef COFF_PAGE_SIZE
3078
    /* Clear D_PAGED if section / file alignment aren't suitable for
3079
       paging at COFF_PAGE_SIZE granularity.  */
3080
1
   if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE
3081
1
       || page_size < COFF_PAGE_SIZE)
3082
1
     abfd->flags &= ~D_PAGED;
3083
1
#endif
3084
3085
1
    count = 0;
3086
1
    for (current = abfd->sections; current != NULL; current = current->next)
3087
0
      ++count;
3088
3089
    /* We allocate an extra cell to simplify the final loop.  */
3090
1
    amt = sizeof (struct asection *) * (count + 1);
3091
1
    section_list = (asection **) bfd_malloc (amt);
3092
1
    if (section_list == NULL)
3093
0
      return false;
3094
3095
1
    i = 0;
3096
1
    for (current = abfd->sections; current != NULL; current = current->next)
3097
0
      {
3098
0
  section_list[i] = current;
3099
0
  ++i;
3100
0
      }
3101
1
    section_list[i] = NULL;
3102
3103
1
    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
3104
3105
    /* Rethread the linked list into sorted order; at the same time,
3106
       assign target_index values.  */
3107
1
    target_index = 1;
3108
1
    abfd->sections = NULL;
3109
1
    abfd->section_last = NULL;
3110
1
    for (i = 0; i < count; i++)
3111
0
      {
3112
0
  current = section_list[i];
3113
0
  bfd_section_list_append (abfd, current);
3114
3115
  /* Later, if the section has zero size, we'll be throwing it
3116
     away, so we don't want to number it now.  Note that having
3117
     a zero size and having real contents are different
3118
     concepts: .bss has no contents, but (usually) non-zero
3119
     size.  */
3120
0
  if (current->size == 0)
3121
0
    {
3122
      /* Discard.  However, it still might have (valid) symbols
3123
         in it, so arbitrarily set it to section 1 (indexing is
3124
         1-based here; usually .text).  __end__ and other
3125
         contents of .endsection really have this happen.
3126
         FIXME: This seems somewhat dubious.  */
3127
0
      current->target_index = 1;
3128
0
    }
3129
0
  else
3130
0
    current->target_index = target_index++;
3131
0
      }
3132
3133
1
    free (section_list);
3134
1
  }
3135
#else /* ! COFF_IMAGE_WITH_PE */
3136
  {
3137
    /* Set the target_index field.  */
3138
    target_index = 1;
3139
    for (current = abfd->sections; current != NULL; current = current->next)
3140
      current->target_index = target_index++;
3141
  }
3142
#endif /* ! COFF_IMAGE_WITH_PE */
3143
3144
1
  if (target_index >= bfd_coff_max_nscns (abfd))
3145
0
    {
3146
0
      bfd_set_error (bfd_error_file_too_big);
3147
0
      _bfd_error_handler
3148
  /* xgettext:c-format */
3149
0
  (_("%pB: too many sections (%d)"), abfd, target_index);
3150
0
      return false;
3151
0
    }
3152
3153
1
  align_adjust = false;
3154
1
  for (current = abfd->sections;
3155
1
       current != NULL;
3156
1
       current = current->next)
3157
0
    {
3158
0
#ifdef COFF_IMAGE_WITH_PE
3159
      /* With PE we have to pad each section to be a multiple of its
3160
   page size too, and remember both sizes.  */
3161
0
      if (coff_section_data (abfd, current) == NULL)
3162
0
  {
3163
0
    size_t amt = sizeof (struct coff_section_tdata);
3164
3165
0
    current->used_by_bfd = bfd_zalloc (abfd, amt);
3166
0
    if (current->used_by_bfd == NULL)
3167
0
      return false;
3168
0
  }
3169
0
      if (pei_section_data (abfd, current) == NULL)
3170
0
  {
3171
0
    size_t amt = sizeof (struct pei_section_tdata);
3172
3173
0
    coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
3174
0
    if (coff_section_data (abfd, current)->tdata == NULL)
3175
0
      return false;
3176
0
  }
3177
0
      if (pei_section_data (abfd, current)->virt_size == 0)
3178
0
  pei_section_data (abfd, current)->virt_size = current->size;
3179
0
#endif
3180
3181
      /* Only deal with sections which have contents.  */
3182
0
      if (!(current->flags & SEC_HAS_CONTENTS))
3183
0
  continue;
3184
3185
0
      current->rawsize = current->size;
3186
3187
0
#ifdef COFF_IMAGE_WITH_PE
3188
      /* Make sure we skip empty sections in a PE image.  */
3189
0
      if (current->size == 0)
3190
0
  continue;
3191
0
#endif
3192
3193
      /* Align the sections in the file to the same boundary on
3194
   which they are aligned in virtual memory.  */
3195
0
#ifdef ALIGN_SECTIONS_IN_FILE
3196
0
      if ((abfd->flags & EXEC_P) != 0)
3197
0
  {
3198
    /* Make sure this section is aligned on the right boundary - by
3199
       padding the previous section up if necessary.  */
3200
0
    old_sofar = sofar;
3201
3202
0
#ifdef COFF_IMAGE_WITH_PE
3203
0
    sofar = BFD_ALIGN (sofar, page_size);
3204
#else
3205
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3206
#endif
3207
3208
#ifdef RS6000COFF_C
3209
    /* Make sure the file offset and the vma of .text/.data are at the
3210
       same page offset, so that the file can be mmap'ed without being
3211
       relocated.  Failing that, AIX is able to load and execute the
3212
       program, but it will be silently relocated (possible as
3213
       executables are PIE).  But the relocation is slightly costly and
3214
       complexify the use of addr2line or gdb.  So better to avoid it,
3215
       like does the native linker.  Usually gnu ld makes sure that
3216
       the vma of .text is the file offset so this issue shouldn't
3217
       appear unless you are stripping such an executable.
3218
3219
       AIX loader checks the text section alignment of (vma - filepos),
3220
       and the native linker doesn't try to align the text sections.
3221
       For example:
3222
3223
       0 .text       000054cc  10000128  10000128  00000128  2**5
3224
           CONTENTS, ALLOC, LOAD, CODE
3225
3226
       Don't perform the above tweak if the previous one is .tdata,
3227
       as it will increase the memory allocated for every threads
3228
       created and not just improve performances with gdb.
3229
    */
3230
3231
    if ((current->flags & SEC_LOAD) != 0
3232
        && (!strcmp (current->name, _TEXT)
3233
      || !strcmp (current->name, _DATA))
3234
        && (previous == NULL || strcmp(previous->name, _TDATA)))
3235
      {
3236
        bfd_vma align = 4096;
3237
        bfd_vma sofar_off = sofar % align;
3238
        bfd_vma vma_off = current->vma % align;
3239
3240
        if (vma_off > sofar_off)
3241
    sofar += vma_off - sofar_off;
3242
        else if (vma_off < sofar_off)
3243
    sofar += align + vma_off - sofar_off;
3244
      }
3245
#endif
3246
0
    if (previous != NULL
3247
0
        && (previous->flags & SEC_LOAD) != 0)
3248
0
      previous->size += sofar - old_sofar;
3249
0
  }
3250
3251
0
#endif
3252
3253
      /* In demand paged files the low order bits of the file offset
3254
   must match the low order bits of the virtual address.  */
3255
0
#ifdef COFF_PAGE_SIZE
3256
0
      if ((abfd->flags & D_PAGED) != 0
3257
0
    && (current->flags & SEC_ALLOC) != 0)
3258
0
  sofar += (current->vma - (bfd_vma) sofar) % page_size;
3259
0
#endif
3260
0
      current->filepos = sofar;
3261
3262
0
#ifdef COFF_IMAGE_WITH_PE
3263
      /* Set the padded size.  */
3264
0
      current->size = (current->size + page_size - 1) & -page_size;
3265
0
#endif
3266
3267
0
      sofar += current->size;
3268
3269
0
#ifdef ALIGN_SECTIONS_IN_FILE
3270
      /* Make sure that this section is of the right size too.  */
3271
0
      if ((abfd->flags & EXEC_P) == 0)
3272
0
  {
3273
0
    bfd_size_type old_size;
3274
3275
0
    old_size = current->size;
3276
0
    current->size = BFD_ALIGN (current->size,
3277
0
             (bfd_vma) 1 << current->alignment_power);
3278
0
    align_adjust = current->size != old_size;
3279
0
    sofar += current->size - old_size;
3280
0
  }
3281
0
      else
3282
0
  {
3283
0
    old_sofar = sofar;
3284
0
#ifdef COFF_IMAGE_WITH_PE
3285
0
    sofar = BFD_ALIGN (sofar, page_size);
3286
#else
3287
    sofar = BFD_ALIGN (sofar, (bfd_vma) 1 << current->alignment_power);
3288
#endif
3289
0
    align_adjust = sofar != old_sofar;
3290
0
    current->size += sofar - old_sofar;
3291
0
  }
3292
0
#endif
3293
3294
0
#ifdef COFF_IMAGE_WITH_PE
3295
      /* For PE we need to make sure we pad out to the aligned
3296
   size, in case the caller only writes out data to the
3297
   unaligned size.  */
3298
0
      if (pei_section_data (abfd, current)->virt_size < current->size)
3299
0
  align_adjust = true;
3300
0
#endif
3301
3302
0
#ifdef _LIB
3303
      /* Force .lib sections to start at zero.  The vma is then
3304
   incremented in coff_set_section_contents.  This is right for
3305
   SVR3.2.  */
3306
0
      if (strcmp (current->name, _LIB) == 0)
3307
0
  bfd_set_section_vma (current, 0);
3308
0
#endif
3309
3310
0
#ifdef ALIGN_SECTIONS_IN_FILE
3311
0
      previous = current;
3312
0
#endif
3313
0
    }
3314
3315
  /* It is now safe to write to the output file.  If we needed an
3316
     alignment adjustment for the last section, then make sure that
3317
     there is a byte at offset sofar.  If there are no symbols and no
3318
     relocs, then nothing follows the last section.  If we don't force
3319
     the last byte out, then the file may appear to be truncated.  */
3320
1
  if (align_adjust)
3321
0
    {
3322
0
      bfd_byte b;
3323
3324
0
      b = 0;
3325
0
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
3326
0
    || bfd_write (&b, 1, abfd) != 1)
3327
0
  return false;
3328
0
    }
3329
3330
  /* Make sure the relocations are aligned.  We don't need to make
3331
     sure that this byte exists, because it will only matter if there
3332
     really are relocs.  */
3333
1
  sofar = BFD_ALIGN (sofar,
3334
1
         (bfd_vma) 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
3335
3336
1
  obj_relocbase (abfd) = sofar;
3337
1
  abfd->output_has_begun = true;
3338
3339
1
  return true;
3340
1
}
3341
3342
#ifdef COFF_IMAGE_WITH_PE
3343
3344
static bool
3345
coff_read_word (bfd *abfd, unsigned int *value, unsigned int *pelength)
3346
11
{
3347
11
  unsigned char b[2];
3348
11
  int status;
3349
3350
11
  status = bfd_read (b, 2, abfd);
3351
11
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
11
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
11
  else
3360
11
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
11
  *pelength += status;
3363
3364
11
  return true;
3365
11
}
pei-i386.c:coff_read_word
Line
Count
Source
3346
3
{
3347
3
  unsigned char b[2];
3348
3
  int status;
3349
3350
3
  status = bfd_read (b, 2, abfd);
3351
3
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
3
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
3
  else
3360
3
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
3
  *pelength += status;
3363
3364
3
  return true;
3365
3
}
pei-x86_64.c:coff_read_word
Line
Count
Source
3346
8
{
3347
8
  unsigned char b[2];
3348
8
  int status;
3349
3350
8
  status = bfd_read (b, 2, abfd);
3351
8
  if (status < 1)
3352
0
    {
3353
0
      *value = 0;
3354
0
      return false;
3355
0
    }
3356
3357
8
  if (status == 1)
3358
0
    *value = (unsigned int) b[0];
3359
8
  else
3360
8
    *value = (unsigned int) (b[0] + (b[1] << 8));
3361
3362
8
  *pelength += status;
3363
3364
8
  return true;
3365
8
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word
Unexecuted instantiation: pei-ia64.c:coff_read_word
Unexecuted instantiation: pei-loongarch64.c:coff_read_word
Unexecuted instantiation: pei-arm-wince.c:coff_read_word
Unexecuted instantiation: pei-arm.c:coff_read_word
Unexecuted instantiation: pei-mcore.c:coff_read_word
Unexecuted instantiation: pei-sh.c:coff_read_word
3366
3367
/* Read a two byte number from buffer B returning the result in VALUE.
3368
   No more than BUF_SIZE bytes will be read.
3369
   Returns true upobn success, false otherwise.
3370
   If successful, increases the value stored in PELENGTH by the number
3371
   of bytes read.  */
3372
3373
static bool
3374
coff_read_word_from_buffer (unsigned char *  b,
3375
          int              buf_size,
3376
                            unsigned int *   value,
3377
          unsigned int *   pelength)
3378
322k
{
3379
322k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
322k
  if (buf_size == 1)
3386
4
    {
3387
4
      *value = (unsigned int)b[0];
3388
4
      *pelength += 1;
3389
4
    }
3390
322k
  else
3391
322k
    {
3392
322k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
322k
      *pelength += 2;
3394
322k
    }
3395
3396
322k
  return true;
3397
322k
}
pei-i386.c:coff_read_word_from_buffer
Line
Count
Source
3378
218k
{
3379
218k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
218k
  if (buf_size == 1)
3386
1
    {
3387
1
      *value = (unsigned int)b[0];
3388
1
      *pelength += 1;
3389
1
    }
3390
218k
  else
3391
218k
    {
3392
218k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
218k
      *pelength += 2;
3394
218k
    }
3395
3396
218k
  return true;
3397
218k
}
pei-x86_64.c:coff_read_word_from_buffer
Line
Count
Source
3378
103k
{
3379
103k
  if (buf_size < 1)
3380
0
    {
3381
0
      *value = 0;
3382
0
      return false;
3383
0
    }
3384
3385
103k
  if (buf_size == 1)
3386
3
    {
3387
3
      *value = (unsigned int)b[0];
3388
3
      *pelength += 1;
3389
3
    }
3390
103k
  else
3391
103k
    {
3392
103k
      *value = (unsigned int)(b[0] + (b[1] << 8));
3393
103k
      *pelength += 2;
3394
103k
    }
3395
3396
103k
  return true;
3397
103k
}
Unexecuted instantiation: pei-aarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-ia64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-loongarch64.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm-wince.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-arm.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-mcore.c:coff_read_word_from_buffer
Unexecuted instantiation: pei-sh.c:coff_read_word_from_buffer
3398
3399
33
#define COFF_CHECKSUM_BUFFER_SIZE 0x800000
3400
3401
static unsigned int
3402
coff_compute_checksum (bfd *abfd, unsigned int *pelength)
3403
11
{
3404
11
  file_ptr filepos;
3405
11
  unsigned int value;
3406
11
  unsigned int total;
3407
11
  unsigned char *buf;
3408
11
  int buf_size;
3409
3410
11
  total = 0;
3411
11
  *pelength = 0;
3412
11
  filepos = (file_ptr) 0;
3413
11
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
11
  if (buf == NULL)
3415
0
    return 0;
3416
11
  buf_size = 0;
3417
3418
11
  do
3419
22
    {
3420
22
      unsigned char *cur_buf;
3421
22
      int cur_buf_size;
3422
3423
22
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
22
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
22
      cur_buf_size = buf_size;
3428
22
      cur_buf = buf;
3429
3430
322k
      while (cur_buf_size > 0)
3431
322k
        {
3432
322k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
322k
          cur_buf += 2;
3434
322k
          cur_buf_size -= 2;
3435
322k
          total += value;
3436
322k
          total = 0xffff & (total + (total >> 0x10));
3437
322k
        }
3438
3439
22
      filepos += buf_size;
3440
22
    }
3441
22
  while (buf_size > 0);
3442
3443
11
  free (buf);
3444
3445
11
  return (0xffff & (total + (total >> 0x10)));
3446
11
}
pei-i386.c:coff_compute_checksum
Line
Count
Source
3403
3
{
3404
3
  file_ptr filepos;
3405
3
  unsigned int value;
3406
3
  unsigned int total;
3407
3
  unsigned char *buf;
3408
3
  int buf_size;
3409
3410
3
  total = 0;
3411
3
  *pelength = 0;
3412
3
  filepos = (file_ptr) 0;
3413
3
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
3
  if (buf == NULL)
3415
0
    return 0;
3416
3
  buf_size = 0;
3417
3418
3
  do
3419
6
    {
3420
6
      unsigned char *cur_buf;
3421
6
      int cur_buf_size;
3422
3423
6
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
6
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
6
      cur_buf_size = buf_size;
3428
6
      cur_buf = buf;
3429
3430
218k
      while (cur_buf_size > 0)
3431
218k
        {
3432
218k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
218k
          cur_buf += 2;
3434
218k
          cur_buf_size -= 2;
3435
218k
          total += value;
3436
218k
          total = 0xffff & (total + (total >> 0x10));
3437
218k
        }
3438
3439
6
      filepos += buf_size;
3440
6
    }
3441
6
  while (buf_size > 0);
3442
3443
3
  free (buf);
3444
3445
3
  return (0xffff & (total + (total >> 0x10)));
3446
3
}
pei-x86_64.c:coff_compute_checksum
Line
Count
Source
3403
8
{
3404
8
  file_ptr filepos;
3405
8
  unsigned int value;
3406
8
  unsigned int total;
3407
8
  unsigned char *buf;
3408
8
  int buf_size;
3409
3410
8
  total = 0;
3411
8
  *pelength = 0;
3412
8
  filepos = (file_ptr) 0;
3413
8
  buf = (unsigned char *) bfd_malloc (COFF_CHECKSUM_BUFFER_SIZE);
3414
8
  if (buf == NULL)
3415
0
    return 0;
3416
8
  buf_size = 0;
3417
3418
8
  do
3419
16
    {
3420
16
      unsigned char *cur_buf;
3421
16
      int cur_buf_size;
3422
3423
16
      if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
3424
0
  return 0;
3425
3426
16
      buf_size = bfd_read (buf, COFF_CHECKSUM_BUFFER_SIZE, abfd);
3427
16
      cur_buf_size = buf_size;
3428
16
      cur_buf = buf;
3429
3430
103k
      while (cur_buf_size > 0)
3431
103k
        {
3432
103k
          coff_read_word_from_buffer (cur_buf, cur_buf_size, &value, pelength);
3433
103k
          cur_buf += 2;
3434
103k
          cur_buf_size -= 2;
3435
103k
          total += value;
3436
103k
          total = 0xffff & (total + (total >> 0x10));
3437
103k
        }
3438
3439
16
      filepos += buf_size;
3440
16
    }
3441
16
  while (buf_size > 0);
3442
3443
8
  free (buf);
3444
3445
8
  return (0xffff & (total + (total >> 0x10)));
3446
8
}
Unexecuted instantiation: pei-aarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-ia64.c:coff_compute_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_compute_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_compute_checksum
Unexecuted instantiation: pei-arm.c:coff_compute_checksum
Unexecuted instantiation: pei-mcore.c:coff_compute_checksum
Unexecuted instantiation: pei-sh.c:coff_compute_checksum
3447
3448
static bool
3449
coff_apply_checksum (bfd *abfd)
3450
11
{
3451
11
  unsigned int computed;
3452
11
  unsigned int checksum = 0;
3453
11
  unsigned int peheader;
3454
11
  unsigned int pelength;
3455
3456
11
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
11
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
11
  checksum = 0;
3466
11
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
11
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
11
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
11
  checksum = computed + pelength;
3475
3476
11
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
11
  return bfd_write (&checksum, 4, abfd) == 4;
3480
11
}
pei-i386.c:coff_apply_checksum
Line
Count
Source
3450
3
{
3451
3
  unsigned int computed;
3452
3
  unsigned int checksum = 0;
3453
3
  unsigned int peheader;
3454
3
  unsigned int pelength;
3455
3456
3
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
3
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
3
  checksum = 0;
3466
3
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
3
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
3
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
3
  checksum = computed + pelength;
3475
3476
3
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
3
  return bfd_write (&checksum, 4, abfd) == 4;
3480
3
}
pei-x86_64.c:coff_apply_checksum
Line
Count
Source
3450
8
{
3451
8
  unsigned int computed;
3452
8
  unsigned int checksum = 0;
3453
8
  unsigned int peheader;
3454
8
  unsigned int pelength;
3455
3456
8
  if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
3457
0
    return false;
3458
3459
8
  if (!coff_read_word (abfd, &peheader, &pelength))
3460
0
    return false;
3461
3462
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3463
0
    return false;
3464
3465
8
  checksum = 0;
3466
8
  if (bfd_write (&checksum, 4, abfd) != 4)
3467
0
    return false;
3468
3469
8
  if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
3470
0
    return false;
3471
3472
8
  computed = coff_compute_checksum (abfd, &pelength);
3473
3474
8
  checksum = computed + pelength;
3475
3476
8
  if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
3477
0
    return false;
3478
3479
8
  return bfd_write (&checksum, 4, abfd) == 4;
3480
8
}
Unexecuted instantiation: pei-aarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-ia64.c:coff_apply_checksum
Unexecuted instantiation: pei-loongarch64.c:coff_apply_checksum
Unexecuted instantiation: pei-arm-wince.c:coff_apply_checksum
Unexecuted instantiation: pei-arm.c:coff_apply_checksum
Unexecuted instantiation: pei-mcore.c:coff_apply_checksum
Unexecuted instantiation: pei-sh.c:coff_apply_checksum
3481
3482
#endif /* COFF_IMAGE_WITH_PE */
3483
3484
static bool
3485
coff_write_object_contents (bfd * abfd)
3486
29
{
3487
29
  asection *current;
3488
29
  bool hasrelocs = false;
3489
29
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
29
  file_ptr scn_base;
3494
29
  file_ptr reloc_base;
3495
29
  file_ptr lineno_base;
3496
29
  file_ptr sym_base;
3497
29
  unsigned long reloc_size = 0, reloc_count = 0;
3498
29
  unsigned long lnno_size = 0;
3499
29
  bool long_section_names;
3500
29
  asection *text_sec = NULL;
3501
29
  asection *data_sec = NULL;
3502
29
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
29
  struct internal_filehdr internal_f;
3508
29
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
22
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
29
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
29
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
29
  if (! abfd->output_has_begun)
3520
16
    {
3521
16
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
16
    }
3524
3525
29
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
884
  for (current = abfd->sections; current != NULL; current =
3530
855
       current->next)
3531
855
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
601
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
#endif
3537
855
      reloc_count += current->reloc_count;
3538
855
    }
3539
3540
29
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
29
  lineno_base = reloc_base + reloc_size;
3543
29
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
884
  for (current = abfd->sections; current != NULL; current =
3547
855
       current->next)
3548
855
    {
3549
855
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
855
      else
3556
855
  current->line_filepos = 0;
3557
3558
855
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
855
      else
3569
855
  current->rel_filepos = 0;
3570
855
    }
3571
3572
  /* Write section headers to the file.  */
3573
29
  internal_f.f_nscns = 0;
3574
3575
29
  if ((abfd->flags & EXEC_P) != 0)
3576
17
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
12
  else
3578
12
    {
3579
12
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
0
      if (xcoff_data (abfd)->full_aouthdr)
3583
0
  scn_base += bfd_coff_aoutsz (abfd);
3584
0
      else
3585
0
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
12
    }
3589
3590
29
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
29
  long_section_names = false;
3594
29
  for (current = abfd->sections;
3595
884
       current != NULL;
3596
855
       current = current->next)
3597
855
    {
3598
855
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
94
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
4
  {
3604
4
    is_reloc_section = true;
3605
4
    hasrelocs = true;
3606
4
    pe_data (abfd)->has_reloc_section = 1;
3607
4
  }
3608
#endif
3609
3610
855
      internal_f.f_nscns++;
3611
3612
855
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
601
      if (bfd_coff_long_section_names (abfd))
3618
591
  {
3619
591
    size_t len;
3620
3621
    len = strlen (current->name);
3622
591
    if (len > SCNNMLEN)
3623
31
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
31
        if (string_size < 10000000)
3629
31
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
31
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
31
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
31
    }
3646
0
        else
3647
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
#endif
3668
31
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
0
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
31
        string_size += len + 1;
3683
31
        long_section_names = true;
3684
31
      }
3685
591
  }
3686
601
#endif
3687
3688
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
855
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
855
      else
3694
855
#endif
3695
855
      section.s_vaddr = current->vma;
3696
601
      section.s_paddr = current->lma;
3697
601
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
0
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
      section.s_page = 0;
3702
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
94
      if (coff_section_data (abfd, current) != NULL
3710
94
    && pei_section_data (abfd, current) != NULL)
3711
94
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
855
      if (current->size == 0
3719
855
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
759
  section.s_scnptr = 0;
3721
96
      else
3722
96
  section.s_scnptr = current->filepos;
3723
3724
601
      section.s_relptr = current->rel_filepos;
3725
601
      section.s_lnnoptr = current->line_filepos;
3726
601
      section.s_nreloc = current->reloc_count;
3727
601
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
761
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
#endif
3733
855
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
94
      if ((current->flags & SEC_DEBUGGING) != 0
3737
94
    && ! is_reloc_section)
3738
39
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
0
  {
3746
0
    section.s_nreloc = 0xffff;
3747
0
    section.s_nlnno = 0xffff;
3748
0
  }
3749
#endif
3750
#endif
3751
3752
601
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
855
      if (!strcmp (current->name, _TEXT))
3755
5
  text_sec = current;
3756
850
      else if (!strcmp (current->name, _DATA))
3757
5
  data_sec = current;
3758
845
      else if (!strcmp (current->name, _BSS))
3759
4
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
0
      else if (!strcmp (current->name, _TDATA))
3762
0
  tdata_sec = current;
3763
0
      else if (!strcmp (current->name, _TBSS))
3764
0
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
601
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
601
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
507
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
94
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
94
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
94
      else
3798
94
#endif
3799
94
  {
3800
855
    SCNHDR buff;
3801
855
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
855
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
855
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
94
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
601
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
1
  {
3814
1
    unsigned int i, count;
3815
1
    asymbol **psym;
3816
1
    coff_symbol_type *csym = NULL;
3817
1
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
160
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
159
      {
3823
159
        if ((*psym)->section != current)
3824
159
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
1
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
1
  }
3902
#endif /* COFF_WITH_PE */
3903
601
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
0
  for (current = abfd->sections; current != NULL; current = current->next)
3910
0
    {
3911
0
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
0
  {
3913
0
    struct internal_scnhdr scnhdr;
3914
0
    SCNHDR buff;
3915
0
    bfd_size_type amt;
3916
3917
0
    internal_f.f_nscns++;
3918
0
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
0
    scnhdr.s_paddr = current->reloc_count;
3920
0
    scnhdr.s_vaddr = current->lineno_count;
3921
0
    scnhdr.s_size = 0;
3922
0
    scnhdr.s_scnptr = 0;
3923
0
    scnhdr.s_relptr = current->rel_filepos;
3924
0
    scnhdr.s_lnnoptr = current->line_filepos;
3925
0
    scnhdr.s_nreloc = current->target_index;
3926
0
    scnhdr.s_nlnno = current->target_index;
3927
0
    scnhdr.s_flags = STYP_OVRFLO;
3928
0
    amt = bfd_coff_scnhsz (abfd);
3929
0
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
0
        || bfd_write (& buff, amt, abfd) != amt)
3931
0
      return false;
3932
0
  }
3933
0
    }
3934
0
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
0
  if ((abfd->flags & EXEC_P) != 0)
3940
0
    {
3941
0
      asection *s = abfd->sections;
3942
0
      while (s != NULL && s->filepos == 0)
3943
0
  s = s->next;
3944
0
      if (s != NULL)
3945
0
  {
3946
0
    file_ptr cur_ptr
3947
0
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
0
    file_ptr fill_size = s->filepos - cur_ptr;
3949
0
    if (fill_size > 0)
3950
0
      {
3951
0
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
0
        if (!b)
3953
0
    return false;
3954
0
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
0
    {
3956
0
      free (b);
3957
0
      return false;
3958
0
    }
3959
0
        free (b);
3960
0
      }
3961
0
  }
3962
0
    }
3963
0
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
29
  internal_f.f_timdat = 0;
3974
29
  internal_f.f_flags = 0;
3975
3976
29
  if (abfd->flags & EXEC_P)
3977
17
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
12
  else
3979
12
    {
3980
12
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
0
      if (xcoff_data (abfd)->full_aouthdr)
3984
0
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
0
      else
3986
0
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
12
    }
3990
3991
29
  if (!hasrelocs)
3992
25
    internal_f.f_flags |= F_RELFLG;
3993
29
  if (!haslinno)
3994
29
    internal_f.f_flags |= F_LNNO;
3995
29
  if (abfd->flags & EXEC_P)
3996
17
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
15
  if (! hasdebug)
3999
5
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
15
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
10
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
10
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
7
  if (bfd_little_endian (abfd))
4009
2
    internal_f.f_flags |= F_AR32WR;
4010
5
  else
4011
5
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
0
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
1
  if ((abfd->flags & DYNAMIC) != 0)
4026
0
    internal_f.f_flags |= F_SHROBJ;
4027
1
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
0
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
29
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
29
  {
4035
29
    unsigned int magic = 0;
4036
29
    unsigned short flags = 0;
4037
4038
29
    coff_set_flags (abfd, &magic, &flags);
4039
29
    internal_f.f_magic = magic;
4040
29
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
0
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
1
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
3
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
0
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
0
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
11
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
6
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
0
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
1
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
1
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
1
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
1
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
29
#undef __A_MAGIC_SET__
4112
29
#endif
4113
29
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
  internal_a.vstamp = 0;
4121
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
29
  obj_sym_filepos (abfd) = sym_base;
4125
4126
29
  if (bfd_get_symcount (abfd) != 0)
4127
7
    {
4128
7
      int firstundef;
4129
4130
7
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
7
      coff_mangle_symbols (abfd);
4133
7
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
7
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
7
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
7
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
15
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
1
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
1
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
1
    }
4148
22
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
29
  if (obj_raw_syment_count (abfd) != 0)
4153
7
    {
4154
7
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
0
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
7
    }
4161
22
  else
4162
22
    {
4163
22
      if (long_section_names)
4164
1
  internal_f.f_symptr = sym_base;
4165
21
      else
4166
21
  internal_f.f_symptr = 0;
4167
22
      internal_f.f_flags |= F_LSYMS;
4168
22
    }
4169
4170
29
  if (text_sec)
4171
5
    {
4172
5
      internal_a.tsize = text_sec->size;
4173
5
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
5
    }
4175
29
  if (data_sec)
4176
5
    {
4177
5
      internal_a.dsize = data_sec->size;
4178
5
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
5
    }
4180
29
  if (bss_sec)
4181
4
    {
4182
4
      internal_a.bsize = bss_sec->size;
4183
4
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
4
    }
4186
4187
29
  internal_a.entry = bfd_get_start_address (abfd);
4188
29
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
1
  if (xcoff_data (abfd)->full_aouthdr)
4192
0
    {
4193
0
      bfd_vma toc;
4194
0
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
0
      if (internal_a.o_snentry == 0)
4200
0
  internal_a.entry = (bfd_vma) -1;
4201
4202
0
      if (text_sec != NULL)
4203
0
  {
4204
0
    internal_a.o_sntext = text_sec->target_index;
4205
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
0
  }
4207
0
      else
4208
0
  {
4209
0
    internal_a.o_sntext = 0;
4210
0
    internal_a.o_algntext = 0;
4211
0
  }
4212
0
      if (data_sec != NULL)
4213
0
  {
4214
0
    internal_a.o_sndata = data_sec->target_index;
4215
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
0
  }
4217
0
      else
4218
0
  {
4219
0
    internal_a.o_sndata = 0;
4220
0
    internal_a.o_algndata = 0;
4221
0
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
0
      if (loader_sec != NULL)
4224
0
  internal_a.o_snloader = loader_sec->target_index;
4225
0
      else
4226
0
  internal_a.o_snloader = 0;
4227
0
      if (bss_sec != NULL)
4228
0
  internal_a.o_snbss = bss_sec->target_index;
4229
0
      else
4230
0
  internal_a.o_snbss = 0;
4231
4232
0
      if (tdata_sec != NULL)
4233
0
  {
4234
0
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
0
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
0
  }
4242
0
      else
4243
0
  {
4244
0
    internal_a.o_sntdata = 0;
4245
0
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
0
  }
4250
0
      if (tbss_sec != NULL)
4251
0
    internal_a.o_sntbss = tbss_sec->target_index;
4252
0
      else
4253
0
    internal_a.o_sntbss = 0;
4254
4255
0
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
0
      if (xcoff_data (abfd)->cputype != -1)
4261
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
0
      else
4263
0
  {
4264
0
    switch (bfd_get_arch (abfd))
4265
0
      {
4266
0
      case bfd_arch_rs6000:
4267
0
        internal_a.o_cputype = 4;
4268
0
        break;
4269
0
      case bfd_arch_powerpc:
4270
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
0
    internal_a.o_cputype = 3;
4272
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
0
    internal_a.o_cputype = 2;
4274
0
        else
4275
0
    internal_a.o_cputype = 1;
4276
0
        break;
4277
0
      default:
4278
0
        abort ();
4279
0
      }
4280
0
  }
4281
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
0
    }
4284
1
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
22
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
22
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
29
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
29
  {
4302
29
    char * buff;
4303
29
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
29
    buff = (char *) bfd_malloc (amount);
4306
29
    if (buff == NULL)
4307
0
      return false;
4308
4309
29
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
29
    amount = bfd_write (buff, amount, abfd);
4311
4312
29
    free (buff);
4313
4314
29
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
29
  }
4317
4318
29
  if (abfd->flags & EXEC_P)
4319
17
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
17
      char * buff;
4323
17
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
17
      buff = (char *) bfd_malloc (amount);
4326
17
      if (buff == NULL)
4327
0
  return false;
4328
4329
17
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
12
      amount = bfd_write (buff, amount, abfd);
4331
4332
12
      free (buff);
4333
4334
17
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
11
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
#endif
4341
11
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
0
    {
4346
0
      AOUTHDR buff;
4347
0
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
0
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
0
      if (xcoff_data (abfd)->full_aouthdr)
4352
0
  size = bfd_coff_aoutsz (abfd);
4353
0
      else
4354
0
  size = SMALL_AOUTSZ;
4355
0
      if (bfd_write (&buff, size, abfd) != size)
4356
0
  return false;
4357
0
    }
4358
0
#endif
4359
#endif
4360
4361
29
  return true;
4362
29
}
pei-i386.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
3
#ifdef COFF_IMAGE_WITH_PE
3491
3
  bool hasdebug = false;
3492
3
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
3
#ifdef COFF_LONG_SECTION_NAMES
3510
3
  size_t string_size = STRING_SIZE_SIZE;
3511
3
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
16
  for (current = abfd->sections; current != NULL; current =
3530
13
       current->next)
3531
13
    {
3532
13
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
13
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
13
#endif
3537
13
      reloc_count += current->reloc_count;
3538
13
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
16
  for (current = abfd->sections; current != NULL; current =
3547
13
       current->next)
3548
13
    {
3549
13
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
13
      else
3556
13
  current->line_filepos = 0;
3557
3558
13
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
13
      else
3569
13
  current->rel_filepos = 0;
3570
13
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
3
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
16
       current != NULL;
3596
13
       current = current->next)
3597
13
    {
3598
13
      struct internal_scnhdr section;
3599
13
#ifdef COFF_IMAGE_WITH_PE
3600
13
      bool is_reloc_section = false;
3601
3602
13
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
1
  {
3604
1
    is_reloc_section = true;
3605
1
    hasrelocs = true;
3606
1
    pe_data (abfd)->has_reloc_section = 1;
3607
1
  }
3608
13
#endif
3609
3610
13
      internal_f.f_nscns++;
3611
3612
13
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
13
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
13
      if (bfd_coff_long_section_names (abfd))
3618
9
  {
3619
9
    size_t len;
3620
3621
9
    len = strlen (current->name);
3622
9
    if (len > SCNNMLEN)
3623
2
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
2
        if (string_size < 10000000)
3629
2
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
2
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
2
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
2
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
2
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
2
#endif
3668
2
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
2
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
2
        string_size += len + 1;
3683
2
        long_section_names = true;
3684
2
      }
3685
9
  }
3686
13
#endif
3687
3688
13
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
13
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
13
      else
3694
13
#endif
3695
13
      section.s_vaddr = current->vma;
3696
13
      section.s_paddr = current->lma;
3697
13
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
13
      section.s_page = 0;
3702
13
#endif
3703
3704
13
#ifdef COFF_WITH_PE
3705
13
      section.s_paddr = 0;
3706
13
#endif
3707
13
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
13
      if (coff_section_data (abfd, current) != NULL
3710
13
    && pei_section_data (abfd, current) != NULL)
3711
13
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
13
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
13
      if (current->size == 0
3719
13
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
1
  section.s_scnptr = 0;
3721
12
      else
3722
12
  section.s_scnptr = current->filepos;
3723
3724
13
      section.s_relptr = current->rel_filepos;
3725
13
      section.s_lnnoptr = current->line_filepos;
3726
13
      section.s_nreloc = current->reloc_count;
3727
13
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
13
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
13
#ifdef COFF_IMAGE_WITH_PE
3736
13
      if ((current->flags & SEC_DEBUGGING) != 0
3737
13
    && ! is_reloc_section)
3738
1
  hasdebug = true;
3739
13
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
13
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
13
      if (!strcmp (current->name, _TEXT))
3755
2
  text_sec = current;
3756
11
      else if (!strcmp (current->name, _DATA))
3757
2
  data_sec = current;
3758
9
      else if (!strcmp (current->name, _BSS))
3759
1
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
13
#ifdef COFF_ENCODE_ALIGNMENT
3769
13
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
13
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
13
#endif
3788
3789
13
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
13
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
13
      else
3798
13
#endif
3799
13
  {
3800
13
    SCNHDR buff;
3801
13
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
13
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
13
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
13
  }
3807
3808
13
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
13
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
13
#endif /* COFF_WITH_PE */
3903
13
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
3
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
3
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
3
    internal_f.f_flags |= F_EXEC;
3997
3
#ifdef COFF_IMAGE_WITH_PE
3998
3
  if (! hasdebug)
3999
2
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
3
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
1
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
3
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
3
#ifdef COFF_WITH_PE
4006
3
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
3
#if defined(I386)
4069
3
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
3
    internal_a.magic = ZMAGIC;
4076
3
#endif
4077
3
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
3
#ifdef COFF_LONG_SECTION_NAMES
4141
3
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
1
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
1
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
1
    }
4148
3
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
3
  else
4162
3
    {
4163
3
      if (long_section_names)
4164
1
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
3
      internal_f.f_flags |= F_LSYMS;
4168
3
    }
4169
4170
3
  if (text_sec)
4171
2
    {
4172
2
      internal_a.tsize = text_sec->size;
4173
2
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
2
    }
4175
3
  if (data_sec)
4176
2
    {
4177
2
      internal_a.dsize = data_sec->size;
4178
2
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
2
    }
4180
3
  if (bss_sec)
4181
1
    {
4182
1
      internal_a.bsize = bss_sec->size;
4183
1
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
1
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
3
#ifdef COFF_WITH_PE
4287
3
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
3
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
3
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
3
  }
4295
3
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
3
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
3
      char * buff;
4323
3
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
3
      buff = (char *) bfd_malloc (amount);
4326
3
      if (buff == NULL)
4327
0
  return false;
4328
4329
3
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
3
      amount = bfd_write (buff, amount, abfd);
4331
4332
3
      free (buff);
4333
4334
3
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
3
#ifdef COFF_IMAGE_WITH_PE
4338
3
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
3
#endif
4341
3
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
pe-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
0
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
0
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
0
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
0
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
0
#ifdef COFF_WITH_PE
3705
0
      section.s_paddr = 0;
3706
0
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
0
#ifdef COFF_ENCODE_ALIGNMENT
3769
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
0
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
0
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
0
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
1
#if defined(I386)
4069
1
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
1
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
1
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
pei-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
8
{
3487
8
  asection *current;
3488
8
  bool hasrelocs = false;
3489
8
  bool haslinno = false;
3490
8
#ifdef COFF_IMAGE_WITH_PE
3491
8
  bool hasdebug = false;
3492
8
#endif
3493
8
  file_ptr scn_base;
3494
8
  file_ptr reloc_base;
3495
8
  file_ptr lineno_base;
3496
8
  file_ptr sym_base;
3497
8
  unsigned long reloc_size = 0, reloc_count = 0;
3498
8
  unsigned long lnno_size = 0;
3499
8
  bool long_section_names;
3500
8
  asection *text_sec = NULL;
3501
8
  asection *data_sec = NULL;
3502
8
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
8
  struct internal_filehdr internal_f;
3508
8
  struct internal_aouthdr internal_a;
3509
8
#ifdef COFF_LONG_SECTION_NAMES
3510
8
  size_t string_size = STRING_SIZE_SIZE;
3511
8
#endif
3512
3513
8
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
8
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
8
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
8
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
83
  for (current = abfd->sections; current != NULL; current =
3530
75
       current->next)
3531
75
    {
3532
75
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
75
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
75
#endif
3537
75
      reloc_count += current->reloc_count;
3538
75
    }
3539
3540
8
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
8
  lineno_base = reloc_base + reloc_size;
3543
8
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
83
  for (current = abfd->sections; current != NULL; current =
3547
75
       current->next)
3548
75
    {
3549
75
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
75
      else
3556
75
  current->line_filepos = 0;
3557
3558
75
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
75
      else
3569
75
  current->rel_filepos = 0;
3570
75
    }
3571
3572
  /* Write section headers to the file.  */
3573
8
  internal_f.f_nscns = 0;
3574
3575
8
  if ((abfd->flags & EXEC_P) != 0)
3576
8
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
8
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
8
  long_section_names = false;
3594
8
  for (current = abfd->sections;
3595
83
       current != NULL;
3596
75
       current = current->next)
3597
75
    {
3598
75
      struct internal_scnhdr section;
3599
75
#ifdef COFF_IMAGE_WITH_PE
3600
75
      bool is_reloc_section = false;
3601
3602
75
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
3
  {
3604
3
    is_reloc_section = true;
3605
3
    hasrelocs = true;
3606
3
    pe_data (abfd)->has_reloc_section = 1;
3607
3
  }
3608
75
#endif
3609
3610
75
      internal_f.f_nscns++;
3611
3612
75
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
75
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
75
      if (bfd_coff_long_section_names (abfd))
3618
75
  {
3619
75
    size_t len;
3620
3621
75
    len = strlen (current->name);
3622
75
    if (len > SCNNMLEN)
3623
29
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
29
        if (string_size < 10000000)
3629
29
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
29
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
29
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
29
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
29
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
29
#endif
3668
29
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
29
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
29
        string_size += len + 1;
3683
29
        long_section_names = true;
3684
29
      }
3685
75
  }
3686
75
#endif
3687
3688
75
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
75
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
75
      else
3694
75
#endif
3695
75
      section.s_vaddr = current->vma;
3696
75
      section.s_paddr = current->lma;
3697
75
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
75
      section.s_page = 0;
3702
75
#endif
3703
3704
75
#ifdef COFF_WITH_PE
3705
75
      section.s_paddr = 0;
3706
75
#endif
3707
75
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
75
      if (coff_section_data (abfd, current) != NULL
3710
75
    && pei_section_data (abfd, current) != NULL)
3711
75
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
75
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
75
      if (current->size == 0
3719
75
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
3
  section.s_scnptr = 0;
3721
72
      else
3722
72
  section.s_scnptr = current->filepos;
3723
3724
75
      section.s_relptr = current->rel_filepos;
3725
75
      section.s_lnnoptr = current->line_filepos;
3726
75
      section.s_nreloc = current->reloc_count;
3727
75
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
75
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
75
#ifdef COFF_IMAGE_WITH_PE
3736
75
      if ((current->flags & SEC_DEBUGGING) != 0
3737
75
    && ! is_reloc_section)
3738
32
  hasdebug = true;
3739
75
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
75
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
75
      if (!strcmp (current->name, _TEXT))
3755
3
  text_sec = current;
3756
72
      else if (!strcmp (current->name, _DATA))
3757
3
  data_sec = current;
3758
69
      else if (!strcmp (current->name, _BSS))
3759
3
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
75
#ifdef COFF_ENCODE_ALIGNMENT
3769
75
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
75
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
75
#endif
3788
3789
75
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
75
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
75
      else
3798
75
#endif
3799
75
  {
3800
75
    SCNHDR buff;
3801
75
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
75
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
75
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
75
  }
3807
3808
75
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
75
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
75
#endif /* COFF_WITH_PE */
3903
75
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
8
  internal_f.f_timdat = 0;
3974
8
  internal_f.f_flags = 0;
3975
3976
8
  if (abfd->flags & EXEC_P)
3977
8
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
8
  if (!hasrelocs)
3992
5
    internal_f.f_flags |= F_RELFLG;
3993
8
  if (!haslinno)
3994
8
    internal_f.f_flags |= F_LNNO;
3995
8
  if (abfd->flags & EXEC_P)
3996
8
    internal_f.f_flags |= F_EXEC;
3997
8
#ifdef COFF_IMAGE_WITH_PE
3998
8
  if (! hasdebug)
3999
2
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
8
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
8
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
8
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
8
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
8
  {
4035
8
    unsigned int magic = 0;
4036
8
    unsigned short flags = 0;
4037
4038
8
    coff_set_flags (abfd, &magic, &flags);
4039
8
    internal_f.f_magic = magic;
4040
8
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
8
#if defined(I386)
4069
8
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
8
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
8
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
8
#undef __A_MAGIC_SET__
4112
8
#endif
4113
8
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
8
  internal_a.vstamp = 0;
4121
8
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
8
  obj_sym_filepos (abfd) = sym_base;
4125
4126
8
  if (bfd_get_symcount (abfd) != 0)
4127
3
    {
4128
3
      int firstundef;
4129
4130
3
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
3
      coff_mangle_symbols (abfd);
4133
3
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
3
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
3
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
3
    }
4140
5
#ifdef COFF_LONG_SECTION_NAMES
4141
5
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
8
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
8
  if (obj_raw_syment_count (abfd) != 0)
4153
3
    {
4154
3
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
3
    }
4161
5
  else
4162
5
    {
4163
5
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
5
      else
4166
5
  internal_f.f_symptr = 0;
4167
5
      internal_f.f_flags |= F_LSYMS;
4168
5
    }
4169
4170
8
  if (text_sec)
4171
3
    {
4172
3
      internal_a.tsize = text_sec->size;
4173
3
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
3
    }
4175
8
  if (data_sec)
4176
3
    {
4177
3
      internal_a.dsize = data_sec->size;
4178
3
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
3
    }
4180
8
  if (bss_sec)
4181
3
    {
4182
3
      internal_a.bsize = bss_sec->size;
4183
3
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
3
    }
4186
4187
8
  internal_a.entry = bfd_get_start_address (abfd);
4188
8
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
8
#ifdef COFF_WITH_PE
4287
8
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
8
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
8
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
8
  }
4295
8
#endif
4296
4297
  /* Now write header.  */
4298
8
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
8
  {
4302
8
    char * buff;
4303
8
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
8
    buff = (char *) bfd_malloc (amount);
4306
8
    if (buff == NULL)
4307
0
      return false;
4308
4309
8
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
8
    amount = bfd_write (buff, amount, abfd);
4311
4312
8
    free (buff);
4313
4314
8
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
8
  }
4317
4318
8
  if (abfd->flags & EXEC_P)
4319
8
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
8
      char * buff;
4323
8
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
8
      buff = (char *) bfd_malloc (amount);
4326
8
      if (buff == NULL)
4327
0
  return false;
4328
4329
8
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
8
      amount = bfd_write (buff, amount, abfd);
4331
4332
8
      free (buff);
4333
4334
8
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
8
#ifdef COFF_IMAGE_WITH_PE
4338
8
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
8
#endif
4341
8
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
8
  return true;
4362
8
}
coff-x86_64.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
2
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
2
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
2
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
2
       current != NULL;
3596
2
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
2
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
2
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
2
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
2
  if (bfd_little_endian (abfd))
4009
2
    internal_f.f_flags |= F_AR32WR;
4010
0
  else
4011
0
    internal_f.f_flags |= F_AR32W;
4012
2
#endif
4013
2
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
2
#if defined(I386)
4069
2
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
2
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
2
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
2
      char * buff;
4323
2
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
2
      buff = (char *) bfd_malloc (amount);
4326
2
      if (buff == NULL)
4327
0
  return false;
4328
4329
2
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
2
      amount = bfd_write (buff, amount, abfd);
4331
4332
2
      free (buff);
4333
4334
2
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
2
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
coff64-rs6000.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
1
#ifdef RS6000COFF_C
3504
1
  asection *tdata_sec = NULL;
3505
1
  asection *tbss_sec = NULL;
3506
1
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
1
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
1
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
      if (strcmp (current->name, _LIB) == 0)
3692
  section.s_vaddr = 0;
3693
      else
3694
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
0
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
0
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
0
#ifdef RS6000COFF_C
3761
0
      else if (!strcmp (current->name, _TDATA))
3762
0
  tdata_sec = current;
3763
0
      else if (!strcmp (current->name, _TBSS))
3764
0
  tbss_sec = current;
3765
0
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
1
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
1
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
1
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
1
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
1
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
1
  else
4011
1
    internal_f.f_flags |= F_AR32W;
4012
1
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
1
#ifdef RS6000COFF_C
4025
1
  if ((abfd->flags & DYNAMIC) != 0)
4026
0
    internal_f.f_flags |= F_SHROBJ;
4027
1
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
0
    internal_f.f_flags |= F_DYNLOAD;
4029
1
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
1
#ifdef RS6000COFF_C
4092
1
#define __A_MAGIC_SET__
4093
1
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
1
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
1
    RS6K_AOUTHDR_OMAGIC;
4096
1
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
1
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
1
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
  internal_a.vstamp = 0;
4121
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
0
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
0
      internal_f.f_flags &=~ F_RELFLG;
4159
0
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
1
#ifdef RS6000COFF_C
4191
1
  if (xcoff_data (abfd)->full_aouthdr)
4192
0
    {
4193
0
      bfd_vma toc;
4194
0
      asection *loader_sec;
4195
4196
0
      internal_a.vstamp = 2;
4197
4198
0
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
0
      if (internal_a.o_snentry == 0)
4200
0
  internal_a.entry = (bfd_vma) -1;
4201
4202
0
      if (text_sec != NULL)
4203
0
  {
4204
0
    internal_a.o_sntext = text_sec->target_index;
4205
0
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
0
  }
4207
0
      else
4208
0
  {
4209
0
    internal_a.o_sntext = 0;
4210
0
    internal_a.o_algntext = 0;
4211
0
  }
4212
0
      if (data_sec != NULL)
4213
0
  {
4214
0
    internal_a.o_sndata = data_sec->target_index;
4215
0
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
0
  }
4217
0
      else
4218
0
  {
4219
0
    internal_a.o_sndata = 0;
4220
0
    internal_a.o_algndata = 0;
4221
0
  }
4222
0
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
0
      if (loader_sec != NULL)
4224
0
  internal_a.o_snloader = loader_sec->target_index;
4225
0
      else
4226
0
  internal_a.o_snloader = 0;
4227
0
      if (bss_sec != NULL)
4228
0
  internal_a.o_snbss = bss_sec->target_index;
4229
0
      else
4230
0
  internal_a.o_snbss = 0;
4231
4232
0
      if (tdata_sec != NULL)
4233
0
  {
4234
0
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
0
    internal_a.o_flags = 0;
4238
0
#ifdef XCOFF64
4239
0
    internal_a.o_x64flags = 0;
4240
0
#endif
4241
0
  }
4242
0
      else
4243
0
  {
4244
0
    internal_a.o_sntdata = 0;
4245
0
    internal_a.o_flags = 0;
4246
0
#ifdef XCOFF64
4247
0
    internal_a.o_x64flags = 0;
4248
0
#endif
4249
0
  }
4250
0
      if (tbss_sec != NULL)
4251
0
    internal_a.o_sntbss = tbss_sec->target_index;
4252
0
      else
4253
0
    internal_a.o_sntbss = 0;
4254
4255
0
      toc = xcoff_data (abfd)->toc;
4256
0
      internal_a.o_toc = toc;
4257
0
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
0
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
0
      if (xcoff_data (abfd)->cputype != -1)
4261
0
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
0
      else
4263
0
  {
4264
0
    switch (bfd_get_arch (abfd))
4265
0
      {
4266
0
      case bfd_arch_rs6000:
4267
0
        internal_a.o_cputype = 4;
4268
0
        break;
4269
0
      case bfd_arch_powerpc:
4270
0
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
0
    internal_a.o_cputype = 3;
4272
0
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
0
    internal_a.o_cputype = 2;
4274
0
        else
4275
0
    internal_a.o_cputype = 1;
4276
0
        break;
4277
0
      default:
4278
0
        abort ();
4279
0
      }
4280
0
  }
4281
0
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
0
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
0
    }
4284
1
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
1
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
1
#endif
4360
4361
1
  return true;
4362
1
}
pe-aarch64.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
2
  for (current = abfd->sections; current != NULL; current =
3530
1
       current->next)
3531
1
    {
3532
1
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
1
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
1
#endif
3537
1
      reloc_count += current->reloc_count;
3538
1
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
2
  for (current = abfd->sections; current != NULL; current =
3547
1
       current->next)
3548
1
    {
3549
1
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
1
      else
3556
1
  current->line_filepos = 0;
3557
3558
1
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
1
      else
3569
1
  current->rel_filepos = 0;
3570
1
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
2
       current != NULL;
3596
1
       current = current->next)
3597
1
    {
3598
1
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
1
      internal_f.f_nscns++;
3611
3612
1
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
1
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
1
      if (bfd_coff_long_section_names (abfd))
3618
1
  {
3619
1
    size_t len;
3620
3621
1
    len = strlen (current->name);
3622
1
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
1
  }
3686
1
#endif
3687
3688
1
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
1
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
1
      else
3694
1
#endif
3695
1
      section.s_vaddr = current->vma;
3696
1
      section.s_paddr = current->lma;
3697
1
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
1
      section.s_page = 0;
3702
1
#endif
3703
3704
1
#ifdef COFF_WITH_PE
3705
1
      section.s_paddr = 0;
3706
1
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
1
      if (current->size == 0
3719
1
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
1
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
1
      section.s_relptr = current->rel_filepos;
3725
1
      section.s_lnnoptr = current->line_filepos;
3726
1
      section.s_nreloc = current->reloc_count;
3727
1
      section.s_nlnno = current->lineno_count;
3728
1
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
1
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
1
#endif
3733
1
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
1
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
1
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
1
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
1
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
1
#ifdef COFF_ENCODE_ALIGNMENT
3769
1
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
1
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
1
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
1
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
1
  {
3800
1
    SCNHDR buff;
3801
1
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
1
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
1
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
1
  }
3807
3808
1
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
1
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
1
#endif /* COFF_WITH_PE */
3903
1
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
1
#if defined(AARCH64)
4054
1
#define __A_MAGIC_SET__
4055
1
    internal_a.magic = ZMAGIC;
4056
1
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
1
    {
4128
1
      int firstundef;
4129
4130
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
1
      coff_mangle_symbols (abfd);
4133
1
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
1
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
1
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
1
    }
4140
0
#ifdef COFF_LONG_SECTION_NAMES
4141
0
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
1
    {
4154
1
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
1
    }
4161
0
  else
4162
0
    {
4163
0
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
0
      else
4166
0
  internal_f.f_symptr = 0;
4167
0
      internal_f.f_flags |= F_LSYMS;
4168
0
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
pei-aarch64.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
2
#ifdef COFF_IMAGE_WITH_PE
3491
2
  bool hasdebug = false;
3492
2
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
2
#ifdef COFF_LONG_SECTION_NAMES
3510
2
  size_t string_size = STRING_SIZE_SIZE;
3511
2
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
0
    {
3521
0
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
0
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
6
  for (current = abfd->sections; current != NULL; current =
3530
4
       current->next)
3531
4
    {
3532
4
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
4
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
4
#endif
3537
4
      reloc_count += current->reloc_count;
3538
4
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
6
  for (current = abfd->sections; current != NULL; current =
3547
4
       current->next)
3548
4
    {
3549
4
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
4
      else
3556
4
  current->line_filepos = 0;
3557
3558
4
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
4
      else
3569
4
  current->rel_filepos = 0;
3570
4
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
2
  else
3578
2
    {
3579
2
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
2
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
6
       current != NULL;
3596
4
       current = current->next)
3597
4
    {
3598
4
      struct internal_scnhdr section;
3599
4
#ifdef COFF_IMAGE_WITH_PE
3600
4
      bool is_reloc_section = false;
3601
3602
4
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
4
#endif
3609
3610
4
      internal_f.f_nscns++;
3611
3612
4
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
4
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
4
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
4
#endif
3687
3688
4
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
4
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
4
      else
3694
4
#endif
3695
4
      section.s_vaddr = current->vma;
3696
4
      section.s_paddr = current->lma;
3697
4
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
4
      section.s_page = 0;
3702
4
#endif
3703
3704
4
#ifdef COFF_WITH_PE
3705
4
      section.s_paddr = 0;
3706
4
#endif
3707
4
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
4
      if (coff_section_data (abfd, current) != NULL
3710
4
    && pei_section_data (abfd, current) != NULL)
3711
4
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
4
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
4
      if (current->size == 0
3719
4
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
4
      else
3722
4
  section.s_scnptr = current->filepos;
3723
3724
4
      section.s_relptr = current->rel_filepos;
3725
4
      section.s_lnnoptr = current->line_filepos;
3726
4
      section.s_nreloc = current->reloc_count;
3727
4
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
4
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
4
#ifdef COFF_IMAGE_WITH_PE
3736
4
      if ((current->flags & SEC_DEBUGGING) != 0
3737
4
    && ! is_reloc_section)
3738
4
  hasdebug = true;
3739
4
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
4
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
4
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
4
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
4
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
4
#ifdef COFF_ENCODE_ALIGNMENT
3769
4
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
4
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
4
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
4
#endif
3788
3789
4
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
4
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
4
      else
3798
4
#endif
3799
4
  {
3800
4
    SCNHDR buff;
3801
4
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
4
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
4
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
4
  }
3807
3808
4
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
4
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
4
#endif /* COFF_WITH_PE */
3903
4
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
2
  else
3979
2
    {
3980
2
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
2
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
2
#ifdef COFF_IMAGE_WITH_PE
3998
2
  if (! hasdebug)
3999
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
2
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
2
#endif
4003
4004
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
2
#if defined(AARCH64)
4054
2
#define __A_MAGIC_SET__
4055
2
    internal_a.magic = ZMAGIC;
4056
2
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
2
#ifdef COFF_LONG_SECTION_NAMES
4141
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
2
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
2
#ifdef COFF_WITH_PE
4287
2
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
2
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
2
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
2
  }
4295
2
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
Unexecuted instantiation: pei-ia64.c:coff_write_object_contents
Unexecuted instantiation: pei-loongarch64.c:coff_write_object_contents
Unexecuted instantiation: cf-i386lynx.c:coff_write_object_contents
Unexecuted instantiation: coff-go32.c:coff_write_object_contents
Unexecuted instantiation: coff-i386.c:coff_write_object_contents
Unexecuted instantiation: coff-rs6000.c:coff_write_object_contents
coff-sh.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
0
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
0
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
0
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
1
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
1
  else
4011
1
    internal_f.f_flags |= F_AR32W;
4012
1
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
Unexecuted instantiation: coff-stgo32.c:coff_write_object_contents
Unexecuted instantiation: coff-tic30.c:coff_write_object_contents
Unexecuted instantiation: coff-tic4x.c:coff_write_object_contents
Unexecuted instantiation: coff-tic54x.c:coff_write_object_contents
Unexecuted instantiation: coff-z80.c:coff_write_object_contents
coff-z8k.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
#ifdef COFF_LONG_SECTION_NAMES
3510
  size_t string_size = STRING_SIZE_SIZE;
3511
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
257
  for (current = abfd->sections; current != NULL; current =
3530
254
       current->next)
3531
254
    {
3532
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
  reloc_count ++;
3536
#endif
3537
254
      reloc_count += current->reloc_count;
3538
254
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
257
  for (current = abfd->sections; current != NULL; current =
3547
254
       current->next)
3548
254
    {
3549
254
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
254
      else
3556
254
  current->line_filepos = 0;
3557
3558
254
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
      reloc_base += bfd_coff_relsz (abfd);
3566
#endif
3567
0
  }
3568
254
      else
3569
254
  current->rel_filepos = 0;
3570
254
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
3
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
0
  else
3578
0
    {
3579
0
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
0
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
257
       current != NULL;
3596
254
       current = current->next)
3597
254
    {
3598
254
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
254
      internal_f.f_nscns++;
3611
3612
254
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
      if (bfd_coff_long_section_names (abfd))
3618
  {
3619
    size_t len;
3620
3621
    len = strlen (current->name);
3622
    if (len > SCNNMLEN)
3623
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
        if (string_size < 10000000)
3629
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
    }
3646
        else
3647
#ifdef COFF_WITH_PE
3648
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
      static const char base64[] =
3653
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
        "abcdefghijklmnopqrstuvwxyz"
3655
        "0123456789+/";
3656
      unsigned long off = string_size;
3657
      unsigned i;
3658
3659
      section.s_name[0] = '/';
3660
      section.s_name[1] = '/';
3661
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
        {
3663
          section.s_name[i] = base64[off & 0x3f];
3664
          off >>= 6;
3665
        }
3666
    }
3667
#endif
3668
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
      )
3673
    {
3674
      bfd_set_error (bfd_error_file_too_big);
3675
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
        abfd, current, (unsigned long) string_size);
3679
      return false;
3680
    }
3681
3682
        string_size += len + 1;
3683
        long_section_names = true;
3684
      }
3685
  }
3686
#endif
3687
3688
254
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
254
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
254
      else
3694
254
#endif
3695
254
      section.s_vaddr = current->vma;
3696
254
      section.s_paddr = current->lma;
3697
254
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
254
      section.s_page = 0;
3702
254
#endif
3703
3704
#ifdef COFF_WITH_PE
3705
      section.s_paddr = 0;
3706
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
254
      if (current->size == 0
3719
254
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
250
  section.s_scnptr = 0;
3721
4
      else
3722
4
  section.s_scnptr = current->filepos;
3723
3724
254
      section.s_relptr = current->rel_filepos;
3725
254
      section.s_lnnoptr = current->line_filepos;
3726
254
      section.s_nreloc = current->reloc_count;
3727
254
      section.s_nlnno = current->lineno_count;
3728
254
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
254
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
254
#endif
3733
254
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
254
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
254
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
254
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
254
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
#ifdef COFF_ENCODE_ALIGNMENT
3769
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
        != current->alignment_power))
3772
  {
3773
    bool warn = (coff_data (abfd)->link_info
3774
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
       abfd, warn ? " warning:" : "", current->name,
3780
       current->alignment_power);
3781
    if (!warn)
3782
      {
3783
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
        return false;
3785
      }
3786
  }
3787
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
254
  {
3800
254
    SCNHDR buff;
3801
254
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
254
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
254
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
254
  }
3807
3808
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
  {
3814
    unsigned int i, count;
3815
    asymbol **psym;
3816
    coff_symbol_type *csym = NULL;
3817
    asymbol **psymsec;
3818
3819
    psymsec = NULL;
3820
    count = bfd_get_symcount (abfd);
3821
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
      {
3823
        if ((*psym)->section != current)
3824
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
        if (psymsec == NULL)
3829
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
        if (strcmp ((*psym)->name, current->name) == 0)
3833
    {
3834
      csym = coff_symbol_from (*psym);
3835
      if (csym == NULL
3836
          || csym->native == NULL
3837
          || ! csym->native->is_sym
3838
          || csym->native->u.syment.n_numaux < 1
3839
          || csym->native->u.syment.n_sclass != C_STAT
3840
          || csym->native->u.syment.n_type != T_NULL)
3841
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
      break;
3846
    }
3847
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
    if (i < count)
3853
      {
3854
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
        aux = csym->native + 1;
3860
        BFD_ASSERT (! aux->is_sym);
3861
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
    {
3863
    case SEC_LINK_DUPLICATES_DISCARD:
3864
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
      break;
3866
3867
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
      aux->u.auxent.x_scn.x_comdat =
3869
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
      break;
3871
3872
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
      aux->u.auxent.x_scn.x_comdat =
3874
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
      break;
3876
3877
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
      aux->u.auxent.x_scn.x_comdat =
3879
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
      break;
3881
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
        if (psym != psymsec)
3891
    {
3892
      asymbol *hold;
3893
      asymbol **pcopy;
3894
3895
      hold = *psym;
3896
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
        pcopy[0] = pcopy[-1];
3898
      *psymsec = hold;
3899
    }
3900
      }
3901
  }
3902
#endif /* COFF_WITH_PE */
3903
254
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
3
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
0
  else
3979
0
    {
3980
0
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
0
    }
3990
3991
3
  if (!hasrelocs)
3992
3
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
3
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
#ifdef COFF_WITH_PE
4006
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
3
  if (bfd_little_endian (abfd))
4009
0
    internal_f.f_flags |= F_AR32WR;
4010
3
  else
4011
3
    internal_f.f_flags |= F_AR32W;
4012
3
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
#ifdef COFF_LONG_SECTION_NAMES
4141
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
      if (! coff_write_symbols (abfd))
4146
  return false;
4147
    }
4148
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
3
  else
4162
3
    {
4163
3
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
3
      else
4166
3
  internal_f.f_symptr = 0;
4167
3
      internal_f.f_flags |= F_LSYMS;
4168
3
    }
4169
4170
3
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
3
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
3
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
#ifdef COFF_WITH_PE
4287
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
    if (pe->build_id.after_write_object_contents != NULL)
4293
      (*pe->build_id.after_write_object_contents) (abfd);
4294
  }
4295
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
3
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
3
      char * buff;
4323
3
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
3
      buff = (char *) bfd_malloc (amount);
4326
3
      if (buff == NULL)
4327
0
  return false;
4328
4329
3
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
3
      amount = bfd_write (buff, amount, abfd);
4331
4332
3
      free (buff);
4333
4334
3
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
3
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
Unexecuted instantiation: pe-arm-wince.c:coff_write_object_contents
Unexecuted instantiation: pe-arm.c:coff_write_object_contents
pe-i386.c:coff_write_object_contents
Line
Count
Source
3486
3
{
3487
3
  asection *current;
3488
3
  bool hasrelocs = false;
3489
3
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
3
  file_ptr scn_base;
3494
3
  file_ptr reloc_base;
3495
3
  file_ptr lineno_base;
3496
3
  file_ptr sym_base;
3497
3
  unsigned long reloc_size = 0, reloc_count = 0;
3498
3
  unsigned long lnno_size = 0;
3499
3
  bool long_section_names;
3500
3
  asection *text_sec = NULL;
3501
3
  asection *data_sec = NULL;
3502
3
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
3
  struct internal_filehdr internal_f;
3508
3
  struct internal_aouthdr internal_a;
3509
3
#ifdef COFF_LONG_SECTION_NAMES
3510
3
  size_t string_size = STRING_SIZE_SIZE;
3511
3
#endif
3512
3513
3
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
3
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
3
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
3
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
502
  for (current = abfd->sections; current != NULL; current =
3530
499
       current->next)
3531
499
    {
3532
499
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
499
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
499
#endif
3537
499
      reloc_count += current->reloc_count;
3538
499
    }
3539
3540
3
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
3
  lineno_base = reloc_base + reloc_size;
3543
3
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
502
  for (current = abfd->sections; current != NULL; current =
3547
499
       current->next)
3548
499
    {
3549
499
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
499
      else
3556
499
  current->line_filepos = 0;
3557
3558
499
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
499
      else
3569
499
  current->rel_filepos = 0;
3570
499
    }
3571
3572
  /* Write section headers to the file.  */
3573
3
  internal_f.f_nscns = 0;
3574
3575
3
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
3
  else
3578
3
    {
3579
3
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
3
    }
3589
3590
3
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
3
  long_section_names = false;
3594
3
  for (current = abfd->sections;
3595
502
       current != NULL;
3596
499
       current = current->next)
3597
499
    {
3598
499
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
499
      internal_f.f_nscns++;
3611
3612
499
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
499
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
499
      if (bfd_coff_long_section_names (abfd))
3618
499
  {
3619
499
    size_t len;
3620
3621
499
    len = strlen (current->name);
3622
499
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
499
  }
3686
499
#endif
3687
3688
499
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
499
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
499
      else
3694
499
#endif
3695
499
      section.s_vaddr = current->vma;
3696
499
      section.s_paddr = current->lma;
3697
499
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
499
      section.s_page = 0;
3702
499
#endif
3703
3704
499
#ifdef COFF_WITH_PE
3705
499
      section.s_paddr = 0;
3706
499
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
499
      if (current->size == 0
3719
499
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
497
  section.s_scnptr = 0;
3721
2
      else
3722
2
  section.s_scnptr = current->filepos;
3723
3724
499
      section.s_relptr = current->rel_filepos;
3725
499
      section.s_lnnoptr = current->line_filepos;
3726
499
      section.s_nreloc = current->reloc_count;
3727
499
      section.s_nlnno = current->lineno_count;
3728
499
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
499
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
499
#endif
3733
499
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
499
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
499
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
499
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
499
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
499
#ifdef COFF_ENCODE_ALIGNMENT
3769
499
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
499
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
499
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
499
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
499
  {
3800
499
    SCNHDR buff;
3801
499
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
499
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
499
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
499
  }
3807
3808
499
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
499
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
1
  {
3814
1
    unsigned int i, count;
3815
1
    asymbol **psym;
3816
1
    coff_symbol_type *csym = NULL;
3817
1
    asymbol **psymsec;
3818
3819
1
    psymsec = NULL;
3820
1
    count = bfd_get_symcount (abfd);
3821
160
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
159
      {
3823
159
        if ((*psym)->section != current)
3824
159
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
1
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
1
  }
3902
499
#endif /* COFF_WITH_PE */
3903
499
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
3
  internal_f.f_timdat = 0;
3974
3
  internal_f.f_flags = 0;
3975
3976
3
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
3
  else
3979
3
    {
3980
3
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
3
    }
3990
3991
3
  if (!hasrelocs)
3992
3
    internal_f.f_flags |= F_RELFLG;
3993
3
  if (!haslinno)
3994
3
    internal_f.f_flags |= F_LNNO;
3995
3
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
3
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
3
#ifdef COFF_WITH_PE
4006
3
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
3
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
3
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
3
  {
4035
3
    unsigned int magic = 0;
4036
3
    unsigned short flags = 0;
4037
4038
3
    coff_set_flags (abfd, &magic, &flags);
4039
3
    internal_f.f_magic = magic;
4040
3
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
3
#if defined(I386)
4069
3
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
3
    internal_a.magic = ZMAGIC;
4076
3
#endif
4077
3
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
3
#undef __A_MAGIC_SET__
4112
3
#endif
4113
3
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
3
  internal_a.vstamp = 0;
4121
3
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
3
  obj_sym_filepos (abfd) = sym_base;
4125
4126
3
  if (bfd_get_symcount (abfd) != 0)
4127
1
    {
4128
1
      int firstundef;
4129
4130
1
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
1
      coff_mangle_symbols (abfd);
4133
1
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
1
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
1
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
1
    }
4140
2
#ifdef COFF_LONG_SECTION_NAMES
4141
2
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
3
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
3
  if (obj_raw_syment_count (abfd) != 0)
4153
1
    {
4154
1
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
1
    }
4161
2
  else
4162
2
    {
4163
2
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
2
      else
4166
2
  internal_f.f_symptr = 0;
4167
2
      internal_f.f_flags |= F_LSYMS;
4168
2
    }
4169
4170
3
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
3
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
3
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
3
  internal_a.entry = bfd_get_start_address (abfd);
4188
3
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
3
#ifdef COFF_WITH_PE
4287
3
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
3
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
3
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
3
  }
4295
3
#endif
4296
4297
  /* Now write header.  */
4298
3
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
3
  {
4302
3
    char * buff;
4303
3
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
3
    buff = (char *) bfd_malloc (amount);
4306
3
    if (buff == NULL)
4307
0
      return false;
4308
4309
3
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
3
    amount = bfd_write (buff, amount, abfd);
4311
4312
3
    free (buff);
4313
4314
3
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
3
  }
4317
4318
3
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
3
  return true;
4362
3
}
pe-mcore.c:coff_write_object_contents
Line
Count
Source
3486
2
{
3487
2
  asection *current;
3488
2
  bool hasrelocs = false;
3489
2
  bool haslinno = false;
3490
#ifdef COFF_IMAGE_WITH_PE
3491
  bool hasdebug = false;
3492
#endif
3493
2
  file_ptr scn_base;
3494
2
  file_ptr reloc_base;
3495
2
  file_ptr lineno_base;
3496
2
  file_ptr sym_base;
3497
2
  unsigned long reloc_size = 0, reloc_count = 0;
3498
2
  unsigned long lnno_size = 0;
3499
2
  bool long_section_names;
3500
2
  asection *text_sec = NULL;
3501
2
  asection *data_sec = NULL;
3502
2
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
2
  struct internal_filehdr internal_f;
3508
2
  struct internal_aouthdr internal_a;
3509
2
#ifdef COFF_LONG_SECTION_NAMES
3510
2
  size_t string_size = STRING_SIZE_SIZE;
3511
2
#endif
3512
3513
2
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
2
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
2
  if (! abfd->output_has_begun)
3520
2
    {
3521
2
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
2
    }
3524
3525
2
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
9
  for (current = abfd->sections; current != NULL; current =
3530
7
       current->next)
3531
7
    {
3532
7
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
7
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
7
#endif
3537
7
      reloc_count += current->reloc_count;
3538
7
    }
3539
3540
2
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
2
  lineno_base = reloc_base + reloc_size;
3543
2
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
9
  for (current = abfd->sections; current != NULL; current =
3547
7
       current->next)
3548
7
    {
3549
7
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
7
      else
3556
7
  current->line_filepos = 0;
3557
3558
7
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
7
      else
3569
7
  current->rel_filepos = 0;
3570
7
    }
3571
3572
  /* Write section headers to the file.  */
3573
2
  internal_f.f_nscns = 0;
3574
3575
2
  if ((abfd->flags & EXEC_P) != 0)
3576
1
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
2
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
2
  long_section_names = false;
3594
2
  for (current = abfd->sections;
3595
9
       current != NULL;
3596
7
       current = current->next)
3597
7
    {
3598
7
      struct internal_scnhdr section;
3599
#ifdef COFF_IMAGE_WITH_PE
3600
      bool is_reloc_section = false;
3601
3602
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
  {
3604
    is_reloc_section = true;
3605
    hasrelocs = true;
3606
    pe_data (abfd)->has_reloc_section = 1;
3607
  }
3608
#endif
3609
3610
7
      internal_f.f_nscns++;
3611
3612
7
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
7
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
7
      if (bfd_coff_long_section_names (abfd))
3618
7
  {
3619
7
    size_t len;
3620
3621
7
    len = strlen (current->name);
3622
7
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
7
  }
3686
7
#endif
3687
3688
7
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
7
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
7
      else
3694
7
#endif
3695
7
      section.s_vaddr = current->vma;
3696
7
      section.s_paddr = current->lma;
3697
7
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
7
      section.s_page = 0;
3702
7
#endif
3703
3704
7
#ifdef COFF_WITH_PE
3705
7
      section.s_paddr = 0;
3706
7
#endif
3707
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
      if (coff_section_data (abfd, current) != NULL
3710
    && pei_section_data (abfd, current) != NULL)
3711
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
      else
3713
  section.s_paddr = 0;
3714
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
7
      if (current->size == 0
3719
7
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
7
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
7
      section.s_relptr = current->rel_filepos;
3725
7
      section.s_lnnoptr = current->line_filepos;
3726
7
      section.s_nreloc = current->reloc_count;
3727
7
      section.s_nlnno = current->lineno_count;
3728
7
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
7
      if (current->reloc_count != 0)
3731
0
  hasrelocs = true;
3732
7
#endif
3733
7
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
#ifdef COFF_IMAGE_WITH_PE
3736
      if ((current->flags & SEC_DEBUGGING) != 0
3737
    && ! is_reloc_section)
3738
  hasdebug = true;
3739
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
7
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
7
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
7
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
7
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
7
#ifdef COFF_ENCODE_ALIGNMENT
3769
7
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
7
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
1
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
7
#endif
3788
3789
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
      if (section.s_size == 0)
3796
  internal_f.f_nscns--;
3797
      else
3798
#endif
3799
7
  {
3800
7
    SCNHDR buff;
3801
7
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
7
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
7
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
7
  }
3807
3808
7
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
7
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
7
#endif /* COFF_WITH_PE */
3903
7
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
2
  internal_f.f_timdat = 0;
3974
2
  internal_f.f_flags = 0;
3975
3976
2
  if (abfd->flags & EXEC_P)
3977
1
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
2
  if (!hasrelocs)
3992
2
    internal_f.f_flags |= F_RELFLG;
3993
2
  if (!haslinno)
3994
2
    internal_f.f_flags |= F_LNNO;
3995
2
  if (abfd->flags & EXEC_P)
3996
1
    internal_f.f_flags |= F_EXEC;
3997
#ifdef COFF_IMAGE_WITH_PE
3998
  if (! hasdebug)
3999
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
#endif
4003
4004
2
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
2
#ifdef COFF_WITH_PE
4006
2
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
2
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
2
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
2
  {
4035
2
    unsigned int magic = 0;
4036
2
    unsigned short flags = 0;
4037
4038
2
    coff_set_flags (abfd, &magic, &flags);
4039
2
    internal_f.f_magic = magic;
4040
2
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
2
#if defined MCORE_PE
4064
2
#define __A_MAGIC_SET__
4065
2
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
2
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
2
#undef __A_MAGIC_SET__
4112
2
#endif
4113
2
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
2
  internal_a.vstamp = 0;
4121
2
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
2
  obj_sym_filepos (abfd) = sym_base;
4125
4126
2
  if (bfd_get_symcount (abfd) != 0)
4127
2
    {
4128
2
      int firstundef;
4129
4130
2
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
2
      coff_mangle_symbols (abfd);
4133
2
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
2
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
2
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
2
    }
4140
0
#ifdef COFF_LONG_SECTION_NAMES
4141
0
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
2
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
2
  if (obj_raw_syment_count (abfd) != 0)
4153
2
    {
4154
2
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
2
    }
4161
0
  else
4162
0
    {
4163
0
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
0
      else
4166
0
  internal_f.f_symptr = 0;
4167
0
      internal_f.f_flags |= F_LSYMS;
4168
0
    }
4169
4170
2
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
2
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
2
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
2
  internal_a.entry = bfd_get_start_address (abfd);
4188
2
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
2
#ifdef COFF_WITH_PE
4287
2
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
2
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
2
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
2
  }
4295
2
#endif
4296
4297
  /* Now write header.  */
4298
2
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
2
  {
4302
2
    char * buff;
4303
2
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
2
    buff = (char *) bfd_malloc (amount);
4306
2
    if (buff == NULL)
4307
0
      return false;
4308
4309
2
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
2
    amount = bfd_write (buff, amount, abfd);
4311
4312
2
    free (buff);
4313
4314
2
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
2
  }
4317
4318
2
  if (abfd->flags & EXEC_P)
4319
1
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
1
      char * buff;
4323
1
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
1
      buff = (char *) bfd_malloc (amount);
4326
1
      if (buff == NULL)
4327
0
  return false;
4328
4329
1
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
1
      amount = bfd_write (buff, amount, abfd);
4331
4332
1
      free (buff);
4333
4334
1
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
#ifdef COFF_IMAGE_WITH_PE
4338
      if (! coff_apply_checksum (abfd))
4339
  return false;
4340
#endif
4341
1
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
2
  return true;
4362
2
}
Unexecuted instantiation: pe-sh.c:coff_write_object_contents
pei-arm-wince.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
1
#ifdef COFF_IMAGE_WITH_PE
3491
1
  bool hasdebug = false;
3492
1
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
0
    {
3521
0
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
0
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
3
  for (current = abfd->sections; current != NULL; current =
3530
2
       current->next)
3531
2
    {
3532
2
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
2
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
2
#endif
3537
2
      reloc_count += current->reloc_count;
3538
2
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
3
  for (current = abfd->sections; current != NULL; current =
3547
2
       current->next)
3548
2
    {
3549
2
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
2
      else
3556
2
  current->line_filepos = 0;
3557
3558
2
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
2
      else
3569
2
  current->rel_filepos = 0;
3570
2
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
3
       current != NULL;
3596
2
       current = current->next)
3597
2
    {
3598
2
      struct internal_scnhdr section;
3599
2
#ifdef COFF_IMAGE_WITH_PE
3600
2
      bool is_reloc_section = false;
3601
3602
2
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
2
#endif
3609
3610
2
      internal_f.f_nscns++;
3611
3612
2
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
2
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
2
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
2
#endif
3687
3688
2
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
2
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
2
      else
3694
2
#endif
3695
2
      section.s_vaddr = current->vma;
3696
2
      section.s_paddr = current->lma;
3697
2
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
2
      section.s_page = 0;
3702
2
#endif
3703
3704
2
#ifdef COFF_WITH_PE
3705
2
      section.s_paddr = 0;
3706
2
#endif
3707
2
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
2
      if (coff_section_data (abfd, current) != NULL
3710
2
    && pei_section_data (abfd, current) != NULL)
3711
2
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
2
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
2
      if (current->size == 0
3719
2
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
2
      else
3722
2
  section.s_scnptr = current->filepos;
3723
3724
2
      section.s_relptr = current->rel_filepos;
3725
2
      section.s_lnnoptr = current->line_filepos;
3726
2
      section.s_nreloc = current->reloc_count;
3727
2
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
2
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
2
#ifdef COFF_IMAGE_WITH_PE
3736
2
      if ((current->flags & SEC_DEBUGGING) != 0
3737
2
    && ! is_reloc_section)
3738
2
  hasdebug = true;
3739
2
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
2
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
2
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
2
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
2
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
2
#ifdef COFF_ENCODE_ALIGNMENT
3769
2
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
2
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
2
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
2
#endif
3788
3789
2
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
2
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
2
      else
3798
2
#endif
3799
2
  {
3800
2
    SCNHDR buff;
3801
2
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
2
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
2
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
2
  }
3807
3808
2
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
2
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
2
#endif /* COFF_WITH_PE */
3903
2
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
1
#ifdef COFF_IMAGE_WITH_PE
3998
1
  if (! hasdebug)
3999
0
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
0
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
1
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
1
#ifdef COFF_WITH_PE
4006
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
1
#if defined(ARM)
4049
1
#define __A_MAGIC_SET__
4050
1
    internal_a.magic = ZMAGIC;
4051
1
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
#if defined(SH) && defined(COFF_WITH_PE)
4099
#define __A_MAGIC_SET__
4100
    internal_a.magic = SH_PE_MAGIC;
4101
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
Unexecuted instantiation: pei-arm.c:coff_write_object_contents
Unexecuted instantiation: pei-mcore.c:coff_write_object_contents
pei-sh.c:coff_write_object_contents
Line
Count
Source
3486
1
{
3487
1
  asection *current;
3488
1
  bool hasrelocs = false;
3489
1
  bool haslinno = false;
3490
1
#ifdef COFF_IMAGE_WITH_PE
3491
1
  bool hasdebug = false;
3492
1
#endif
3493
1
  file_ptr scn_base;
3494
1
  file_ptr reloc_base;
3495
1
  file_ptr lineno_base;
3496
1
  file_ptr sym_base;
3497
1
  unsigned long reloc_size = 0, reloc_count = 0;
3498
1
  unsigned long lnno_size = 0;
3499
1
  bool long_section_names;
3500
1
  asection *text_sec = NULL;
3501
1
  asection *data_sec = NULL;
3502
1
  asection *bss_sec = NULL;
3503
#ifdef RS6000COFF_C
3504
  asection *tdata_sec = NULL;
3505
  asection *tbss_sec = NULL;
3506
#endif
3507
1
  struct internal_filehdr internal_f;
3508
1
  struct internal_aouthdr internal_a;
3509
1
#ifdef COFF_LONG_SECTION_NAMES
3510
1
  size_t string_size = STRING_SIZE_SIZE;
3511
1
#endif
3512
3513
1
  bfd_set_error (bfd_error_system_call);
3514
3515
  /* Make a pass through the symbol table to count line number entries and
3516
     put them into the correct asections.  */
3517
1
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
3518
3519
1
  if (! abfd->output_has_begun)
3520
1
    {
3521
1
      if (! coff_compute_section_file_positions (abfd))
3522
0
  return false;
3523
1
    }
3524
3525
1
  reloc_base = obj_relocbase (abfd);
3526
3527
  /* Work out the size of the reloc and linno areas.  */
3528
3529
1
  for (current = abfd->sections; current != NULL; current =
3530
0
       current->next)
3531
0
    {
3532
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3533
      /* We store the actual reloc count in the first reloc's addr.  */
3534
0
      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3535
0
  reloc_count ++;
3536
0
#endif
3537
0
      reloc_count += current->reloc_count;
3538
0
    }
3539
3540
1
  reloc_size = reloc_count * bfd_coff_relsz (abfd);
3541
3542
1
  lineno_base = reloc_base + reloc_size;
3543
1
  sym_base = lineno_base + lnno_size;
3544
3545
  /* Indicate in each section->line_filepos its actual file address.  */
3546
1
  for (current = abfd->sections; current != NULL; current =
3547
0
       current->next)
3548
0
    {
3549
0
      if (current->lineno_count)
3550
0
  {
3551
0
    current->line_filepos = lineno_base;
3552
0
    current->moving_line_filepos = lineno_base;
3553
0
    lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
3554
0
  }
3555
0
      else
3556
0
  current->line_filepos = 0;
3557
3558
0
      if (current->reloc_count)
3559
0
  {
3560
0
    current->rel_filepos = reloc_base;
3561
0
    reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
3562
0
#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
3563
    /* Extra reloc to hold real count.  */
3564
0
    if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
3565
0
      reloc_base += bfd_coff_relsz (abfd);
3566
0
#endif
3567
0
  }
3568
0
      else
3569
0
  current->rel_filepos = 0;
3570
0
    }
3571
3572
  /* Write section headers to the file.  */
3573
1
  internal_f.f_nscns = 0;
3574
3575
1
  if ((abfd->flags & EXEC_P) != 0)
3576
0
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
3577
1
  else
3578
1
    {
3579
1
      scn_base = bfd_coff_filhsz (abfd);
3580
#ifdef RS6000COFF_C
3581
#ifndef XCOFF64
3582
      if (xcoff_data (abfd)->full_aouthdr)
3583
  scn_base += bfd_coff_aoutsz (abfd);
3584
      else
3585
  scn_base += SMALL_AOUTSZ;
3586
#endif
3587
#endif
3588
1
    }
3589
3590
1
  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
3591
0
    return false;
3592
3593
1
  long_section_names = false;
3594
1
  for (current = abfd->sections;
3595
1
       current != NULL;
3596
1
       current = current->next)
3597
0
    {
3598
0
      struct internal_scnhdr section;
3599
0
#ifdef COFF_IMAGE_WITH_PE
3600
0
      bool is_reloc_section = false;
3601
3602
0
      if (strcmp (current->name, DOT_RELOC) == 0)
3603
0
  {
3604
0
    is_reloc_section = true;
3605
0
    hasrelocs = true;
3606
0
    pe_data (abfd)->has_reloc_section = 1;
3607
0
  }
3608
0
#endif
3609
3610
0
      internal_f.f_nscns++;
3611
3612
0
      strncpy (section.s_name, current->name, SCNNMLEN);
3613
3614
0
#ifdef COFF_LONG_SECTION_NAMES
3615
      /* Handle long section names as in PE.  This must be compatible
3616
   with the code in coff_write_symbols and _bfd_coff_final_link.  */
3617
0
      if (bfd_coff_long_section_names (abfd))
3618
0
  {
3619
0
    size_t len;
3620
3621
0
    len = strlen (current->name);
3622
0
    if (len > SCNNMLEN)
3623
0
      {
3624
3625
        /* An inherent limitation of the /nnnnnnn notation used to indicate
3626
     the offset of the long name in the string table is that we
3627
     cannot address entries beyone the ten million byte boundary.  */
3628
0
        if (string_size < 10000000)
3629
0
    {
3630
      /* The s_name field is defined to be NUL-padded but need not
3631
         be NUL-terminated.  We use a temporary buffer so that we
3632
         can still sprintf all eight chars without splatting a
3633
         terminating NUL over the first byte of the following
3634
         member (s_paddr).  */
3635
      /* PR 21096: The +20 is to stop a bogus warning from gcc7
3636
         about a possible buffer overflow.  */
3637
0
      char s_name_buf[SCNNMLEN + 1 + 20];
3638
3639
      /* We do not need to use snprintf here as we have already
3640
         verified that string_size is not too big, plus we have
3641
         an overlarge buffer, just in case.  */
3642
0
      sprintf (s_name_buf, "/%lu", (unsigned long) string_size);
3643
      /* Then strncpy takes care of any padding for us.  */
3644
0
      strncpy (section.s_name, s_name_buf, SCNNMLEN);
3645
0
    }
3646
0
        else
3647
0
#ifdef COFF_WITH_PE
3648
0
    {
3649
      /* PE use a base 64 encoding for long section names whose
3650
         index is very large.  But contrary to RFC 4648, there is
3651
         no padding: 6 characters must be generated.  */
3652
0
      static const char base64[] =
3653
0
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3654
0
        "abcdefghijklmnopqrstuvwxyz"
3655
0
        "0123456789+/";
3656
0
      unsigned long off = string_size;
3657
0
      unsigned i;
3658
3659
0
      section.s_name[0] = '/';
3660
0
      section.s_name[1] = '/';
3661
0
      for (i = SCNNMLEN - 1; i >= 2; i--)
3662
0
        {
3663
0
          section.s_name[i] = base64[off & 0x3f];
3664
0
          off >>= 6;
3665
0
        }
3666
0
    }
3667
0
#endif
3668
0
        if (string_size > 0xffffffffUL - (len + 1)
3669
#ifndef COFF_WITH_PE
3670
      || string_size >= 10000000
3671
#endif
3672
0
      )
3673
0
    {
3674
0
      bfd_set_error (bfd_error_file_too_big);
3675
0
      _bfd_error_handler
3676
        /* xgettext:c-format */
3677
0
        (_("%pB: section %pA: string table overflow at offset %ld"),
3678
0
        abfd, current, (unsigned long) string_size);
3679
0
      return false;
3680
0
    }
3681
3682
0
        string_size += len + 1;
3683
0
        long_section_names = true;
3684
0
      }
3685
0
  }
3686
0
#endif
3687
3688
0
#ifdef _LIB
3689
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
3690
   Ian Taylor <ian@cygnus.com>.  */
3691
0
      if (strcmp (current->name, _LIB) == 0)
3692
0
  section.s_vaddr = 0;
3693
0
      else
3694
0
#endif
3695
0
      section.s_vaddr = current->vma;
3696
0
      section.s_paddr = current->lma;
3697
0
      section.s_size =  current->size;
3698
#ifdef coff_get_section_load_page
3699
      section.s_page = coff_get_section_load_page (current);
3700
#else
3701
0
      section.s_page = 0;
3702
0
#endif
3703
3704
0
#ifdef COFF_WITH_PE
3705
0
      section.s_paddr = 0;
3706
0
#endif
3707
0
#ifdef COFF_IMAGE_WITH_PE
3708
      /* Reminder: s_paddr holds the virtual size of the section.  */
3709
0
      if (coff_section_data (abfd, current) != NULL
3710
0
    && pei_section_data (abfd, current) != NULL)
3711
0
  section.s_paddr = pei_section_data (abfd, current)->virt_size;
3712
0
      else
3713
0
  section.s_paddr = 0;
3714
0
#endif
3715
3716
      /* If this section has no size or is unloadable then the scnptr
3717
   will be 0 too.  */
3718
0
      if (current->size == 0
3719
0
    || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3720
0
  section.s_scnptr = 0;
3721
0
      else
3722
0
  section.s_scnptr = current->filepos;
3723
3724
0
      section.s_relptr = current->rel_filepos;
3725
0
      section.s_lnnoptr = current->line_filepos;
3726
0
      section.s_nreloc = current->reloc_count;
3727
0
      section.s_nlnno = current->lineno_count;
3728
#ifndef COFF_IMAGE_WITH_PE
3729
      /* In PEI, relocs come in the .reloc section.  */
3730
      if (current->reloc_count != 0)
3731
  hasrelocs = true;
3732
#endif
3733
0
      if (current->lineno_count != 0)
3734
0
  haslinno = true;
3735
0
#ifdef COFF_IMAGE_WITH_PE
3736
0
      if ((current->flags & SEC_DEBUGGING) != 0
3737
0
    && ! is_reloc_section)
3738
0
  hasdebug = true;
3739
0
#endif
3740
3741
#ifdef RS6000COFF_C
3742
#ifndef XCOFF64
3743
      /* Indicate the use of an XCOFF overflow section header.  */
3744
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3745
  {
3746
    section.s_nreloc = 0xffff;
3747
    section.s_nlnno = 0xffff;
3748
  }
3749
#endif
3750
#endif
3751
3752
0
      section.s_flags = sec_to_styp_flags (current->name, current->flags);
3753
3754
0
      if (!strcmp (current->name, _TEXT))
3755
0
  text_sec = current;
3756
0
      else if (!strcmp (current->name, _DATA))
3757
0
  data_sec = current;
3758
0
      else if (!strcmp (current->name, _BSS))
3759
0
  bss_sec = current;
3760
#ifdef RS6000COFF_C
3761
      else if (!strcmp (current->name, _TDATA))
3762
  tdata_sec = current;
3763
      else if (!strcmp (current->name, _TBSS))
3764
  tbss_sec = current;
3765
#endif
3766
3767
3768
0
#ifdef COFF_ENCODE_ALIGNMENT
3769
0
      if (COFF_ENCODE_ALIGNMENT (abfd, section, current->alignment_power)
3770
0
    && (COFF_DECODE_ALIGNMENT (section.s_flags)
3771
0
        != current->alignment_power))
3772
0
  {
3773
0
    bool warn = (coff_data (abfd)->link_info
3774
0
           && !bfd_link_relocatable (coff_data (abfd)->link_info));
3775
3776
0
    _bfd_error_handler
3777
      /* xgettext:c-format */
3778
0
      (_("%pB:%s section %s: alignment 2**%u not representable"),
3779
0
       abfd, warn ? " warning:" : "", current->name,
3780
0
       current->alignment_power);
3781
0
    if (!warn)
3782
0
      {
3783
0
        bfd_set_error (bfd_error_nonrepresentable_section);
3784
0
        return false;
3785
0
      }
3786
0
  }
3787
0
#endif
3788
3789
0
#ifdef COFF_IMAGE_WITH_PE
3790
      /* Suppress output of the sections if they are null.  ld
3791
   includes the bss and data sections even if there is no size
3792
   assigned to them.  NT loader doesn't like it if these section
3793
   headers are included if the sections themselves are not
3794
   needed.  See also coff_compute_section_file_positions.  */
3795
0
      if (section.s_size == 0)
3796
0
  internal_f.f_nscns--;
3797
0
      else
3798
0
#endif
3799
0
  {
3800
0
    SCNHDR buff;
3801
0
    bfd_size_type amt = bfd_coff_scnhsz (abfd);
3802
3803
0
    if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
3804
0
        || bfd_write (& buff, amt, abfd) != amt)
3805
0
      return false;
3806
0
  }
3807
3808
0
#ifdef COFF_WITH_PE
3809
      /* PE stores COMDAT section information in the symbol table.  If
3810
   this section is supposed to have some COMDAT info, track down
3811
   the symbol in the symbol table and modify it.  */
3812
0
      if ((current->flags & SEC_LINK_ONCE) != 0)
3813
0
  {
3814
0
    unsigned int i, count;
3815
0
    asymbol **psym;
3816
0
    coff_symbol_type *csym = NULL;
3817
0
    asymbol **psymsec;
3818
3819
0
    psymsec = NULL;
3820
0
    count = bfd_get_symcount (abfd);
3821
0
    for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
3822
0
      {
3823
0
        if ((*psym)->section != current)
3824
0
    continue;
3825
3826
        /* Remember the location of the first symbol in this
3827
     section.  */
3828
0
        if (psymsec == NULL)
3829
0
    psymsec = psym;
3830
3831
        /* See if this is the section symbol.  */
3832
0
        if (strcmp ((*psym)->name, current->name) == 0)
3833
0
    {
3834
0
      csym = coff_symbol_from (*psym);
3835
0
      if (csym == NULL
3836
0
          || csym->native == NULL
3837
0
          || ! csym->native->is_sym
3838
0
          || csym->native->u.syment.n_numaux < 1
3839
0
          || csym->native->u.syment.n_sclass != C_STAT
3840
0
          || csym->native->u.syment.n_type != T_NULL)
3841
0
        continue;
3842
3843
      /* Here *PSYM is the section symbol for CURRENT.  */
3844
3845
0
      break;
3846
0
    }
3847
0
      }
3848
3849
    /* Did we find it?
3850
       Note that we might not if we're converting the file from
3851
       some other object file format.  */
3852
0
    if (i < count)
3853
0
      {
3854
0
        combined_entry_type *aux;
3855
3856
        /* We don't touch the x_checksum field.  The
3857
     x_associated field is not currently supported.  */
3858
3859
0
        aux = csym->native + 1;
3860
0
        BFD_ASSERT (! aux->is_sym);
3861
0
        switch (current->flags & SEC_LINK_DUPLICATES)
3862
0
    {
3863
0
    case SEC_LINK_DUPLICATES_DISCARD:
3864
0
      aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
3865
0
      break;
3866
3867
0
    case SEC_LINK_DUPLICATES_ONE_ONLY:
3868
0
      aux->u.auxent.x_scn.x_comdat =
3869
0
        IMAGE_COMDAT_SELECT_NODUPLICATES;
3870
0
      break;
3871
3872
0
    case SEC_LINK_DUPLICATES_SAME_SIZE:
3873
0
      aux->u.auxent.x_scn.x_comdat =
3874
0
        IMAGE_COMDAT_SELECT_SAME_SIZE;
3875
0
      break;
3876
3877
0
    case SEC_LINK_DUPLICATES_SAME_CONTENTS:
3878
0
      aux->u.auxent.x_scn.x_comdat =
3879
0
        IMAGE_COMDAT_SELECT_EXACT_MATCH;
3880
0
      break;
3881
0
    }
3882
3883
        /* The COMDAT symbol must be the first symbol from this
3884
     section in the symbol table.  In order to make this
3885
     work, we move the COMDAT symbol before the first
3886
     symbol we found in the search above.  It's OK to
3887
     rearrange the symbol table at this point, because
3888
     coff_renumber_symbols is going to rearrange it
3889
     further and fix up all the aux entries.  */
3890
0
        if (psym != psymsec)
3891
0
    {
3892
0
      asymbol *hold;
3893
0
      asymbol **pcopy;
3894
3895
0
      hold = *psym;
3896
0
      for (pcopy = psym; pcopy > psymsec; pcopy--)
3897
0
        pcopy[0] = pcopy[-1];
3898
0
      *psymsec = hold;
3899
0
    }
3900
0
      }
3901
0
  }
3902
0
#endif /* COFF_WITH_PE */
3903
0
    }
3904
3905
#ifdef RS6000COFF_C
3906
#ifndef XCOFF64
3907
  /* XCOFF handles overflows in the reloc and line number count fields
3908
     by creating a new section header to hold the correct values.  */
3909
  for (current = abfd->sections; current != NULL; current = current->next)
3910
    {
3911
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
3912
  {
3913
    struct internal_scnhdr scnhdr;
3914
    SCNHDR buff;
3915
    bfd_size_type amt;
3916
3917
    internal_f.f_nscns++;
3918
    memcpy (scnhdr.s_name, ".ovrflo", 8);
3919
    scnhdr.s_paddr = current->reloc_count;
3920
    scnhdr.s_vaddr = current->lineno_count;
3921
    scnhdr.s_size = 0;
3922
    scnhdr.s_scnptr = 0;
3923
    scnhdr.s_relptr = current->rel_filepos;
3924
    scnhdr.s_lnnoptr = current->line_filepos;
3925
    scnhdr.s_nreloc = current->target_index;
3926
    scnhdr.s_nlnno = current->target_index;
3927
    scnhdr.s_flags = STYP_OVRFLO;
3928
    amt = bfd_coff_scnhsz (abfd);
3929
    if (bfd_coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
3930
        || bfd_write (& buff, amt, abfd) != amt)
3931
      return false;
3932
  }
3933
    }
3934
#endif
3935
#endif
3936
3937
#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
3938
  /* Pad section headers.  */
3939
  if ((abfd->flags & EXEC_P) != 0)
3940
    {
3941
      asection *s = abfd->sections;
3942
      while (s != NULL && s->filepos == 0)
3943
  s = s->next;
3944
      if (s != NULL)
3945
  {
3946
    file_ptr cur_ptr
3947
      = scn_base + abfd->section_count * bfd_coff_scnhsz (abfd);
3948
    file_ptr fill_size = s->filepos - cur_ptr;
3949
    if (fill_size > 0)
3950
      {
3951
        bfd_byte *b = bfd_zmalloc (fill_size);
3952
        if (!b)
3953
    return false;
3954
        if (bfd_write (b, fill_size, abfd) != (ufile_ptr) fill_size)
3955
    {
3956
      free (b);
3957
      return false;
3958
    }
3959
        free (b);
3960
      }
3961
  }
3962
    }
3963
#endif
3964
3965
  /* OK, now set up the filehdr...  */
3966
3967
  /* Don't include the internal abs section in the section count */
3968
3969
  /* We will NOT put a fucking timestamp in the header here. Every time you
3970
     put it back, I will come in and take it out again.  I'm sorry.  This
3971
     field does not belong here.  We fill it with a 0 so it compares the
3972
     same but is not a reasonable time. -- gnu@cygnus.com  */
3973
1
  internal_f.f_timdat = 0;
3974
1
  internal_f.f_flags = 0;
3975
3976
1
  if (abfd->flags & EXEC_P)
3977
0
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3978
1
  else
3979
1
    {
3980
1
      internal_f.f_opthdr = 0;
3981
#ifdef RS6000COFF_C
3982
#ifndef XCOFF64
3983
      if (xcoff_data (abfd)->full_aouthdr)
3984
  internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
3985
      else
3986
  internal_f.f_opthdr = SMALL_AOUTSZ;
3987
#endif
3988
#endif
3989
1
    }
3990
3991
1
  if (!hasrelocs)
3992
1
    internal_f.f_flags |= F_RELFLG;
3993
1
  if (!haslinno)
3994
1
    internal_f.f_flags |= F_LNNO;
3995
1
  if (abfd->flags & EXEC_P)
3996
0
    internal_f.f_flags |= F_EXEC;
3997
1
#ifdef COFF_IMAGE_WITH_PE
3998
1
  if (! hasdebug)
3999
1
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
4000
1
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
4001
1
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
4002
1
#endif
4003
4004
1
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
4005
1
#ifdef COFF_WITH_PE
4006
1
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
4007
#else
4008
  if (bfd_little_endian (abfd))
4009
    internal_f.f_flags |= F_AR32WR;
4010
  else
4011
    internal_f.f_flags |= F_AR32W;
4012
#endif
4013
1
#endif
4014
4015
#ifdef TI_TARGET_ID
4016
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
4017
     but it doesn't hurt to set it internally.  */
4018
  internal_f.f_target_id = TI_TARGET_ID;
4019
#endif
4020
4021
  /* FIXME, should do something about the other byte orders and
4022
     architectures.  */
4023
4024
#ifdef RS6000COFF_C
4025
  if ((abfd->flags & DYNAMIC) != 0)
4026
    internal_f.f_flags |= F_SHROBJ;
4027
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
4028
    internal_f.f_flags |= F_DYNLOAD;
4029
#endif
4030
4031
1
  memset (&internal_a, 0, sizeof internal_a);
4032
4033
  /* Set up architecture-dependent stuff.  */
4034
1
  {
4035
1
    unsigned int magic = 0;
4036
1
    unsigned short flags = 0;
4037
4038
1
    coff_set_flags (abfd, &magic, &flags);
4039
1
    internal_f.f_magic = magic;
4040
1
    internal_f.f_flags |= flags;
4041
    /* ...and the "opt"hdr...  */
4042
4043
#ifdef TICOFF_AOUT_MAGIC
4044
    internal_a.magic = TICOFF_AOUT_MAGIC;
4045
#define __A_MAGIC_SET__
4046
#endif
4047
4048
#if defined(ARM)
4049
#define __A_MAGIC_SET__
4050
    internal_a.magic = ZMAGIC;
4051
#endif
4052
4053
#if defined(AARCH64)
4054
#define __A_MAGIC_SET__
4055
    internal_a.magic = ZMAGIC;
4056
#endif
4057
4058
#if defined(LOONGARCH64)
4059
#define __A_MAGIC_SET__
4060
    internal_a.magic = ZMAGIC;
4061
#endif
4062
4063
#if defined MCORE_PE
4064
#define __A_MAGIC_SET__
4065
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
4066
#endif
4067
4068
#if defined(I386)
4069
#define __A_MAGIC_SET__
4070
#if defined LYNXOS
4071
    internal_a.magic = LYNXCOFFMAGIC;
4072
#elif defined AMD64
4073
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
4074
#else
4075
    internal_a.magic = ZMAGIC;
4076
#endif
4077
#endif /* I386 */
4078
4079
#if defined(IA64)
4080
#define __A_MAGIC_SET__
4081
    internal_a.magic = PE32PMAGIC;
4082
#endif /* IA64 */
4083
4084
#if defined(SPARC)
4085
#define __A_MAGIC_SET__
4086
#if defined(LYNXOS)
4087
    internal_a.magic = LYNXCOFFMAGIC;
4088
#endif /* LYNXOS */
4089
#endif /* SPARC */
4090
4091
#ifdef RS6000COFF_C
4092
#define __A_MAGIC_SET__
4093
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
4094
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
4095
    RS6K_AOUTHDR_OMAGIC;
4096
#endif
4097
4098
1
#if defined(SH) && defined(COFF_WITH_PE)
4099
1
#define __A_MAGIC_SET__
4100
1
    internal_a.magic = SH_PE_MAGIC;
4101
1
#endif
4102
4103
#if defined(MIPS) && defined(COFF_WITH_PE)
4104
#define __A_MAGIC_SET__
4105
    internal_a.magic = MIPS_PE_MAGIC;
4106
#endif
4107
4108
#ifndef __A_MAGIC_SET__
4109
#include "Your aouthdr magic number is not being set!"
4110
#else
4111
1
#undef __A_MAGIC_SET__
4112
1
#endif
4113
1
  }
4114
4115
#ifdef RS6000COFF_C
4116
  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
4117
  internal_a.vstamp = 2;
4118
#else
4119
  /* FIXME: Does anybody ever set this to another value?  */
4120
1
  internal_a.vstamp = 0;
4121
1
#endif
4122
4123
  /* Now should write relocs, strings, syms.  */
4124
1
  obj_sym_filepos (abfd) = sym_base;
4125
4126
1
  if (bfd_get_symcount (abfd) != 0)
4127
0
    {
4128
0
      int firstundef;
4129
4130
0
      if (!coff_renumber_symbols (abfd, &firstundef))
4131
0
  return false;
4132
0
      coff_mangle_symbols (abfd);
4133
0
      if (! coff_write_symbols (abfd))
4134
0
  return false;
4135
0
      if (! coff_write_linenumbers (abfd))
4136
0
  return false;
4137
0
      if (! coff_write_relocs (abfd, firstundef))
4138
0
  return false;
4139
0
    }
4140
1
#ifdef COFF_LONG_SECTION_NAMES
4141
1
  else if (long_section_names && ! obj_coff_strings_written (abfd))
4142
0
    {
4143
      /* If we have long section names we have to write out the string
4144
   table even if there are no symbols.  */
4145
0
      if (! coff_write_symbols (abfd))
4146
0
  return false;
4147
0
    }
4148
1
#endif
4149
  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
4150
     backend linker, and obj_raw_syment_count is not valid until after
4151
     coff_write_symbols is called.  */
4152
1
  if (obj_raw_syment_count (abfd) != 0)
4153
0
    {
4154
0
      internal_f.f_symptr = sym_base;
4155
#ifdef RS6000COFF_C
4156
      /* AIX appears to require that F_RELFLG not be set if there are
4157
   local symbols but no relocations.  */
4158
      internal_f.f_flags &=~ F_RELFLG;
4159
#endif
4160
0
    }
4161
1
  else
4162
1
    {
4163
1
      if (long_section_names)
4164
0
  internal_f.f_symptr = sym_base;
4165
1
      else
4166
1
  internal_f.f_symptr = 0;
4167
1
      internal_f.f_flags |= F_LSYMS;
4168
1
    }
4169
4170
1
  if (text_sec)
4171
0
    {
4172
0
      internal_a.tsize = text_sec->size;
4173
0
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
4174
0
    }
4175
1
  if (data_sec)
4176
0
    {
4177
0
      internal_a.dsize = data_sec->size;
4178
0
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
4179
0
    }
4180
1
  if (bss_sec)
4181
0
    {
4182
0
      internal_a.bsize = bss_sec->size;
4183
0
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
4184
0
  internal_a.data_start = bss_sec->vma;
4185
0
    }
4186
4187
1
  internal_a.entry = bfd_get_start_address (abfd);
4188
1
  internal_f.f_nsyms = obj_raw_syment_count (abfd);
4189
4190
#ifdef RS6000COFF_C
4191
  if (xcoff_data (abfd)->full_aouthdr)
4192
    {
4193
      bfd_vma toc;
4194
      asection *loader_sec;
4195
4196
      internal_a.vstamp = 2;
4197
4198
      internal_a.o_snentry = xcoff_data (abfd)->snentry;
4199
      if (internal_a.o_snentry == 0)
4200
  internal_a.entry = (bfd_vma) -1;
4201
4202
      if (text_sec != NULL)
4203
  {
4204
    internal_a.o_sntext = text_sec->target_index;
4205
    internal_a.o_algntext = bfd_section_alignment (text_sec);
4206
  }
4207
      else
4208
  {
4209
    internal_a.o_sntext = 0;
4210
    internal_a.o_algntext = 0;
4211
  }
4212
      if (data_sec != NULL)
4213
  {
4214
    internal_a.o_sndata = data_sec->target_index;
4215
    internal_a.o_algndata = bfd_section_alignment (data_sec);
4216
  }
4217
      else
4218
  {
4219
    internal_a.o_sndata = 0;
4220
    internal_a.o_algndata = 0;
4221
  }
4222
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
4223
      if (loader_sec != NULL)
4224
  internal_a.o_snloader = loader_sec->target_index;
4225
      else
4226
  internal_a.o_snloader = 0;
4227
      if (bss_sec != NULL)
4228
  internal_a.o_snbss = bss_sec->target_index;
4229
      else
4230
  internal_a.o_snbss = 0;
4231
4232
      if (tdata_sec != NULL)
4233
  {
4234
    internal_a.o_sntdata = tdata_sec->target_index;
4235
    /* TODO: o_flags should be set to RS6K_AOUTHDR_TLS_LE
4236
       if there is at least one R_TLS_LE relocations.  */
4237
    internal_a.o_flags = 0;
4238
#ifdef XCOFF64
4239
    internal_a.o_x64flags = 0;
4240
#endif
4241
  }
4242
      else
4243
  {
4244
    internal_a.o_sntdata = 0;
4245
    internal_a.o_flags = 0;
4246
#ifdef XCOFF64
4247
    internal_a.o_x64flags = 0;
4248
#endif
4249
  }
4250
      if (tbss_sec != NULL)
4251
    internal_a.o_sntbss = tbss_sec->target_index;
4252
      else
4253
    internal_a.o_sntbss = 0;
4254
4255
      toc = xcoff_data (abfd)->toc;
4256
      internal_a.o_toc = toc;
4257
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
4258
4259
      internal_a.o_modtype = xcoff_data (abfd)->modtype;
4260
      if (xcoff_data (abfd)->cputype != -1)
4261
  internal_a.o_cputype = xcoff_data (abfd)->cputype;
4262
      else
4263
  {
4264
    switch (bfd_get_arch (abfd))
4265
      {
4266
      case bfd_arch_rs6000:
4267
        internal_a.o_cputype = 4;
4268
        break;
4269
      case bfd_arch_powerpc:
4270
        if (bfd_get_mach (abfd) == bfd_mach_ppc)
4271
    internal_a.o_cputype = 3;
4272
        else if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
4273
    internal_a.o_cputype = 2;
4274
        else
4275
    internal_a.o_cputype = 1;
4276
        break;
4277
      default:
4278
        abort ();
4279
      }
4280
  }
4281
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
4282
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
4283
    }
4284
#endif
4285
4286
1
#ifdef COFF_WITH_PE
4287
1
  {
4288
    /* After object contents are finalized so we can compute a reasonable hash,
4289
       but before header is written so we can update it to point to debug directory.  */
4290
1
    struct pe_tdata *pe = pe_data (abfd);
4291
4292
1
    if (pe->build_id.after_write_object_contents != NULL)
4293
0
      (*pe->build_id.after_write_object_contents) (abfd);
4294
1
  }
4295
1
#endif
4296
4297
  /* Now write header.  */
4298
1
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4299
0
    return false;
4300
4301
1
  {
4302
1
    char * buff;
4303
1
    bfd_size_type amount = bfd_coff_filhsz (abfd);
4304
4305
1
    buff = (char *) bfd_malloc (amount);
4306
1
    if (buff == NULL)
4307
0
      return false;
4308
4309
1
    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
4310
1
    amount = bfd_write (buff, amount, abfd);
4311
4312
1
    free (buff);
4313
4314
1
    if (amount != bfd_coff_filhsz (abfd))
4315
0
      return false;
4316
1
  }
4317
4318
1
  if (abfd->flags & EXEC_P)
4319
0
    {
4320
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
4321
   include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
4322
0
      char * buff;
4323
0
      bfd_size_type amount = bfd_coff_aoutsz (abfd);
4324
4325
0
      buff = (char *) bfd_malloc (amount);
4326
0
      if (buff == NULL)
4327
0
  return false;
4328
4329
0
      coff_swap_aouthdr_out (abfd, & internal_a, buff);
4330
0
      amount = bfd_write (buff, amount, abfd);
4331
4332
0
      free (buff);
4333
4334
0
      if (amount != bfd_coff_aoutsz (abfd))
4335
0
  return false;
4336
4337
0
#ifdef COFF_IMAGE_WITH_PE
4338
0
      if (! coff_apply_checksum (abfd))
4339
0
  return false;
4340
0
#endif
4341
0
    }
4342
#ifdef RS6000COFF_C
4343
#ifndef XCOFF64
4344
  else
4345
    {
4346
      AOUTHDR buff;
4347
      size_t size;
4348
4349
      /* XCOFF32 seems to always write at least a small a.out header.  */
4350
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
4351
      if (xcoff_data (abfd)->full_aouthdr)
4352
  size = bfd_coff_aoutsz (abfd);
4353
      else
4354
  size = SMALL_AOUTSZ;
4355
      if (bfd_write (&buff, size, abfd) != size)
4356
  return false;
4357
    }
4358
#endif
4359
#endif
4360
4361
1
  return true;
4362
1
}
4363
4364
static bool
4365
coff_set_section_contents (bfd * abfd,
4366
         sec_ptr section,
4367
         const void * location,
4368
         file_ptr offset,
4369
         bfd_size_type count)
4370
101
{
4371
101
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
16
    {
4373
16
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
16
    }
4376
4377
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
101
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
  rec = (bfd_byte *) location;
4403
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
101
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
101
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
101
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
101
  if (count == 0)
4426
0
    return true;
4427
4428
101
  return bfd_write (location, count, abfd) == count;
4429
101
}
pei-i386.c:coff_set_section_contents
Line
Count
Source
4370
14
{
4371
14
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
2
    {
4373
2
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
2
    }
4376
4377
14
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
14
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
14
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
14
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
14
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
14
  if (count == 0)
4426
0
    return true;
4427
4428
14
  return bfd_write (location, count, abfd) == count;
4429
14
}
Unexecuted instantiation: pe-x86_64.c:coff_set_section_contents
pei-x86_64.c:coff_set_section_contents
Line
Count
Source
4370
75
{
4371
75
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
6
    {
4373
6
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
6
    }
4376
4377
75
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
75
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
75
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
75
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
75
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
75
  if (count == 0)
4426
0
    return true;
4427
4428
75
  return bfd_write (location, count, abfd) == count;
4429
75
}
Unexecuted instantiation: coff-x86_64.c:coff_set_section_contents
Unexecuted instantiation: coff64-rs6000.c:coff_set_section_contents
Unexecuted instantiation: pe-aarch64.c:coff_set_section_contents
pei-aarch64.c:coff_set_section_contents
Line
Count
Source
4370
4
{
4371
4
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
2
    {
4373
2
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
2
    }
4376
4377
4
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
4
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
4
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
4
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
4
  if (count == 0)
4426
0
    return true;
4427
4428
4
  return bfd_write (location, count, abfd) == count;
4429
4
}
Unexecuted instantiation: pei-ia64.c:coff_set_section_contents
Unexecuted instantiation: pei-loongarch64.c:coff_set_section_contents
Unexecuted instantiation: cf-i386lynx.c:coff_set_section_contents
Unexecuted instantiation: coff-go32.c:coff_set_section_contents
Unexecuted instantiation: coff-i386.c:coff_set_section_contents
Unexecuted instantiation: coff-rs6000.c:coff_set_section_contents
Unexecuted instantiation: coff-sh.c:coff_set_section_contents
Unexecuted instantiation: coff-stgo32.c:coff_set_section_contents
Unexecuted instantiation: coff-tic30.c:coff_set_section_contents
Unexecuted instantiation: coff-tic4x.c:coff_set_section_contents
Unexecuted instantiation: coff-tic54x.c:coff_set_section_contents
Unexecuted instantiation: coff-z80.c:coff_set_section_contents
coff-z8k.c:coff_set_section_contents
Line
Count
Source
4370
4
{
4371
4
  if (! abfd->output_has_begun) /* Set by bfd.c handler.  */
4372
4
    {
4373
4
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
4
    }
4376
4377
4
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
4
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
4
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
4
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
4
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
4
  if (count == 0)
4426
0
    return true;
4427
4428
4
  return bfd_write (location, count, abfd) == count;
4429
4
}
Unexecuted instantiation: pe-arm-wince.c:coff_set_section_contents
Unexecuted instantiation: pe-arm.c:coff_set_section_contents
pe-i386.c:coff_set_section_contents
Line
Count
Source
4370
2
{
4371
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
1
    {
4373
1
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
1
    }
4376
4377
2
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
2
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
2
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
2
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
2
  if (count == 0)
4426
0
    return true;
4427
4428
2
  return bfd_write (location, count, abfd) == count;
4429
2
}
Unexecuted instantiation: pe-mcore.c:coff_set_section_contents
Unexecuted instantiation: pe-sh.c:coff_set_section_contents
pei-arm-wince.c:coff_set_section_contents
Line
Count
Source
4370
2
{
4371
2
  if (! abfd->output_has_begun)  /* Set by bfd.c handler.  */
4372
1
    {
4373
1
      if (! coff_compute_section_file_positions (abfd))
4374
0
  return false;
4375
1
    }
4376
4377
2
#if defined(_LIB) && !defined(TARG_AUX)
4378
   /* The physical address field of a .lib section is used to hold the
4379
      number of shared libraries in the section.  This code counts the
4380
      number of sections being written, and increments the lma field
4381
      with the number.
4382
4383
      I have found no documentation on the contents of this section.
4384
      Experimentation indicates that the section contains zero or more
4385
      records, each of which has the following structure:
4386
4387
      - a (four byte) word holding the length of this record, in words,
4388
      - a word that always seems to be set to "2",
4389
      - the path to a shared library, null-terminated and then padded
4390
  to a whole word boundary.
4391
4392
      bfd_assert calls have been added to alert if an attempt is made
4393
      to write a section which doesn't follow these assumptions.  The
4394
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
4395
      <robertl@arnet.com> (Thanks!).
4396
4397
      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
4398
2
    if (strcmp (section->name, _LIB) == 0)
4399
0
      {
4400
0
  bfd_byte *rec, *recend;
4401
4402
0
  rec = (bfd_byte *) location;
4403
0
  recend = rec + count;
4404
0
  while (recend - rec >= 4)
4405
0
    {
4406
0
      size_t len = bfd_get_32 (abfd, rec);
4407
0
      if (len == 0 || len > (size_t) (recend - rec) / 4)
4408
0
        break;
4409
0
      rec += len * 4;
4410
0
      ++section->lma;
4411
0
    }
4412
4413
0
  BFD_ASSERT (rec == recend);
4414
0
      }
4415
2
#endif
4416
4417
  /* Don't write out bss sections - one way to do this is to
4418
       see if the filepos has not been set.  */
4419
2
  if (section->filepos == 0)
4420
0
    return true;
4421
4422
2
  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
4423
0
    return false;
4424
4425
2
  if (count == 0)
4426
0
    return true;
4427
4428
2
  return bfd_write (location, count, abfd) == count;
4429
2
}
Unexecuted instantiation: pei-arm.c:coff_set_section_contents
Unexecuted instantiation: pei-mcore.c:coff_set_section_contents
Unexecuted instantiation: pei-sh.c:coff_set_section_contents
4430
4431
static void *
4432
buy_and_read (bfd *abfd, file_ptr where,
4433
        bfd_size_type nmemb, bfd_size_type size)
4434
25.0k
{
4435
25.0k
  size_t amt;
4436
4437
25.0k
  if (_bfd_mul_overflow (nmemb, size, &amt))
4438
0
    {
4439
0
      bfd_set_error (bfd_error_file_too_big);
4440
0
      return NULL;
4441
0
    }
4442
25.0k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
307
    return NULL;
4444
24.7k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
25.0k
}
pei-i386.c:buy_and_read
Line
Count
Source
4434
323
{
4435
323
  size_t amt;
4436
4437
323
  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
323
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
323
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
323
}
pe-x86_64.c:buy_and_read
Line
Count
Source
4434
753
{
4435
753
  size_t amt;
4436
4437
753
  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
753
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
753
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
753
}
pei-x86_64.c:buy_and_read
Line
Count
Source
4434
402
{
4435
402
  size_t amt;
4436
4437
402
  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
402
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
402
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
402
}
coff-x86_64.c:buy_and_read
Line
Count
Source
4434
1.48k
{
4435
1.48k
  size_t amt;
4436
4437
1.48k
  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
1.48k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
1.48k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
1.48k
}
coff64-rs6000.c:buy_and_read
Line
Count
Source
4434
925
{
4435
925
  size_t amt;
4436
4437
925
  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
925
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
307
    return NULL;
4444
618
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
925
}
pe-aarch64.c:buy_and_read
Line
Count
Source
4434
1.02k
{
4435
1.02k
  size_t amt;
4436
4437
1.02k
  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
1.02k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
1.02k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
1.02k
}
pei-aarch64.c:buy_and_read
Line
Count
Source
4434
409
{
4435
409
  size_t amt;
4436
4437
409
  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
409
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
409
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
409
}
pei-ia64.c:buy_and_read
Line
Count
Source
4434
506
{
4435
506
  size_t amt;
4436
4437
506
  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
506
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
506
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
506
}
pei-loongarch64.c:buy_and_read
Line
Count
Source
4434
346
{
4435
346
  size_t amt;
4436
4437
346
  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
346
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
346
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
346
}
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
785
{
4435
785
  size_t amt;
4436
4437
785
  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
785
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
785
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
785
}
coff-sh.c:buy_and_read
Line
Count
Source
4434
1.35k
{
4435
1.35k
  size_t amt;
4436
4437
1.35k
  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
1.35k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
1.35k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
1.35k
}
Unexecuted instantiation: coff-stgo32.c:buy_and_read
coff-tic30.c:buy_and_read
Line
Count
Source
4434
10.8k
{
4435
10.8k
  size_t amt;
4436
4437
10.8k
  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.8k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
10.8k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
10.8k
}
Unexecuted instantiation: coff-tic4x.c:buy_and_read
coff-tic54x.c:buy_and_read
Line
Count
Source
4434
1.29k
{
4435
1.29k
  size_t amt;
4436
4437
1.29k
  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
1.29k
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
1.29k
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
1.29k
}
coff-z80.c:buy_and_read
Line
Count
Source
4434
813
{
4435
813
  size_t amt;
4436
4437
813
  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
813
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
813
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
813
}
coff-z8k.c:buy_and_read
Line
Count
Source
4434
818
{
4435
818
  size_t amt;
4436
4437
818
  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
818
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
818
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
818
}
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
469
{
4435
469
  size_t amt;
4436
4437
469
  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
469
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
469
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
469
}
pe-mcore.c:buy_and_read
Line
Count
Source
4434
688
{
4435
688
  size_t amt;
4436
4437
688
  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
688
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
688
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
688
}
pe-sh.c:buy_and_read
Line
Count
Source
4434
514
{
4435
514
  size_t amt;
4436
4437
514
  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
514
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
514
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
514
}
pei-arm-wince.c:buy_and_read
Line
Count
Source
4434
265
{
4435
265
  size_t amt;
4436
4437
265
  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
265
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
265
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
265
}
pei-arm.c:buy_and_read
Line
Count
Source
4434
362
{
4435
362
  size_t amt;
4436
4437
362
  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
362
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
362
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
362
}
pei-mcore.c:buy_and_read
Line
Count
Source
4434
312
{
4435
312
  size_t amt;
4436
4437
312
  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
312
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
312
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
312
}
pei-sh.c:buy_and_read
Line
Count
Source
4434
344
{
4435
344
  size_t amt;
4436
4437
344
  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
344
  if (bfd_seek (abfd, where, SEEK_SET) != 0)
4443
0
    return NULL;
4444
344
  return _bfd_malloc_and_read (abfd, amt, amt);
4445
344
}
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
9.32M
{
4473
9.32M
  const alent *al1 = *(const alent **) arg1;
4474
9.32M
  const alent *al2 = *(const alent **) arg2;
4475
9.32M
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
9.32M
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
9.32M
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
9.32M
  if (s1->symbol.value < s2->symbol.value)
4481
104k
    return -1;
4482
9.22M
  else if (s1->symbol.value > s2->symbol.value)
4483
1.93M
    return 1;
4484
4485
7.29M
  return 0;
4486
9.32M
}
pei-i386.c:coff_sort_func_alent
Line
Count
Source
4472
430k
{
4473
430k
  const alent *al1 = *(const alent **) arg1;
4474
430k
  const alent *al2 = *(const alent **) arg2;
4475
430k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
430k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
430k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
430k
  if (s1->symbol.value < s2->symbol.value)
4481
7.28k
    return -1;
4482
422k
  else if (s1->symbol.value > s2->symbol.value)
4483
85.1k
    return 1;
4484
4485
337k
  return 0;
4486
430k
}
pe-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
271k
{
4473
271k
  const alent *al1 = *(const alent **) arg1;
4474
271k
  const alent *al2 = *(const alent **) arg2;
4475
271k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
271k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
271k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
271k
  if (s1->symbol.value < s2->symbol.value)
4481
2.83k
    return -1;
4482
268k
  else if (s1->symbol.value > s2->symbol.value)
4483
56.6k
    return 1;
4484
4485
211k
  return 0;
4486
271k
}
pei-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
400k
{
4473
400k
  const alent *al1 = *(const alent **) arg1;
4474
400k
  const alent *al2 = *(const alent **) arg2;
4475
400k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
400k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
400k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
400k
  if (s1->symbol.value < s2->symbol.value)
4481
4.78k
    return -1;
4482
395k
  else if (s1->symbol.value > s2->symbol.value)
4483
70.6k
    return 1;
4484
4485
325k
  return 0;
4486
400k
}
coff-x86_64.c:coff_sort_func_alent
Line
Count
Source
4472
542k
{
4473
542k
  const alent *al1 = *(const alent **) arg1;
4474
542k
  const alent *al2 = *(const alent **) arg2;
4475
542k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
542k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
542k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
542k
  if (s1->symbol.value < s2->symbol.value)
4481
6.21k
    return -1;
4482
536k
  else if (s1->symbol.value > s2->symbol.value)
4483
130k
    return 1;
4484
4485
406k
  return 0;
4486
542k
}
coff64-rs6000.c:coff_sort_func_alent
Line
Count
Source
4472
541k
{
4473
541k
  const alent *al1 = *(const alent **) arg1;
4474
541k
  const alent *al2 = *(const alent **) arg2;
4475
541k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
541k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
541k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
541k
  if (s1->symbol.value < s2->symbol.value)
4481
5.00k
    return -1;
4482
536k
  else if (s1->symbol.value > s2->symbol.value)
4483
108k
    return 1;
4484
4485
427k
  return 0;
4486
541k
}
pe-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
181k
{
4473
181k
  const alent *al1 = *(const alent **) arg1;
4474
181k
  const alent *al2 = *(const alent **) arg2;
4475
181k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
181k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
181k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
181k
  if (s1->symbol.value < s2->symbol.value)
4481
3.27k
    return -1;
4482
178k
  else if (s1->symbol.value > s2->symbol.value)
4483
22.4k
    return 1;
4484
4485
155k
  return 0;
4486
181k
}
pei-aarch64.c:coff_sort_func_alent
Line
Count
Source
4472
484k
{
4473
484k
  const alent *al1 = *(const alent **) arg1;
4474
484k
  const alent *al2 = *(const alent **) arg2;
4475
484k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
484k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
484k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
484k
  if (s1->symbol.value < s2->symbol.value)
4481
6.26k
    return -1;
4482
478k
  else if (s1->symbol.value > s2->symbol.value)
4483
56.0k
    return 1;
4484
4485
422k
  return 0;
4486
484k
}
pei-ia64.c:coff_sort_func_alent
Line
Count
Source
4472
223k
{
4473
223k
  const alent *al1 = *(const alent **) arg1;
4474
223k
  const alent *al2 = *(const alent **) arg2;
4475
223k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
223k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
223k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
223k
  if (s1->symbol.value < s2->symbol.value)
4481
3.03k
    return -1;
4482
219k
  else if (s1->symbol.value > s2->symbol.value)
4483
36.7k
    return 1;
4484
4485
183k
  return 0;
4486
223k
}
pei-loongarch64.c:coff_sort_func_alent
Line
Count
Source
4472
597k
{
4473
597k
  const alent *al1 = *(const alent **) arg1;
4474
597k
  const alent *al2 = *(const alent **) arg2;
4475
597k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
597k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
597k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
597k
  if (s1->symbol.value < s2->symbol.value)
4481
6.99k
    return -1;
4482
590k
  else if (s1->symbol.value > s2->symbol.value)
4483
196k
    return 1;
4484
4485
394k
  return 0;
4486
597k
}
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
777k
{
4473
777k
  const alent *al1 = *(const alent **) arg1;
4474
777k
  const alent *al2 = *(const alent **) arg2;
4475
777k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
777k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
777k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
777k
  if (s1->symbol.value < s2->symbol.value)
4481
2.89k
    return -1;
4482
774k
  else if (s1->symbol.value > s2->symbol.value)
4483
126k
    return 1;
4484
4485
648k
  return 0;
4486
777k
}
coff-sh.c:coff_sort_func_alent
Line
Count
Source
4472
184k
{
4473
184k
  const alent *al1 = *(const alent **) arg1;
4474
184k
  const alent *al2 = *(const alent **) arg2;
4475
184k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
184k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
184k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
184k
  if (s1->symbol.value < s2->symbol.value)
4481
3.43k
    return -1;
4482
181k
  else if (s1->symbol.value > s2->symbol.value)
4483
34.2k
    return 1;
4484
4485
146k
  return 0;
4486
184k
}
Unexecuted instantiation: coff-stgo32.c:coff_sort_func_alent
coff-tic30.c:coff_sort_func_alent
Line
Count
Source
4472
206k
{
4473
206k
  const alent *al1 = *(const alent **) arg1;
4474
206k
  const alent *al2 = *(const alent **) arg2;
4475
206k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
206k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
206k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
206k
  if (s1->symbol.value < s2->symbol.value)
4481
1.76k
    return -1;
4482
205k
  else if (s1->symbol.value > s2->symbol.value)
4483
36.8k
    return 1;
4484
4485
168k
  return 0;
4486
206k
}
Unexecuted instantiation: coff-tic4x.c:coff_sort_func_alent
coff-tic54x.c:coff_sort_func_alent
Line
Count
Source
4472
514k
{
4473
514k
  const alent *al1 = *(const alent **) arg1;
4474
514k
  const alent *al2 = *(const alent **) arg2;
4475
514k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
514k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
514k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
514k
  if (s1->symbol.value < s2->symbol.value)
4481
4.91k
    return -1;
4482
509k
  else if (s1->symbol.value > s2->symbol.value)
4483
105k
    return 1;
4484
4485
403k
  return 0;
4486
514k
}
coff-z80.c:coff_sort_func_alent
Line
Count
Source
4472
453k
{
4473
453k
  const alent *al1 = *(const alent **) arg1;
4474
453k
  const alent *al2 = *(const alent **) arg2;
4475
453k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
453k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
453k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
453k
  if (s1->symbol.value < s2->symbol.value)
4481
3.50k
    return -1;
4482
449k
  else if (s1->symbol.value > s2->symbol.value)
4483
60.8k
    return 1;
4484
4485
389k
  return 0;
4486
453k
}
coff-z8k.c:coff_sort_func_alent
Line
Count
Source
4472
316k
{
4473
316k
  const alent *al1 = *(const alent **) arg1;
4474
316k
  const alent *al2 = *(const alent **) arg2;
4475
316k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
316k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
316k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
316k
  if (s1->symbol.value < s2->symbol.value)
4481
3.98k
    return -1;
4482
312k
  else if (s1->symbol.value > s2->symbol.value)
4483
87.5k
    return 1;
4484
4485
224k
  return 0;
4486
316k
}
Unexecuted instantiation: pe-arm-wince.c:coff_sort_func_alent
Unexecuted instantiation: pe-arm.c:coff_sort_func_alent
pe-i386.c:coff_sort_func_alent
Line
Count
Source
4472
239k
{
4473
239k
  const alent *al1 = *(const alent **) arg1;
4474
239k
  const alent *al2 = *(const alent **) arg2;
4475
239k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
239k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
239k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
239k
  if (s1->symbol.value < s2->symbol.value)
4481
4.57k
    return -1;
4482
234k
  else if (s1->symbol.value > s2->symbol.value)
4483
56.9k
    return 1;
4484
4485
177k
  return 0;
4486
239k
}
pe-mcore.c:coff_sort_func_alent
Line
Count
Source
4472
500k
{
4473
500k
  const alent *al1 = *(const alent **) arg1;
4474
500k
  const alent *al2 = *(const alent **) arg2;
4475
500k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
500k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
500k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
500k
  if (s1->symbol.value < s2->symbol.value)
4481
1.96k
    return -1;
4482
498k
  else if (s1->symbol.value > s2->symbol.value)
4483
131k
    return 1;
4484
4485
367k
  return 0;
4486
500k
}
pe-sh.c:coff_sort_func_alent
Line
Count
Source
4472
970k
{
4473
970k
  const alent *al1 = *(const alent **) arg1;
4474
970k
  const alent *al2 = *(const alent **) arg2;
4475
970k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
970k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
970k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
970k
  if (s1->symbol.value < s2->symbol.value)
4481
9.69k
    return -1;
4482
960k
  else if (s1->symbol.value > s2->symbol.value)
4483
224k
    return 1;
4484
4485
736k
  return 0;
4486
970k
}
pei-arm-wince.c:coff_sort_func_alent
Line
Count
Source
4472
474k
{
4473
474k
  const alent *al1 = *(const alent **) arg1;
4474
474k
  const alent *al2 = *(const alent **) arg2;
4475
474k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
474k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
474k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
474k
  if (s1->symbol.value < s2->symbol.value)
4481
6.14k
    return -1;
4482
468k
  else if (s1->symbol.value > s2->symbol.value)
4483
106k
    return 1;
4484
4485
361k
  return 0;
4486
474k
}
pei-arm.c:coff_sort_func_alent
Line
Count
Source
4472
456k
{
4473
456k
  const alent *al1 = *(const alent **) arg1;
4474
456k
  const alent *al2 = *(const alent **) arg2;
4475
456k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
456k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
456k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
456k
  if (s1->symbol.value < s2->symbol.value)
4481
9.73k
    return -1;
4482
446k
  else if (s1->symbol.value > s2->symbol.value)
4483
111k
    return 1;
4484
4485
335k
  return 0;
4486
456k
}
pei-mcore.c:coff_sort_func_alent
Line
Count
Source
4472
392k
{
4473
392k
  const alent *al1 = *(const alent **) arg1;
4474
392k
  const alent *al2 = *(const alent **) arg2;
4475
392k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
392k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
392k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
392k
  if (s1->symbol.value < s2->symbol.value)
4481
3.02k
    return -1;
4482
389k
  else if (s1->symbol.value > s2->symbol.value)
4483
48.8k
    return 1;
4484
4485
340k
  return 0;
4486
392k
}
pei-sh.c:coff_sort_func_alent
Line
Count
Source
4472
165k
{
4473
165k
  const alent *al1 = *(const alent **) arg1;
4474
165k
  const alent *al2 = *(const alent **) arg2;
4475
165k
  const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
4476
165k
  const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
4477
4478
165k
  if (s1 == NULL || s2 == NULL)
4479
0
    return 0;
4480
165k
  if (s1->symbol.value < s2->symbol.value)
4481
2.83k
    return -1;
4482
163k
  else if (s1->symbol.value > s2->symbol.value)
4483
35.0k
    return 1;
4484
4485
128k
  return 0;
4486
165k
}
4487
4488
static bool
4489
coff_slurp_line_table (bfd *abfd, asection *asect)
4490
108k
{
4491
108k
  LINENO *native_lineno;
4492
108k
  alent *lineno_cache;
4493
108k
  unsigned int counter;
4494
108k
  alent *cache_ptr;
4495
108k
  bfd_vma prev_offset = 0;
4496
108k
  bool ordered = true;
4497
108k
  unsigned int nbr_func;
4498
108k
  LINENO *src;
4499
108k
  bool have_func;
4500
108k
  bool ret = true;
4501
108k
  size_t amt;
4502
4503
108k
  if (asect->lineno_count == 0)
4504
96.4k
    return true;
4505
4506
11.6k
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
11.6k
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
11.6k
             asect->lineno_count,
4510
11.6k
             bfd_coff_linesz (abfd));
4511
11.6k
  if (native_lineno == NULL)
4512
4.90k
    {
4513
4.90k
      _bfd_error_handler
4514
4.90k
  (_("%pB: warning: line number table read failed"), abfd);
4515
4.90k
      return false;
4516
4.90k
    }
4517
4518
6.74k
  if (_bfd_mul_overflow (asect->lineno_count + 1, sizeof (alent), &amt))
4519
0
    {
4520
0
      bfd_set_error (bfd_error_file_too_big);
4521
0
      free (native_lineno);
4522
0
      return false;
4523
0
    }
4524
6.74k
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
6.74k
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
6.74k
  cache_ptr = lineno_cache;
4532
6.74k
  asect->lineno = lineno_cache;
4533
6.74k
  src = native_lineno;
4534
6.74k
  nbr_func = 0;
4535
6.74k
  have_func = false;
4536
4537
8.05M
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
8.05M
    {
4539
8.05M
      struct internal_lineno dst;
4540
4541
8.05M
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
8.05M
      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
8.05M
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
8.05M
      if (cache_ptr->line_number == 0)
4549
3.17M
  {
4550
3.17M
    combined_entry_type * ent;
4551
3.17M
    unsigned long symndx;
4552
3.17M
    coff_symbol_type *sym;
4553
4554
3.17M
    have_func = false;
4555
3.17M
    symndx = dst.l_addr.l_symndx;
4556
3.17M
    if (symndx >= obj_raw_syment_count (abfd))
4557
1.36M
      {
4558
1.36M
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
1.36M
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
1.36M
     abfd, symndx, counter);
4562
1.36M
        cache_ptr->line_number = -1;
4563
1.36M
        ret = false;
4564
1.36M
        continue;
4565
1.36M
      }
4566
4567
1.81M
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
1.81M
    if (! ent->is_sym)
4571
223k
      {
4572
223k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
223k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
223k
     abfd, symndx, counter);
4576
223k
        cache_ptr->line_number = -1;
4577
223k
        ret = false;
4578
223k
        continue;
4579
223k
      }
4580
1.59M
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
1.59M
    if (sym < obj_symbols (abfd)
4584
1.59M
        || 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.59M
    have_func = true;
4596
1.59M
    nbr_func++;
4597
1.59M
    cache_ptr->u.sym = (asymbol *) sym;
4598
1.59M
    if (sym->lineno != NULL)
4599
1.56M
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
1.56M
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
1.56M
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
1.59M
    sym->lineno = cache_ptr;
4605
1.59M
    if (sym->symbol.value < prev_offset)
4606
36.1k
      ordered = false;
4607
1.59M
    prev_offset = sym->symbol.value;
4608
1.59M
  }
4609
4.87M
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
3.23M
  continue;
4613
1.63M
      else
4614
1.63M
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
3.22M
      cache_ptr++;
4616
3.22M
    }
4617
4618
6.74k
  asect->lineno_count = cache_ptr - lineno_cache;
4619
6.74k
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
6.74k
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
6.74k
  if (!ordered)
4624
3.18k
    {
4625
      /* Sort the table.  */
4626
3.18k
      alent **func_table;
4627
3.18k
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
3.18k
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
3.18k
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
3.18k
  {
4637
3.18k
    alent **p = func_table;
4638
3.18k
    unsigned int i;
4639
4640
2.96M
    for (i = 0; i < asect->lineno_count; i++)
4641
2.96M
      if (lineno_cache[i].line_number == 0)
4642
1.42M
        *p++ = &lineno_cache[i];
4643
4644
3.18k
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
3.18k
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
3.18k
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
3.18k
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
3.18k
      {
4657
3.18k
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
1.43M
        for (i = 0; i < nbr_func; i++)
4660
1.42M
    {
4661
1.42M
      coff_symbol_type *sym;
4662
1.42M
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
1.42M
      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.42M
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
1.42M
      do
4671
2.96M
        *n_cache_ptr++ = *old_ptr++;
4672
2.96M
      while (old_ptr->line_number != 0);
4673
1.42M
    }
4674
4675
3.18k
        memcpy (lineno_cache, n_lineno_cache,
4676
3.18k
          asect->lineno_count * sizeof (alent));
4677
3.18k
      }
4678
0
    else
4679
0
      ret = false;
4680
3.18k
    bfd_release (abfd, func_table);
4681
3.18k
  }
4682
0
      else
4683
0
  ret = false;
4684
3.18k
    }
4685
4686
6.74k
  return ret;
4687
6.74k
}
pei-i386.c:coff_slurp_line_table
Line
Count
Source
4490
8.88k
{
4491
8.88k
  LINENO *native_lineno;
4492
8.88k
  alent *lineno_cache;
4493
8.88k
  unsigned int counter;
4494
8.88k
  alent *cache_ptr;
4495
8.88k
  bfd_vma prev_offset = 0;
4496
8.88k
  bool ordered = true;
4497
8.88k
  unsigned int nbr_func;
4498
8.88k
  LINENO *src;
4499
8.88k
  bool have_func;
4500
8.88k
  bool ret = true;
4501
8.88k
  size_t amt;
4502
4503
8.88k
  if (asect->lineno_count == 0)
4504
8.56k
    return true;
4505
4506
323
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
323
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
323
             asect->lineno_count,
4510
323
             bfd_coff_linesz (abfd));
4511
323
  if (native_lineno == NULL)
4512
151
    {
4513
151
      _bfd_error_handler
4514
151
  (_("%pB: warning: line number table read failed"), abfd);
4515
151
      return false;
4516
151
    }
4517
4518
172
  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
172
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
172
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
172
  cache_ptr = lineno_cache;
4532
172
  asect->lineno = lineno_cache;
4533
172
  src = native_lineno;
4534
172
  nbr_func = 0;
4535
172
  have_func = false;
4536
4537
238k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
237k
    {
4539
237k
      struct internal_lineno dst;
4540
4541
237k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
237k
      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
237k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
237k
      if (cache_ptr->line_number == 0)
4549
116k
  {
4550
116k
    combined_entry_type * ent;
4551
116k
    unsigned long symndx;
4552
116k
    coff_symbol_type *sym;
4553
4554
116k
    have_func = false;
4555
116k
    symndx = dst.l_addr.l_symndx;
4556
116k
    if (symndx >= obj_raw_syment_count (abfd))
4557
43.6k
      {
4558
43.6k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
43.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
43.6k
     abfd, symndx, counter);
4562
43.6k
        cache_ptr->line_number = -1;
4563
43.6k
        ret = false;
4564
43.6k
        continue;
4565
43.6k
      }
4566
4567
72.7k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
72.7k
    if (! ent->is_sym)
4571
6.92k
      {
4572
6.92k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
6.92k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
6.92k
     abfd, symndx, counter);
4576
6.92k
        cache_ptr->line_number = -1;
4577
6.92k
        ret = false;
4578
6.92k
        continue;
4579
6.92k
      }
4580
65.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
65.8k
    if (sym < obj_symbols (abfd)
4584
65.8k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
65.8k
    have_func = true;
4596
65.8k
    nbr_func++;
4597
65.8k
    cache_ptr->u.sym = (asymbol *) sym;
4598
65.8k
    if (sym->lineno != NULL)
4599
64.5k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
64.5k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
64.5k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
65.8k
    sym->lineno = cache_ptr;
4605
65.8k
    if (sym->symbol.value < prev_offset)
4606
2.02k
      ordered = false;
4607
65.8k
    prev_offset = sym->symbol.value;
4608
65.8k
  }
4609
121k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
71.2k
  continue;
4613
50.3k
      else
4614
50.3k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
116k
      cache_ptr++;
4616
116k
    }
4617
4618
172
  asect->lineno_count = cache_ptr - lineno_cache;
4619
172
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
172
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
172
  if (!ordered)
4624
102
    {
4625
      /* Sort the table.  */
4626
102
      alent **func_table;
4627
102
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
102
      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
102
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
102
  {
4637
102
    alent **p = func_table;
4638
102
    unsigned int i;
4639
4640
114k
    for (i = 0; i < asect->lineno_count; i++)
4641
114k
      if (lineno_cache[i].line_number == 0)
4642
64.6k
        *p++ = &lineno_cache[i];
4643
4644
102
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
102
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
102
    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
102
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
102
      {
4657
102
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
64.7k
        for (i = 0; i < nbr_func; i++)
4660
64.6k
    {
4661
64.6k
      coff_symbol_type *sym;
4662
64.6k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
64.6k
      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
64.6k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
64.6k
      do
4671
114k
        *n_cache_ptr++ = *old_ptr++;
4672
114k
      while (old_ptr->line_number != 0);
4673
64.6k
    }
4674
4675
102
        memcpy (lineno_cache, n_lineno_cache,
4676
102
          asect->lineno_count * sizeof (alent));
4677
102
      }
4678
0
    else
4679
0
      ret = false;
4680
102
    bfd_release (abfd, func_table);
4681
102
  }
4682
0
      else
4683
0
  ret = false;
4684
102
    }
4685
4686
172
  return ret;
4687
172
}
pe-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
10.5k
{
4491
10.5k
  LINENO *native_lineno;
4492
10.5k
  alent *lineno_cache;
4493
10.5k
  unsigned int counter;
4494
10.5k
  alent *cache_ptr;
4495
10.5k
  bfd_vma prev_offset = 0;
4496
10.5k
  bool ordered = true;
4497
10.5k
  unsigned int nbr_func;
4498
10.5k
  LINENO *src;
4499
10.5k
  bool have_func;
4500
10.5k
  bool ret = true;
4501
10.5k
  size_t amt;
4502
4503
10.5k
  if (asect->lineno_count == 0)
4504
9.95k
    return true;
4505
4506
575
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
575
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
575
             asect->lineno_count,
4510
575
             bfd_coff_linesz (abfd));
4511
575
  if (native_lineno == NULL)
4512
239
    {
4513
239
      _bfd_error_handler
4514
239
  (_("%pB: warning: line number table read failed"), abfd);
4515
239
      return false;
4516
239
    }
4517
4518
336
  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
336
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
336
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
336
  cache_ptr = lineno_cache;
4532
336
  asect->lineno = lineno_cache;
4533
336
  src = native_lineno;
4534
336
  nbr_func = 0;
4535
336
  have_func = false;
4536
4537
208k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
208k
    {
4539
208k
      struct internal_lineno dst;
4540
4541
208k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
208k
      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
208k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
208k
      if (cache_ptr->line_number == 0)
4549
90.3k
  {
4550
90.3k
    combined_entry_type * ent;
4551
90.3k
    unsigned long symndx;
4552
90.3k
    coff_symbol_type *sym;
4553
4554
90.3k
    have_func = false;
4555
90.3k
    symndx = dst.l_addr.l_symndx;
4556
90.3k
    if (symndx >= obj_raw_syment_count (abfd))
4557
38.6k
      {
4558
38.6k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
38.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
38.6k
     abfd, symndx, counter);
4562
38.6k
        cache_ptr->line_number = -1;
4563
38.6k
        ret = false;
4564
38.6k
        continue;
4565
38.6k
      }
4566
4567
51.6k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
51.6k
    if (! ent->is_sym)
4571
7.36k
      {
4572
7.36k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
7.36k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
7.36k
     abfd, symndx, counter);
4576
7.36k
        cache_ptr->line_number = -1;
4577
7.36k
        ret = false;
4578
7.36k
        continue;
4579
7.36k
      }
4580
44.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
44.3k
    if (sym < obj_symbols (abfd)
4584
44.3k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
44.3k
    have_func = true;
4596
44.3k
    nbr_func++;
4597
44.3k
    cache_ptr->u.sym = (asymbol *) sym;
4598
44.3k
    if (sym->lineno != NULL)
4599
43.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
43.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
43.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
44.3k
    sym->lineno = cache_ptr;
4605
44.3k
    if (sym->symbol.value < prev_offset)
4606
1.20k
      ordered = false;
4607
44.3k
    prev_offset = sym->symbol.value;
4608
44.3k
  }
4609
118k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
73.1k
  continue;
4613
44.9k
      else
4614
44.9k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
89.3k
      cache_ptr++;
4616
89.3k
    }
4617
4618
336
  asect->lineno_count = cache_ptr - lineno_cache;
4619
336
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
336
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
336
  if (!ordered)
4624
136
    {
4625
      /* Sort the table.  */
4626
136
      alent **func_table;
4627
136
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
136
      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
136
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
136
  {
4637
136
    alent **p = func_table;
4638
136
    unsigned int i;
4639
4640
85.8k
    for (i = 0; i < asect->lineno_count; i++)
4641
85.6k
      if (lineno_cache[i].line_number == 0)
4642
42.0k
        *p++ = &lineno_cache[i];
4643
4644
136
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
136
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
136
    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
136
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
136
      {
4657
136
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
42.2k
        for (i = 0; i < nbr_func; i++)
4660
42.0k
    {
4661
42.0k
      coff_symbol_type *sym;
4662
42.0k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
42.0k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
42.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
42.0k
      do
4671
85.6k
        *n_cache_ptr++ = *old_ptr++;
4672
85.6k
      while (old_ptr->line_number != 0);
4673
42.0k
    }
4674
4675
136
        memcpy (lineno_cache, n_lineno_cache,
4676
136
          asect->lineno_count * sizeof (alent));
4677
136
      }
4678
0
    else
4679
0
      ret = false;
4680
136
    bfd_release (abfd, func_table);
4681
136
  }
4682
0
      else
4683
0
  ret = false;
4684
136
    }
4685
4686
336
  return ret;
4687
336
}
pei-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
1.45k
{
4491
1.45k
  LINENO *native_lineno;
4492
1.45k
  alent *lineno_cache;
4493
1.45k
  unsigned int counter;
4494
1.45k
  alent *cache_ptr;
4495
1.45k
  bfd_vma prev_offset = 0;
4496
1.45k
  bool ordered = true;
4497
1.45k
  unsigned int nbr_func;
4498
1.45k
  LINENO *src;
4499
1.45k
  bool have_func;
4500
1.45k
  bool ret = true;
4501
1.45k
  size_t amt;
4502
4503
1.45k
  if (asect->lineno_count == 0)
4504
1.05k
    return true;
4505
4506
402
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
402
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
402
             asect->lineno_count,
4510
402
             bfd_coff_linesz (abfd));
4511
402
  if (native_lineno == NULL)
4512
154
    {
4513
154
      _bfd_error_handler
4514
154
  (_("%pB: warning: line number table read failed"), abfd);
4515
154
      return false;
4516
154
    }
4517
4518
248
  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
248
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
248
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
248
  cache_ptr = lineno_cache;
4532
248
  asect->lineno = lineno_cache;
4533
248
  src = native_lineno;
4534
248
  nbr_func = 0;
4535
248
  have_func = false;
4536
4537
316k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
316k
    {
4539
316k
      struct internal_lineno dst;
4540
4541
316k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
316k
      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
316k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
316k
      if (cache_ptr->line_number == 0)
4549
147k
  {
4550
147k
    combined_entry_type * ent;
4551
147k
    unsigned long symndx;
4552
147k
    coff_symbol_type *sym;
4553
4554
147k
    have_func = false;
4555
147k
    symndx = dst.l_addr.l_symndx;
4556
147k
    if (symndx >= obj_raw_syment_count (abfd))
4557
68.1k
      {
4558
68.1k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
68.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
68.1k
     abfd, symndx, counter);
4562
68.1k
        cache_ptr->line_number = -1;
4563
68.1k
        ret = false;
4564
68.1k
        continue;
4565
68.1k
      }
4566
4567
79.0k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
79.0k
    if (! ent->is_sym)
4571
8.62k
      {
4572
8.62k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
8.62k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
8.62k
     abfd, symndx, counter);
4576
8.62k
        cache_ptr->line_number = -1;
4577
8.62k
        ret = false;
4578
8.62k
        continue;
4579
8.62k
      }
4580
70.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
70.4k
    if (sym < obj_symbols (abfd)
4584
70.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
70.4k
    have_func = true;
4596
70.4k
    nbr_func++;
4597
70.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
70.4k
    if (sym->lineno != NULL)
4599
69.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
69.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
69.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
70.4k
    sym->lineno = cache_ptr;
4605
70.4k
    if (sym->symbol.value < prev_offset)
4606
1.61k
      ordered = false;
4607
70.4k
    prev_offset = sym->symbol.value;
4608
70.4k
  }
4609
168k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
113k
  continue;
4613
55.7k
      else
4614
55.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
126k
      cache_ptr++;
4616
126k
    }
4617
4618
248
  asect->lineno_count = cache_ptr - lineno_cache;
4619
248
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
248
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
248
  if (!ordered)
4624
125
    {
4625
      /* Sort the table.  */
4626
125
      alent **func_table;
4627
125
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
125
      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
125
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
125
  {
4637
125
    alent **p = func_table;
4638
125
    unsigned int i;
4639
4640
118k
    for (i = 0; i < asect->lineno_count; i++)
4641
118k
      if (lineno_cache[i].line_number == 0)
4642
64.2k
        *p++ = &lineno_cache[i];
4643
4644
125
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
125
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
125
    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
125
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
125
      {
4657
125
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
64.3k
        for (i = 0; i < nbr_func; i++)
4660
64.2k
    {
4661
64.2k
      coff_symbol_type *sym;
4662
64.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
64.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
64.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
64.2k
      do
4671
118k
        *n_cache_ptr++ = *old_ptr++;
4672
118k
      while (old_ptr->line_number != 0);
4673
64.2k
    }
4674
4675
125
        memcpy (lineno_cache, n_lineno_cache,
4676
125
          asect->lineno_count * sizeof (alent));
4677
125
      }
4678
0
    else
4679
0
      ret = false;
4680
125
    bfd_release (abfd, func_table);
4681
125
  }
4682
0
      else
4683
0
  ret = false;
4684
125
    }
4685
4686
248
  return ret;
4687
248
}
coff-x86_64.c:coff_slurp_line_table
Line
Count
Source
4490
30.7k
{
4491
30.7k
  LINENO *native_lineno;
4492
30.7k
  alent *lineno_cache;
4493
30.7k
  unsigned int counter;
4494
30.7k
  alent *cache_ptr;
4495
30.7k
  bfd_vma prev_offset = 0;
4496
30.7k
  bool ordered = true;
4497
30.7k
  unsigned int nbr_func;
4498
30.7k
  LINENO *src;
4499
30.7k
  bool have_func;
4500
30.7k
  bool ret = true;
4501
30.7k
  size_t amt;
4502
4503
30.7k
  if (asect->lineno_count == 0)
4504
29.7k
    return true;
4505
4506
968
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
968
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
968
             asect->lineno_count,
4510
968
             bfd_coff_linesz (abfd));
4511
968
  if (native_lineno == NULL)
4512
536
    {
4513
536
      _bfd_error_handler
4514
536
  (_("%pB: warning: line number table read failed"), abfd);
4515
536
      return false;
4516
536
    }
4517
4518
432
  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
432
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
432
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
432
  cache_ptr = lineno_cache;
4532
432
  asect->lineno = lineno_cache;
4533
432
  src = native_lineno;
4534
432
  nbr_func = 0;
4535
432
  have_func = false;
4536
4537
532k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
532k
    {
4539
532k
      struct internal_lineno dst;
4540
4541
532k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
532k
      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
532k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
532k
      if (cache_ptr->line_number == 0)
4549
187k
  {
4550
187k
    combined_entry_type * ent;
4551
187k
    unsigned long symndx;
4552
187k
    coff_symbol_type *sym;
4553
4554
187k
    have_func = false;
4555
187k
    symndx = dst.l_addr.l_symndx;
4556
187k
    if (symndx >= obj_raw_syment_count (abfd))
4557
81.4k
      {
4558
81.4k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
81.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
81.4k
     abfd, symndx, counter);
4562
81.4k
        cache_ptr->line_number = -1;
4563
81.4k
        ret = false;
4564
81.4k
        continue;
4565
81.4k
      }
4566
4567
106k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
106k
    if (! ent->is_sym)
4571
19.6k
      {
4572
19.6k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
19.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
19.6k
     abfd, symndx, counter);
4576
19.6k
        cache_ptr->line_number = -1;
4577
19.6k
        ret = false;
4578
19.6k
        continue;
4579
19.6k
      }
4580
86.6k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
86.6k
    if (sym < obj_symbols (abfd)
4584
86.6k
        || 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
86.6k
    have_func = true;
4596
86.6k
    nbr_func++;
4597
86.6k
    cache_ptr->u.sym = (asymbol *) sym;
4598
86.6k
    if (sym->lineno != NULL)
4599
85.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
85.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
85.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
86.6k
    sym->lineno = cache_ptr;
4605
86.6k
    if (sym->symbol.value < prev_offset)
4606
2.22k
      ordered = false;
4607
86.6k
    prev_offset = sym->symbol.value;
4608
86.6k
  }
4609
344k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
219k
  continue;
4613
125k
      else
4614
125k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
211k
      cache_ptr++;
4616
211k
    }
4617
4618
432
  asect->lineno_count = cache_ptr - lineno_cache;
4619
432
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
432
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
432
  if (!ordered)
4624
193
    {
4625
      /* Sort the table.  */
4626
193
      alent **func_table;
4627
193
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
193
      if (_bfd_mul_overflow (nbr_func, sizeof (alent *), &amt))
4631
0
  {
4632
0
    bfd_set_error (bfd_error_file_too_big);
4633
0
    ret = false;
4634
0
  }
4635
193
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
193
  {
4637
193
    alent **p = func_table;
4638
193
    unsigned int i;
4639
4640
199k
    for (i = 0; i < asect->lineno_count; i++)
4641
199k
      if (lineno_cache[i].line_number == 0)
4642
77.6k
        *p++ = &lineno_cache[i];
4643
4644
193
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
193
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
193
    if (_bfd_mul_overflow (asect->lineno_count, sizeof (alent), &amt))
4651
0
      {
4652
0
        bfd_set_error (bfd_error_file_too_big);
4653
0
        ret = false;
4654
0
      }
4655
193
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
193
      {
4657
193
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
77.8k
        for (i = 0; i < nbr_func; i++)
4660
77.6k
    {
4661
77.6k
      coff_symbol_type *sym;
4662
77.6k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
77.6k
      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
77.6k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
77.6k
      do
4671
199k
        *n_cache_ptr++ = *old_ptr++;
4672
199k
      while (old_ptr->line_number != 0);
4673
77.6k
    }
4674
4675
193
        memcpy (lineno_cache, n_lineno_cache,
4676
193
          asect->lineno_count * sizeof (alent));
4677
193
      }
4678
0
    else
4679
0
      ret = false;
4680
193
    bfd_release (abfd, func_table);
4681
193
  }
4682
0
      else
4683
0
  ret = false;
4684
193
    }
4685
4686
432
  return ret;
4687
432
}
coff64-rs6000.c:coff_slurp_line_table
Line
Count
Source
4490
4.62k
{
4491
4.62k
  LINENO *native_lineno;
4492
4.62k
  alent *lineno_cache;
4493
4.62k
  unsigned int counter;
4494
4.62k
  alent *cache_ptr;
4495
4.62k
  bfd_vma prev_offset = 0;
4496
4.62k
  bool ordered = true;
4497
4.62k
  unsigned int nbr_func;
4498
4.62k
  LINENO *src;
4499
4.62k
  bool have_func;
4500
4.62k
  bool ret = true;
4501
4.62k
  size_t amt;
4502
4503
4.62k
  if (asect->lineno_count == 0)
4504
3.75k
    return true;
4505
4506
865
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
865
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
865
             asect->lineno_count,
4510
865
             bfd_coff_linesz (abfd));
4511
865
  if (native_lineno == NULL)
4512
475
    {
4513
475
      _bfd_error_handler
4514
475
  (_("%pB: warning: line number table read failed"), abfd);
4515
475
      return false;
4516
475
    }
4517
4518
390
  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
390
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
390
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
390
  cache_ptr = lineno_cache;
4532
390
  asect->lineno = lineno_cache;
4533
390
  src = native_lineno;
4534
390
  nbr_func = 0;
4535
390
  have_func = false;
4536
4537
551k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
550k
    {
4539
550k
      struct internal_lineno dst;
4540
4541
550k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
550k
      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
550k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
550k
      if (cache_ptr->line_number == 0)
4549
154k
  {
4550
154k
    combined_entry_type * ent;
4551
154k
    unsigned long symndx;
4552
154k
    coff_symbol_type *sym;
4553
4554
154k
    have_func = false;
4555
154k
    symndx = dst.l_addr.l_symndx;
4556
154k
    if (symndx >= obj_raw_syment_count (abfd))
4557
51.6k
      {
4558
51.6k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
51.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
51.6k
     abfd, symndx, counter);
4562
51.6k
        cache_ptr->line_number = -1;
4563
51.6k
        ret = false;
4564
51.6k
        continue;
4565
51.6k
      }
4566
4567
102k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
102k
    if (! ent->is_sym)
4571
7.82k
      {
4572
7.82k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
7.82k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
7.82k
     abfd, symndx, counter);
4576
7.82k
        cache_ptr->line_number = -1;
4577
7.82k
        ret = false;
4578
7.82k
        continue;
4579
7.82k
      }
4580
94.7k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
94.7k
    if (sym < obj_symbols (abfd)
4584
94.7k
        || 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
94.7k
    have_func = true;
4596
94.7k
    nbr_func++;
4597
94.7k
    cache_ptr->u.sym = (asymbol *) sym;
4598
94.7k
    if (sym->lineno != NULL)
4599
93.6k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
93.6k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
93.6k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
94.7k
    sym->lineno = cache_ptr;
4605
94.7k
    if (sym->symbol.value < prev_offset)
4606
1.55k
      ordered = false;
4607
94.7k
    prev_offset = sym->symbol.value;
4608
94.7k
  }
4609
396k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
215k
  continue;
4613
181k
      else
4614
181k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
276k
      cache_ptr++;
4616
276k
    }
4617
4618
390
  asect->lineno_count = cache_ptr - lineno_cache;
4619
390
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
390
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
390
  if (!ordered)
4624
188
    {
4625
      /* Sort the table.  */
4626
188
      alent **func_table;
4627
188
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
188
      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
188
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
188
  {
4637
188
    alent **p = func_table;
4638
188
    unsigned int i;
4639
4640
243k
    for (i = 0; i < asect->lineno_count; i++)
4641
243k
      if (lineno_cache[i].line_number == 0)
4642
84.6k
        *p++ = &lineno_cache[i];
4643
4644
188
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
188
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
188
    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
188
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
188
      {
4657
188
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
84.8k
        for (i = 0; i < nbr_func; i++)
4660
84.6k
    {
4661
84.6k
      coff_symbol_type *sym;
4662
84.6k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
84.6k
      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
84.6k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
84.6k
      do
4671
243k
        *n_cache_ptr++ = *old_ptr++;
4672
243k
      while (old_ptr->line_number != 0);
4673
84.6k
    }
4674
4675
188
        memcpy (lineno_cache, n_lineno_cache,
4676
188
          asect->lineno_count * sizeof (alent));
4677
188
      }
4678
0
    else
4679
0
      ret = false;
4680
188
    bfd_release (abfd, func_table);
4681
188
  }
4682
0
      else
4683
0
  ret = false;
4684
188
    }
4685
4686
390
  return ret;
4687
390
}
pe-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
3.02k
{
4491
3.02k
  LINENO *native_lineno;
4492
3.02k
  alent *lineno_cache;
4493
3.02k
  unsigned int counter;
4494
3.02k
  alent *cache_ptr;
4495
3.02k
  bfd_vma prev_offset = 0;
4496
3.02k
  bool ordered = true;
4497
3.02k
  unsigned int nbr_func;
4498
3.02k
  LINENO *src;
4499
3.02k
  bool have_func;
4500
3.02k
  bool ret = true;
4501
3.02k
  size_t amt;
4502
4503
3.02k
  if (asect->lineno_count == 0)
4504
2.60k
    return true;
4505
4506
419
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
419
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
419
             asect->lineno_count,
4510
419
             bfd_coff_linesz (abfd));
4511
419
  if (native_lineno == NULL)
4512
190
    {
4513
190
      _bfd_error_handler
4514
190
  (_("%pB: warning: line number table read failed"), abfd);
4515
190
      return false;
4516
190
    }
4517
4518
229
  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
229
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
229
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
229
  cache_ptr = lineno_cache;
4532
229
  asect->lineno = lineno_cache;
4533
229
  src = native_lineno;
4534
229
  nbr_func = 0;
4535
229
  have_func = false;
4536
4537
123k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
122k
    {
4539
122k
      struct internal_lineno dst;
4540
4541
122k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
122k
      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
122k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
122k
      if (cache_ptr->line_number == 0)
4549
62.3k
  {
4550
62.3k
    combined_entry_type * ent;
4551
62.3k
    unsigned long symndx;
4552
62.3k
    coff_symbol_type *sym;
4553
4554
62.3k
    have_func = false;
4555
62.3k
    symndx = dst.l_addr.l_symndx;
4556
62.3k
    if (symndx >= obj_raw_syment_count (abfd))
4557
29.6k
      {
4558
29.6k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
29.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
29.6k
     abfd, symndx, counter);
4562
29.6k
        cache_ptr->line_number = -1;
4563
29.6k
        ret = false;
4564
29.6k
        continue;
4565
29.6k
      }
4566
4567
32.7k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
32.7k
    if (! ent->is_sym)
4571
1.42k
      {
4572
1.42k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.42k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.42k
     abfd, symndx, counter);
4576
1.42k
        cache_ptr->line_number = -1;
4577
1.42k
        ret = false;
4578
1.42k
        continue;
4579
1.42k
      }
4580
31.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
31.2k
    if (sym < obj_symbols (abfd)
4584
31.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
31.2k
    have_func = true;
4596
31.2k
    nbr_func++;
4597
31.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
31.2k
    if (sym->lineno != NULL)
4599
30.7k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
30.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
30.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
31.2k
    sym->lineno = cache_ptr;
4605
31.2k
    if (sym->symbol.value < prev_offset)
4606
840
      ordered = false;
4607
31.2k
    prev_offset = sym->symbol.value;
4608
31.2k
  }
4609
60.5k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
38.5k
  continue;
4613
21.9k
      else
4614
21.9k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
53.2k
      cache_ptr++;
4616
53.2k
    }
4617
4618
229
  asect->lineno_count = cache_ptr - lineno_cache;
4619
229
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
229
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
229
  if (!ordered)
4624
91
    {
4625
      /* Sort the table.  */
4626
91
      alent **func_table;
4627
91
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
91
      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
91
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
91
  {
4637
91
    alent **p = func_table;
4638
91
    unsigned int i;
4639
4640
51.7k
    for (i = 0; i < asect->lineno_count; i++)
4641
51.7k
      if (lineno_cache[i].line_number == 0)
4642
30.3k
        *p++ = &lineno_cache[i];
4643
4644
91
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
91
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
91
    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
91
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
91
      {
4657
91
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
30.4k
        for (i = 0; i < nbr_func; i++)
4660
30.3k
    {
4661
30.3k
      coff_symbol_type *sym;
4662
30.3k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
30.3k
      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
30.3k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
30.3k
      do
4671
51.7k
        *n_cache_ptr++ = *old_ptr++;
4672
51.7k
      while (old_ptr->line_number != 0);
4673
30.3k
    }
4674
4675
91
        memcpy (lineno_cache, n_lineno_cache,
4676
91
          asect->lineno_count * sizeof (alent));
4677
91
      }
4678
0
    else
4679
0
      ret = false;
4680
91
    bfd_release (abfd, func_table);
4681
91
  }
4682
0
      else
4683
0
  ret = false;
4684
91
    }
4685
4686
229
  return ret;
4687
229
}
pei-aarch64.c:coff_slurp_line_table
Line
Count
Source
4490
2.33k
{
4491
2.33k
  LINENO *native_lineno;
4492
2.33k
  alent *lineno_cache;
4493
2.33k
  unsigned int counter;
4494
2.33k
  alent *cache_ptr;
4495
2.33k
  bfd_vma prev_offset = 0;
4496
2.33k
  bool ordered = true;
4497
2.33k
  unsigned int nbr_func;
4498
2.33k
  LINENO *src;
4499
2.33k
  bool have_func;
4500
2.33k
  bool ret = true;
4501
2.33k
  size_t amt;
4502
4503
2.33k
  if (asect->lineno_count == 0)
4504
1.92k
    return true;
4505
4506
409
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
409
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
409
             asect->lineno_count,
4510
409
             bfd_coff_linesz (abfd));
4511
409
  if (native_lineno == NULL)
4512
210
    {
4513
210
      _bfd_error_handler
4514
210
  (_("%pB: warning: line number table read failed"), abfd);
4515
210
      return false;
4516
210
    }
4517
4518
199
  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
199
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
199
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
199
  cache_ptr = lineno_cache;
4532
199
  asect->lineno = lineno_cache;
4533
199
  src = native_lineno;
4534
199
  nbr_func = 0;
4535
199
  have_func = false;
4536
4537
505k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
504k
    {
4539
504k
      struct internal_lineno dst;
4540
4541
504k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
504k
      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
504k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
504k
      if (cache_ptr->line_number == 0)
4549
220k
  {
4550
220k
    combined_entry_type * ent;
4551
220k
    unsigned long symndx;
4552
220k
    coff_symbol_type *sym;
4553
4554
220k
    have_func = false;
4555
220k
    symndx = dst.l_addr.l_symndx;
4556
220k
    if (symndx >= obj_raw_syment_count (abfd))
4557
109k
      {
4558
109k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
109k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
109k
     abfd, symndx, counter);
4562
109k
        cache_ptr->line_number = -1;
4563
109k
        ret = false;
4564
109k
        continue;
4565
109k
      }
4566
4567
110k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
110k
    if (! ent->is_sym)
4571
26.2k
      {
4572
26.2k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
26.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
26.2k
     abfd, symndx, counter);
4576
26.2k
        cache_ptr->line_number = -1;
4577
26.2k
        ret = false;
4578
26.2k
        continue;
4579
26.2k
      }
4580
84.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
84.2k
    if (sym < obj_symbols (abfd)
4584
84.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
84.2k
    have_func = true;
4596
84.2k
    nbr_func++;
4597
84.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
84.2k
    if (sym->lineno != NULL)
4599
82.7k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
82.7k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
82.7k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
84.2k
    sym->lineno = cache_ptr;
4605
84.2k
    if (sym->symbol.value < prev_offset)
4606
1.65k
      ordered = false;
4607
84.2k
    prev_offset = sym->symbol.value;
4608
84.2k
  }
4609
284k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
188k
  continue;
4613
96.5k
      else
4614
96.5k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
180k
      cache_ptr++;
4616
180k
    }
4617
4618
199
  asect->lineno_count = cache_ptr - lineno_cache;
4619
199
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
199
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
199
  if (!ordered)
4624
132
    {
4625
      /* Sort the table.  */
4626
132
      alent **func_table;
4627
132
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
132
      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
132
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
132
  {
4637
132
    alent **p = func_table;
4638
132
    unsigned int i;
4639
4640
178k
    for (i = 0; i < asect->lineno_count; i++)
4641
178k
      if (lineno_cache[i].line_number == 0)
4642
82.7k
        *p++ = &lineno_cache[i];
4643
4644
132
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
132
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
132
    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
132
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
132
      {
4657
132
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
82.9k
        for (i = 0; i < nbr_func; i++)
4660
82.7k
    {
4661
82.7k
      coff_symbol_type *sym;
4662
82.7k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
82.7k
      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
82.7k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
82.7k
      do
4671
178k
        *n_cache_ptr++ = *old_ptr++;
4672
178k
      while (old_ptr->line_number != 0);
4673
82.7k
    }
4674
4675
132
        memcpy (lineno_cache, n_lineno_cache,
4676
132
          asect->lineno_count * sizeof (alent));
4677
132
      }
4678
0
    else
4679
0
      ret = false;
4680
132
    bfd_release (abfd, func_table);
4681
132
  }
4682
0
      else
4683
0
  ret = false;
4684
132
    }
4685
4686
199
  return ret;
4687
199
}
pei-ia64.c:coff_slurp_line_table
Line
Count
Source
4490
1.31k
{
4491
1.31k
  LINENO *native_lineno;
4492
1.31k
  alent *lineno_cache;
4493
1.31k
  unsigned int counter;
4494
1.31k
  alent *cache_ptr;
4495
1.31k
  bfd_vma prev_offset = 0;
4496
1.31k
  bool ordered = true;
4497
1.31k
  unsigned int nbr_func;
4498
1.31k
  LINENO *src;
4499
1.31k
  bool have_func;
4500
1.31k
  bool ret = true;
4501
1.31k
  size_t amt;
4502
4503
1.31k
  if (asect->lineno_count == 0)
4504
808
    return true;
4505
4506
506
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
506
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
506
             asect->lineno_count,
4510
506
             bfd_coff_linesz (abfd));
4511
506
  if (native_lineno == NULL)
4512
175
    {
4513
175
      _bfd_error_handler
4514
175
  (_("%pB: warning: line number table read failed"), abfd);
4515
175
      return false;
4516
175
    }
4517
4518
331
  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
331
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
331
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
331
  cache_ptr = lineno_cache;
4532
331
  asect->lineno = lineno_cache;
4533
331
  src = native_lineno;
4534
331
  nbr_func = 0;
4535
331
  have_func = false;
4536
4537
261k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
261k
    {
4539
261k
      struct internal_lineno dst;
4540
4541
261k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
261k
      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
261k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
261k
      if (cache_ptr->line_number == 0)
4549
117k
  {
4550
117k
    combined_entry_type * ent;
4551
117k
    unsigned long symndx;
4552
117k
    coff_symbol_type *sym;
4553
4554
117k
    have_func = false;
4555
117k
    symndx = dst.l_addr.l_symndx;
4556
117k
    if (symndx >= obj_raw_syment_count (abfd))
4557
54.4k
      {
4558
54.4k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
54.4k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
54.4k
     abfd, symndx, counter);
4562
54.4k
        cache_ptr->line_number = -1;
4563
54.4k
        ret = false;
4564
54.4k
        continue;
4565
54.4k
      }
4566
4567
63.4k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
63.4k
    if (! ent->is_sym)
4571
9.55k
      {
4572
9.55k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
9.55k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
9.55k
     abfd, symndx, counter);
4576
9.55k
        cache_ptr->line_number = -1;
4577
9.55k
        ret = false;
4578
9.55k
        continue;
4579
9.55k
      }
4580
53.8k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
53.8k
    if (sym < obj_symbols (abfd)
4584
53.8k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
53.8k
    have_func = true;
4596
53.8k
    nbr_func++;
4597
53.8k
    cache_ptr->u.sym = (asymbol *) sym;
4598
53.8k
    if (sym->lineno != NULL)
4599
52.9k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
52.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
52.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
53.8k
    sym->lineno = cache_ptr;
4605
53.8k
    if (sym->symbol.value < prev_offset)
4606
1.08k
      ordered = false;
4607
53.8k
    prev_offset = sym->symbol.value;
4608
53.8k
  }
4609
143k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
93.8k
  continue;
4613
49.4k
      else
4614
49.4k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
103k
      cache_ptr++;
4616
103k
    }
4617
4618
331
  asect->lineno_count = cache_ptr - lineno_cache;
4619
331
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
331
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
331
  if (!ordered)
4624
151
    {
4625
      /* Sort the table.  */
4626
151
      alent **func_table;
4627
151
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
151
      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
151
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
151
  {
4637
151
    alent **p = func_table;
4638
151
    unsigned int i;
4639
4640
84.6k
    for (i = 0; i < asect->lineno_count; i++)
4641
84.5k
      if (lineno_cache[i].line_number == 0)
4642
42.3k
        *p++ = &lineno_cache[i];
4643
4644
151
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
151
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
151
    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
151
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
151
      {
4657
151
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
42.4k
        for (i = 0; i < nbr_func; i++)
4660
42.3k
    {
4661
42.3k
      coff_symbol_type *sym;
4662
42.3k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
42.3k
      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
42.3k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
42.3k
      do
4671
84.5k
        *n_cache_ptr++ = *old_ptr++;
4672
84.5k
      while (old_ptr->line_number != 0);
4673
42.3k
    }
4674
4675
151
        memcpy (lineno_cache, n_lineno_cache,
4676
151
          asect->lineno_count * sizeof (alent));
4677
151
      }
4678
0
    else
4679
0
      ret = false;
4680
151
    bfd_release (abfd, func_table);
4681
151
  }
4682
0
      else
4683
0
  ret = false;
4684
151
    }
4685
4686
331
  return ret;
4687
331
}
pei-loongarch64.c:coff_slurp_line_table
Line
Count
Source
4490
911
{
4491
911
  LINENO *native_lineno;
4492
911
  alent *lineno_cache;
4493
911
  unsigned int counter;
4494
911
  alent *cache_ptr;
4495
911
  bfd_vma prev_offset = 0;
4496
911
  bool ordered = true;
4497
911
  unsigned int nbr_func;
4498
911
  LINENO *src;
4499
911
  bool have_func;
4500
911
  bool ret = true;
4501
911
  size_t amt;
4502
4503
911
  if (asect->lineno_count == 0)
4504
565
    return true;
4505
4506
346
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
346
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
346
             asect->lineno_count,
4510
346
             bfd_coff_linesz (abfd));
4511
346
  if (native_lineno == NULL)
4512
153
    {
4513
153
      _bfd_error_handler
4514
153
  (_("%pB: warning: line number table read failed"), abfd);
4515
153
      return false;
4516
153
    }
4517
4518
193
  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
193
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
193
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
193
  cache_ptr = lineno_cache;
4532
193
  asect->lineno = lineno_cache;
4533
193
  src = native_lineno;
4534
193
  nbr_func = 0;
4535
193
  have_func = false;
4536
4537
444k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
443k
    {
4539
443k
      struct internal_lineno dst;
4540
4541
443k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
443k
      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
443k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
443k
      if (cache_ptr->line_number == 0)
4549
204k
  {
4550
204k
    combined_entry_type * ent;
4551
204k
    unsigned long symndx;
4552
204k
    coff_symbol_type *sym;
4553
4554
204k
    have_func = false;
4555
204k
    symndx = dst.l_addr.l_symndx;
4556
204k
    if (symndx >= obj_raw_syment_count (abfd))
4557
98.8k
      {
4558
98.8k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
98.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
98.8k
     abfd, symndx, counter);
4562
98.8k
        cache_ptr->line_number = -1;
4563
98.8k
        ret = false;
4564
98.8k
        continue;
4565
98.8k
      }
4566
4567
105k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
105k
    if (! ent->is_sym)
4571
31.1k
      {
4572
31.1k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
31.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
31.1k
     abfd, symndx, counter);
4576
31.1k
        cache_ptr->line_number = -1;
4577
31.1k
        ret = false;
4578
31.1k
        continue;
4579
31.1k
      }
4580
74.1k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
74.1k
    if (sym < obj_symbols (abfd)
4584
74.1k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
74.1k
    have_func = true;
4596
74.1k
    nbr_func++;
4597
74.1k
    cache_ptr->u.sym = (asymbol *) sym;
4598
74.1k
    if (sym->lineno != NULL)
4599
73.0k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
73.0k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
73.0k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
74.1k
    sym->lineno = cache_ptr;
4605
74.1k
    if (sym->symbol.value < prev_offset)
4606
2.58k
      ordered = false;
4607
74.1k
    prev_offset = sym->symbol.value;
4608
74.1k
  }
4609
239k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
165k
  continue;
4613
74.7k
      else
4614
74.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
148k
      cache_ptr++;
4616
148k
    }
4617
4618
193
  asect->lineno_count = cache_ptr - lineno_cache;
4619
193
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
193
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
193
  if (!ordered)
4624
136
    {
4625
      /* Sort the table.  */
4626
136
      alent **func_table;
4627
136
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
136
      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
136
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
136
  {
4637
136
    alent **p = func_table;
4638
136
    unsigned int i;
4639
4640
146k
    for (i = 0; i < asect->lineno_count; i++)
4641
146k
      if (lineno_cache[i].line_number == 0)
4642
73.1k
        *p++ = &lineno_cache[i];
4643
4644
136
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
136
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
136
    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
136
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
136
      {
4657
136
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
73.2k
        for (i = 0; i < nbr_func; i++)
4660
73.1k
    {
4661
73.1k
      coff_symbol_type *sym;
4662
73.1k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
73.1k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
73.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
73.1k
      do
4671
146k
        *n_cache_ptr++ = *old_ptr++;
4672
146k
      while (old_ptr->line_number != 0);
4673
73.1k
    }
4674
4675
136
        memcpy (lineno_cache, n_lineno_cache,
4676
136
          asect->lineno_count * sizeof (alent));
4677
136
      }
4678
0
    else
4679
0
      ret = false;
4680
136
    bfd_release (abfd, func_table);
4681
136
  }
4682
0
      else
4683
0
  ret = false;
4684
136
    }
4685
4686
193
  return ret;
4687
193
}
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
10.0k
{
4491
10.0k
  LINENO *native_lineno;
4492
10.0k
  alent *lineno_cache;
4493
10.0k
  unsigned int counter;
4494
10.0k
  alent *cache_ptr;
4495
10.0k
  bfd_vma prev_offset = 0;
4496
10.0k
  bool ordered = true;
4497
10.0k
  unsigned int nbr_func;
4498
10.0k
  LINENO *src;
4499
10.0k
  bool have_func;
4500
10.0k
  bool ret = true;
4501
10.0k
  size_t amt;
4502
4503
10.0k
  if (asect->lineno_count == 0)
4504
9.26k
    return true;
4505
4506
734
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
734
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
734
             asect->lineno_count,
4510
734
             bfd_coff_linesz (abfd));
4511
734
  if (native_lineno == NULL)
4512
340
    {
4513
340
      _bfd_error_handler
4514
340
  (_("%pB: warning: line number table read failed"), abfd);
4515
340
      return false;
4516
340
    }
4517
4518
394
  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
394
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
394
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
394
  cache_ptr = lineno_cache;
4532
394
  asect->lineno = lineno_cache;
4533
394
  src = native_lineno;
4534
394
  nbr_func = 0;
4535
394
  have_func = false;
4536
4537
283k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
282k
    {
4539
282k
      struct internal_lineno dst;
4540
4541
282k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
282k
      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
282k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
282k
      if (cache_ptr->line_number == 0)
4549
163k
  {
4550
163k
    combined_entry_type * ent;
4551
163k
    unsigned long symndx;
4552
163k
    coff_symbol_type *sym;
4553
4554
163k
    have_func = false;
4555
163k
    symndx = dst.l_addr.l_symndx;
4556
163k
    if (symndx >= obj_raw_syment_count (abfd))
4557
34.1k
      {
4558
34.1k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
34.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
34.1k
     abfd, symndx, counter);
4562
34.1k
        cache_ptr->line_number = -1;
4563
34.1k
        ret = false;
4564
34.1k
        continue;
4565
34.1k
      }
4566
4567
128k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
128k
    if (! ent->is_sym)
4571
6.60k
      {
4572
6.60k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
6.60k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
6.60k
     abfd, symndx, counter);
4576
6.60k
        cache_ptr->line_number = -1;
4577
6.60k
        ret = false;
4578
6.60k
        continue;
4579
6.60k
      }
4580
122k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
122k
    if (sym < obj_symbols (abfd)
4584
122k
        || 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
122k
    have_func = true;
4596
122k
    nbr_func++;
4597
122k
    cache_ptr->u.sym = (asymbol *) sym;
4598
122k
    if (sym->lineno != NULL)
4599
121k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
121k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
121k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
122k
    sym->lineno = cache_ptr;
4605
122k
    if (sym->symbol.value < prev_offset)
4606
1.61k
      ordered = false;
4607
122k
    prev_offset = sym->symbol.value;
4608
122k
  }
4609
119k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
73.9k
  continue;
4613
45.5k
      else
4614
45.5k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
167k
      cache_ptr++;
4616
167k
    }
4617
4618
394
  asect->lineno_count = cache_ptr - lineno_cache;
4619
394
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
394
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
394
  if (!ordered)
4624
221
    {
4625
      /* Sort the table.  */
4626
221
      alent **func_table;
4627
221
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
221
      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
221
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
221
  {
4637
221
    alent **p = func_table;
4638
221
    unsigned int i;
4639
4640
151k
    for (i = 0; i < asect->lineno_count; i++)
4641
151k
      if (lineno_cache[i].line_number == 0)
4642
113k
        *p++ = &lineno_cache[i];
4643
4644
221
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
221
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
221
    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
221
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
221
      {
4657
221
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
113k
        for (i = 0; i < nbr_func; i++)
4660
113k
    {
4661
113k
      coff_symbol_type *sym;
4662
113k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
113k
      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
113k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
113k
      do
4671
151k
        *n_cache_ptr++ = *old_ptr++;
4672
151k
      while (old_ptr->line_number != 0);
4673
113k
    }
4674
4675
221
        memcpy (lineno_cache, n_lineno_cache,
4676
221
          asect->lineno_count * sizeof (alent));
4677
221
      }
4678
0
    else
4679
0
      ret = false;
4680
221
    bfd_release (abfd, func_table);
4681
221
  }
4682
0
      else
4683
0
  ret = false;
4684
221
    }
4685
4686
394
  return ret;
4687
394
}
coff-sh.c:coff_slurp_line_table
Line
Count
Source
4490
4.29k
{
4491
4.29k
  LINENO *native_lineno;
4492
4.29k
  alent *lineno_cache;
4493
4.29k
  unsigned int counter;
4494
4.29k
  alent *cache_ptr;
4495
4.29k
  bfd_vma prev_offset = 0;
4496
4.29k
  bool ordered = true;
4497
4.29k
  unsigned int nbr_func;
4498
4.29k
  LINENO *src;
4499
4.29k
  bool have_func;
4500
4.29k
  bool ret = true;
4501
4.29k
  size_t amt;
4502
4503
4.29k
  if (asect->lineno_count == 0)
4504
3.67k
    return true;
4505
4506
614
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
614
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
614
             asect->lineno_count,
4510
614
             bfd_coff_linesz (abfd));
4511
614
  if (native_lineno == NULL)
4512
322
    {
4513
322
      _bfd_error_handler
4514
322
  (_("%pB: warning: line number table read failed"), abfd);
4515
322
      return false;
4516
322
    }
4517
4518
292
  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
292
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
292
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
292
  cache_ptr = lineno_cache;
4532
292
  asect->lineno = lineno_cache;
4533
292
  src = native_lineno;
4534
292
  nbr_func = 0;
4535
292
  have_func = false;
4536
4537
302k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
301k
    {
4539
301k
      struct internal_lineno dst;
4540
4541
301k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
301k
      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
301k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
301k
      if (cache_ptr->line_number == 0)
4549
100k
  {
4550
100k
    combined_entry_type * ent;
4551
100k
    unsigned long symndx;
4552
100k
    coff_symbol_type *sym;
4553
4554
100k
    have_func = false;
4555
100k
    symndx = dst.l_addr.l_symndx;
4556
100k
    if (symndx >= obj_raw_syment_count (abfd))
4557
26.2k
      {
4558
26.2k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
26.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
26.2k
     abfd, symndx, counter);
4562
26.2k
        cache_ptr->line_number = -1;
4563
26.2k
        ret = false;
4564
26.2k
        continue;
4565
26.2k
      }
4566
4567
74.4k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
74.4k
    if (! ent->is_sym)
4571
8.35k
      {
4572
8.35k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
8.35k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
8.35k
     abfd, symndx, counter);
4576
8.35k
        cache_ptr->line_number = -1;
4577
8.35k
        ret = false;
4578
8.35k
        continue;
4579
8.35k
      }
4580
66.0k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
66.0k
    if (sym < obj_symbols (abfd)
4584
66.0k
        || 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
66.0k
    have_func = true;
4596
66.0k
    nbr_func++;
4597
66.0k
    cache_ptr->u.sym = (asymbol *) sym;
4598
66.0k
    if (sym->lineno != NULL)
4599
65.0k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
65.0k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
65.0k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
66.0k
    sym->lineno = cache_ptr;
4605
66.0k
    if (sym->symbol.value < prev_offset)
4606
943
      ordered = false;
4607
66.0k
    prev_offset = sym->symbol.value;
4608
66.0k
  }
4609
201k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
139k
  continue;
4613
61.6k
      else
4614
61.6k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
127k
      cache_ptr++;
4616
127k
    }
4617
4618
292
  asect->lineno_count = cache_ptr - lineno_cache;
4619
292
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
292
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
292
  if (!ordered)
4624
109
    {
4625
      /* Sort the table.  */
4626
109
      alent **func_table;
4627
109
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
109
      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
109
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
109
  {
4637
109
    alent **p = func_table;
4638
109
    unsigned int i;
4639
4640
83.8k
    for (i = 0; i < asect->lineno_count; i++)
4641
83.7k
      if (lineno_cache[i].line_number == 0)
4642
31.1k
        *p++ = &lineno_cache[i];
4643
4644
109
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
109
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
109
    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
109
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
109
      {
4657
109
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
31.2k
        for (i = 0; i < nbr_func; i++)
4660
31.1k
    {
4661
31.1k
      coff_symbol_type *sym;
4662
31.1k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
31.1k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
31.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
31.1k
      do
4671
83.7k
        *n_cache_ptr++ = *old_ptr++;
4672
83.7k
      while (old_ptr->line_number != 0);
4673
31.1k
    }
4674
4675
109
        memcpy (lineno_cache, n_lineno_cache,
4676
109
          asect->lineno_count * sizeof (alent));
4677
109
      }
4678
0
    else
4679
0
      ret = false;
4680
109
    bfd_release (abfd, func_table);
4681
109
  }
4682
0
      else
4683
0
  ret = false;
4684
109
    }
4685
4686
292
  return ret;
4687
292
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_line_table
coff-tic30.c:coff_slurp_line_table
Line
Count
Source
4490
4.49k
{
4491
4.49k
  LINENO *native_lineno;
4492
4.49k
  alent *lineno_cache;
4493
4.49k
  unsigned int counter;
4494
4.49k
  alent *cache_ptr;
4495
4.49k
  bfd_vma prev_offset = 0;
4496
4.49k
  bool ordered = true;
4497
4.49k
  unsigned int nbr_func;
4498
4.49k
  LINENO *src;
4499
4.49k
  bool have_func;
4500
4.49k
  bool ret = true;
4501
4.49k
  size_t amt;
4502
4503
4.49k
  if (asect->lineno_count == 0)
4504
3.50k
    return true;
4505
4506
999
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
999
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
999
             asect->lineno_count,
4510
999
             bfd_coff_linesz (abfd));
4511
999
  if (native_lineno == NULL)
4512
367
    {
4513
367
      _bfd_error_handler
4514
367
  (_("%pB: warning: line number table read failed"), abfd);
4515
367
      return false;
4516
367
    }
4517
4518
632
  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
632
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
632
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
632
  cache_ptr = lineno_cache;
4532
632
  asect->lineno = lineno_cache;
4533
632
  src = native_lineno;
4534
632
  nbr_func = 0;
4535
632
  have_func = false;
4536
4537
622k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
622k
    {
4539
622k
      struct internal_lineno dst;
4540
4541
622k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
622k
      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
622k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
622k
      if (cache_ptr->line_number == 0)
4549
187k
  {
4550
187k
    combined_entry_type * ent;
4551
187k
    unsigned long symndx;
4552
187k
    coff_symbol_type *sym;
4553
4554
187k
    have_func = false;
4555
187k
    symndx = dst.l_addr.l_symndx;
4556
187k
    if (symndx >= obj_raw_syment_count (abfd))
4557
114k
      {
4558
114k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
114k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
114k
     abfd, symndx, counter);
4562
114k
        cache_ptr->line_number = -1;
4563
114k
        ret = false;
4564
114k
        continue;
4565
114k
      }
4566
4567
72.1k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
72.1k
    if (! ent->is_sym)
4571
5.82k
      {
4572
5.82k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
5.82k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
5.82k
     abfd, symndx, counter);
4576
5.82k
        cache_ptr->line_number = -1;
4577
5.82k
        ret = false;
4578
5.82k
        continue;
4579
5.82k
      }
4580
66.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
66.2k
    if (sym < obj_symbols (abfd)
4584
66.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
66.2k
    have_func = true;
4596
66.2k
    nbr_func++;
4597
66.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
66.2k
    if (sym->lineno != NULL)
4599
65.3k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
65.3k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
65.3k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
66.2k
    sym->lineno = cache_ptr;
4605
66.2k
    if (sym->symbol.value < prev_offset)
4606
828
      ordered = false;
4607
66.2k
    prev_offset = sym->symbol.value;
4608
66.2k
  }
4609
435k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
377k
  continue;
4613
57.4k
      else
4614
57.4k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
123k
      cache_ptr++;
4616
123k
    }
4617
4618
632
  asect->lineno_count = cache_ptr - lineno_cache;
4619
632
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
632
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
632
  if (!ordered)
4624
174
    {
4625
      /* Sort the table.  */
4626
174
      alent **func_table;
4627
174
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
174
      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
174
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
174
  {
4637
174
    alent **p = func_table;
4638
174
    unsigned int i;
4639
4640
87.1k
    for (i = 0; i < asect->lineno_count; i++)
4641
86.9k
      if (lineno_cache[i].line_number == 0)
4642
35.2k
        *p++ = &lineno_cache[i];
4643
4644
174
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
174
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
174
    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
174
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
174
      {
4657
174
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
35.3k
        for (i = 0; i < nbr_func; i++)
4660
35.2k
    {
4661
35.2k
      coff_symbol_type *sym;
4662
35.2k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
35.2k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
35.2k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
35.2k
      do
4671
86.9k
        *n_cache_ptr++ = *old_ptr++;
4672
86.9k
      while (old_ptr->line_number != 0);
4673
35.2k
    }
4674
4675
174
        memcpy (lineno_cache, n_lineno_cache,
4676
174
          asect->lineno_count * sizeof (alent));
4677
174
      }
4678
0
    else
4679
0
      ret = false;
4680
174
    bfd_release (abfd, func_table);
4681
174
  }
4682
0
      else
4683
0
  ret = false;
4684
174
    }
4685
4686
632
  return ret;
4687
632
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_line_table
coff-tic54x.c:coff_slurp_line_table
Line
Count
Source
4490
4.47k
{
4491
4.47k
  LINENO *native_lineno;
4492
4.47k
  alent *lineno_cache;
4493
4.47k
  unsigned int counter;
4494
4.47k
  alent *cache_ptr;
4495
4.47k
  bfd_vma prev_offset = 0;
4496
4.47k
  bool ordered = true;
4497
4.47k
  unsigned int nbr_func;
4498
4.47k
  LINENO *src;
4499
4.47k
  bool have_func;
4500
4.47k
  bool ret = true;
4501
4.47k
  size_t amt;
4502
4503
4.47k
  if (asect->lineno_count == 0)
4504
3.69k
    return true;
4505
4506
786
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
786
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
786
             asect->lineno_count,
4510
786
             bfd_coff_linesz (abfd));
4511
786
  if (native_lineno == NULL)
4512
455
    {
4513
455
      _bfd_error_handler
4514
455
  (_("%pB: warning: line number table read failed"), abfd);
4515
455
      return false;
4516
455
    }
4517
4518
331
  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
331
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
331
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
331
  cache_ptr = lineno_cache;
4532
331
  asect->lineno = lineno_cache;
4533
331
  src = native_lineno;
4534
331
  nbr_func = 0;
4535
331
  have_func = false;
4536
4537
343k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
343k
    {
4539
343k
      struct internal_lineno dst;
4540
4541
343k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
343k
      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
343k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
343k
      if (cache_ptr->line_number == 0)
4549
156k
  {
4550
156k
    combined_entry_type * ent;
4551
156k
    unsigned long symndx;
4552
156k
    coff_symbol_type *sym;
4553
4554
156k
    have_func = false;
4555
156k
    symndx = dst.l_addr.l_symndx;
4556
156k
    if (symndx >= obj_raw_syment_count (abfd))
4557
66.2k
      {
4558
66.2k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
66.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
66.2k
     abfd, symndx, counter);
4562
66.2k
        cache_ptr->line_number = -1;
4563
66.2k
        ret = false;
4564
66.2k
        continue;
4565
66.2k
      }
4566
4567
90.7k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
90.7k
    if (! ent->is_sym)
4571
12.0k
      {
4572
12.0k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
12.0k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
12.0k
     abfd, symndx, counter);
4576
12.0k
        cache_ptr->line_number = -1;
4577
12.0k
        ret = false;
4578
12.0k
        continue;
4579
12.0k
      }
4580
78.7k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
78.7k
    if (sym < obj_symbols (abfd)
4584
78.7k
        || 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
78.7k
    have_func = true;
4596
78.7k
    nbr_func++;
4597
78.7k
    cache_ptr->u.sym = (asymbol *) sym;
4598
78.7k
    if (sym->lineno != NULL)
4599
77.6k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
77.6k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
77.6k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
78.7k
    sym->lineno = cache_ptr;
4605
78.7k
    if (sym->symbol.value < prev_offset)
4606
2.03k
      ordered = false;
4607
78.7k
    prev_offset = sym->symbol.value;
4608
78.7k
  }
4609
186k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
120k
  continue;
4613
65.3k
      else
4614
65.3k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
144k
      cache_ptr++;
4616
144k
    }
4617
4618
331
  asect->lineno_count = cache_ptr - lineno_cache;
4619
331
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
331
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
331
  if (!ordered)
4624
172
    {
4625
      /* Sort the table.  */
4626
172
      alent **func_table;
4627
172
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
172
      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
172
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
172
  {
4637
172
    alent **p = func_table;
4638
172
    unsigned int i;
4639
4640
139k
    for (i = 0; i < asect->lineno_count; i++)
4641
139k
      if (lineno_cache[i].line_number == 0)
4642
75.8k
        *p++ = &lineno_cache[i];
4643
4644
172
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
172
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
172
    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
172
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
172
      {
4657
172
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
76.0k
        for (i = 0; i < nbr_func; i++)
4660
75.8k
    {
4661
75.8k
      coff_symbol_type *sym;
4662
75.8k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
75.8k
      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
75.8k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
75.8k
      do
4671
139k
        *n_cache_ptr++ = *old_ptr++;
4672
139k
      while (old_ptr->line_number != 0);
4673
75.8k
    }
4674
4675
172
        memcpy (lineno_cache, n_lineno_cache,
4676
172
          asect->lineno_count * sizeof (alent));
4677
172
      }
4678
0
    else
4679
0
      ret = false;
4680
172
    bfd_release (abfd, func_table);
4681
172
  }
4682
0
      else
4683
0
  ret = false;
4684
172
    }
4685
4686
331
  return ret;
4687
331
}
coff-z80.c:coff_slurp_line_table
Line
Count
Source
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.72k
    return true;
4505
4506
614
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
614
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
614
             asect->lineno_count,
4510
614
             bfd_coff_linesz (abfd));
4511
614
  if (native_lineno == NULL)
4512
249
    {
4513
249
      _bfd_error_handler
4514
249
  (_("%pB: warning: line number table read failed"), abfd);
4515
249
      return false;
4516
249
    }
4517
4518
365
  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
365
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
365
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
365
  cache_ptr = lineno_cache;
4532
365
  asect->lineno = lineno_cache;
4533
365
  src = native_lineno;
4534
365
  nbr_func = 0;
4535
365
  have_func = false;
4536
4537
371k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
371k
    {
4539
371k
      struct internal_lineno dst;
4540
4541
371k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
371k
      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
371k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
371k
      if (cache_ptr->line_number == 0)
4549
122k
  {
4550
122k
    combined_entry_type * ent;
4551
122k
    unsigned long symndx;
4552
122k
    coff_symbol_type *sym;
4553
4554
122k
    have_func = false;
4555
122k
    symndx = dst.l_addr.l_symndx;
4556
122k
    if (symndx >= obj_raw_syment_count (abfd))
4557
36.9k
      {
4558
36.9k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
36.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
36.9k
     abfd, symndx, counter);
4562
36.9k
        cache_ptr->line_number = -1;
4563
36.9k
        ret = false;
4564
36.9k
        continue;
4565
36.9k
      }
4566
4567
85.5k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
85.5k
    if (! ent->is_sym)
4571
7.09k
      {
4572
7.09k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
7.09k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
7.09k
     abfd, symndx, counter);
4576
7.09k
        cache_ptr->line_number = -1;
4577
7.09k
        ret = false;
4578
7.09k
        continue;
4579
7.09k
      }
4580
78.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
78.4k
    if (sym < obj_symbols (abfd)
4584
78.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
78.4k
    have_func = true;
4596
78.4k
    nbr_func++;
4597
78.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
78.4k
    if (sym->lineno != NULL)
4599
77.1k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
77.1k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
77.1k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
78.4k
    sym->lineno = cache_ptr;
4605
78.4k
    if (sym->symbol.value < prev_offset)
4606
1.42k
      ordered = false;
4607
78.4k
    prev_offset = sym->symbol.value;
4608
78.4k
  }
4609
249k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
146k
  continue;
4613
102k
      else
4614
102k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
181k
      cache_ptr++;
4616
181k
    }
4617
4618
365
  asect->lineno_count = cache_ptr - lineno_cache;
4619
365
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
365
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
365
  if (!ordered)
4624
156
    {
4625
      /* Sort the table.  */
4626
156
      alent **func_table;
4627
156
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
156
      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
156
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
156
  {
4637
156
    alent **p = func_table;
4638
156
    unsigned int i;
4639
4640
176k
    for (i = 0; i < asect->lineno_count; i++)
4641
175k
      if (lineno_cache[i].line_number == 0)
4642
76.7k
        *p++ = &lineno_cache[i];
4643
4644
156
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
156
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
156
    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
156
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
156
      {
4657
156
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
76.9k
        for (i = 0; i < nbr_func; i++)
4660
76.7k
    {
4661
76.7k
      coff_symbol_type *sym;
4662
76.7k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
76.7k
      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
76.7k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
76.7k
      do
4671
175k
        *n_cache_ptr++ = *old_ptr++;
4672
175k
      while (old_ptr->line_number != 0);
4673
76.7k
    }
4674
4675
156
        memcpy (lineno_cache, n_lineno_cache,
4676
156
          asect->lineno_count * sizeof (alent));
4677
156
      }
4678
0
    else
4679
0
      ret = false;
4680
156
    bfd_release (abfd, func_table);
4681
156
  }
4682
0
      else
4683
0
  ret = false;
4684
156
    }
4685
4686
365
  return ret;
4687
365
}
coff-z8k.c:coff_slurp_line_table
Line
Count
Source
4490
4.60k
{
4491
4.60k
  LINENO *native_lineno;
4492
4.60k
  alent *lineno_cache;
4493
4.60k
  unsigned int counter;
4494
4.60k
  alent *cache_ptr;
4495
4.60k
  bfd_vma prev_offset = 0;
4496
4.60k
  bool ordered = true;
4497
4.60k
  unsigned int nbr_func;
4498
4.60k
  LINENO *src;
4499
4.60k
  bool have_func;
4500
4.60k
  bool ret = true;
4501
4.60k
  size_t amt;
4502
4503
4.60k
  if (asect->lineno_count == 0)
4504
4.00k
    return true;
4505
4506
599
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
599
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
599
             asect->lineno_count,
4510
599
             bfd_coff_linesz (abfd));
4511
599
  if (native_lineno == NULL)
4512
228
    {
4513
228
      _bfd_error_handler
4514
228
  (_("%pB: warning: line number table read failed"), abfd);
4515
228
      return false;
4516
228
    }
4517
4518
371
  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
371
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
371
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
371
  cache_ptr = lineno_cache;
4532
371
  asect->lineno = lineno_cache;
4533
371
  src = native_lineno;
4534
371
  nbr_func = 0;
4535
371
  have_func = false;
4536
4537
561k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
560k
    {
4539
560k
      struct internal_lineno dst;
4540
4541
560k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
560k
      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
560k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
560k
      if (cache_ptr->line_number == 0)
4549
132k
  {
4550
132k
    combined_entry_type * ent;
4551
132k
    unsigned long symndx;
4552
132k
    coff_symbol_type *sym;
4553
4554
132k
    have_func = false;
4555
132k
    symndx = dst.l_addr.l_symndx;
4556
132k
    if (symndx >= obj_raw_syment_count (abfd))
4557
74.3k
      {
4558
74.3k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
74.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
74.3k
     abfd, symndx, counter);
4562
74.3k
        cache_ptr->line_number = -1;
4563
74.3k
        ret = false;
4564
74.3k
        continue;
4565
74.3k
      }
4566
4567
57.7k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
57.7k
    if (! ent->is_sym)
4571
7.29k
      {
4572
7.29k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
7.29k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
7.29k
     abfd, symndx, counter);
4576
7.29k
        cache_ptr->line_number = -1;
4577
7.29k
        ret = false;
4578
7.29k
        continue;
4579
7.29k
      }
4580
50.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
50.4k
    if (sym < obj_symbols (abfd)
4584
50.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
50.4k
    have_func = true;
4596
50.4k
    nbr_func++;
4597
50.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
50.4k
    if (sym->lineno != NULL)
4599
49.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
49.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
49.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
50.4k
    sym->lineno = cache_ptr;
4605
50.4k
    if (sym->symbol.value < prev_offset)
4606
1.69k
      ordered = false;
4607
50.4k
    prev_offset = sym->symbol.value;
4608
50.4k
  }
4609
428k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
298k
  continue;
4613
130k
      else
4614
130k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
180k
      cache_ptr++;
4616
180k
    }
4617
4618
371
  asect->lineno_count = cache_ptr - lineno_cache;
4619
371
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
371
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
371
  if (!ordered)
4624
140
    {
4625
      /* Sort the table.  */
4626
140
      alent **func_table;
4627
140
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
140
      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
140
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
140
  {
4637
140
    alent **p = func_table;
4638
140
    unsigned int i;
4639
4640
173k
    for (i = 0; i < asect->lineno_count; i++)
4641
172k
      if (lineno_cache[i].line_number == 0)
4642
46.1k
        *p++ = &lineno_cache[i];
4643
4644
140
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
140
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
140
    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
140
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
140
      {
4657
140
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
46.3k
        for (i = 0; i < nbr_func; i++)
4660
46.1k
    {
4661
46.1k
      coff_symbol_type *sym;
4662
46.1k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
46.1k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
46.1k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
46.1k
      do
4671
172k
        *n_cache_ptr++ = *old_ptr++;
4672
172k
      while (old_ptr->line_number != 0);
4673
46.1k
    }
4674
4675
140
        memcpy (lineno_cache, n_lineno_cache,
4676
140
          asect->lineno_count * sizeof (alent));
4677
140
      }
4678
0
    else
4679
0
      ret = false;
4680
140
    bfd_release (abfd, func_table);
4681
140
  }
4682
0
      else
4683
0
  ret = false;
4684
140
    }
4685
4686
371
  return ret;
4687
371
}
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
2.15k
{
4491
2.15k
  LINENO *native_lineno;
4492
2.15k
  alent *lineno_cache;
4493
2.15k
  unsigned int counter;
4494
2.15k
  alent *cache_ptr;
4495
2.15k
  bfd_vma prev_offset = 0;
4496
2.15k
  bool ordered = true;
4497
2.15k
  unsigned int nbr_func;
4498
2.15k
  LINENO *src;
4499
2.15k
  bool have_func;
4500
2.15k
  bool ret = true;
4501
2.15k
  size_t amt;
4502
4503
2.15k
  if (asect->lineno_count == 0)
4504
1.80k
    return true;
4505
4506
344
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
344
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
344
             asect->lineno_count,
4510
344
             bfd_coff_linesz (abfd));
4511
344
  if (native_lineno == NULL)
4512
78
    {
4513
78
      _bfd_error_handler
4514
78
  (_("%pB: warning: line number table read failed"), abfd);
4515
78
      return false;
4516
78
    }
4517
4518
266
  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
266
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
266
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
266
  cache_ptr = lineno_cache;
4532
266
  asect->lineno = lineno_cache;
4533
266
  src = native_lineno;
4534
266
  nbr_func = 0;
4535
266
  have_func = false;
4536
4537
192k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
192k
    {
4539
192k
      struct internal_lineno dst;
4540
4541
192k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
192k
      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
192k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
192k
      if (cache_ptr->line_number == 0)
4549
86.6k
  {
4550
86.6k
    combined_entry_type * ent;
4551
86.6k
    unsigned long symndx;
4552
86.6k
    coff_symbol_type *sym;
4553
4554
86.6k
    have_func = false;
4555
86.6k
    symndx = dst.l_addr.l_symndx;
4556
86.6k
    if (symndx >= obj_raw_syment_count (abfd))
4557
38.6k
      {
4558
38.6k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
38.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
38.6k
     abfd, symndx, counter);
4562
38.6k
        cache_ptr->line_number = -1;
4563
38.6k
        ret = false;
4564
38.6k
        continue;
4565
38.6k
      }
4566
4567
48.0k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
48.0k
    if (! ent->is_sym)
4571
5.57k
      {
4572
5.57k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
5.57k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
5.57k
     abfd, symndx, counter);
4576
5.57k
        cache_ptr->line_number = -1;
4577
5.57k
        ret = false;
4578
5.57k
        continue;
4579
5.57k
      }
4580
42.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
42.4k
    if (sym < obj_symbols (abfd)
4584
42.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
42.4k
    have_func = true;
4596
42.4k
    nbr_func++;
4597
42.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
42.4k
    if (sym->lineno != NULL)
4599
41.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
41.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
41.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
42.4k
    sym->lineno = cache_ptr;
4605
42.4k
    if (sym->symbol.value < prev_offset)
4606
1.63k
      ordered = false;
4607
42.4k
    prev_offset = sym->symbol.value;
4608
42.4k
  }
4609
105k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
64.3k
  continue;
4613
41.6k
      else
4614
41.6k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
84.0k
      cache_ptr++;
4616
84.0k
    }
4617
4618
266
  asect->lineno_count = cache_ptr - lineno_cache;
4619
266
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
266
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
266
  if (!ordered)
4624
141
    {
4625
      /* Sort the table.  */
4626
141
      alent **func_table;
4627
141
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
141
      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
141
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
141
  {
4637
141
    alent **p = func_table;
4638
141
    unsigned int i;
4639
4640
75.2k
    for (i = 0; i < asect->lineno_count; i++)
4641
75.0k
      if (lineno_cache[i].line_number == 0)
4642
40.9k
        *p++ = &lineno_cache[i];
4643
4644
141
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
141
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
141
    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
141
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
141
      {
4657
141
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
41.0k
        for (i = 0; i < nbr_func; i++)
4660
40.9k
    {
4661
40.9k
      coff_symbol_type *sym;
4662
40.9k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
40.9k
      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.9k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
40.9k
      do
4671
75.0k
        *n_cache_ptr++ = *old_ptr++;
4672
75.0k
      while (old_ptr->line_number != 0);
4673
40.9k
    }
4674
4675
141
        memcpy (lineno_cache, n_lineno_cache,
4676
141
          asect->lineno_count * sizeof (alent));
4677
141
      }
4678
0
    else
4679
0
      ret = false;
4680
141
    bfd_release (abfd, func_table);
4681
141
  }
4682
0
      else
4683
0
  ret = false;
4684
141
    }
4685
4686
266
  return ret;
4687
266
}
pe-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
1.92k
{
4491
1.92k
  LINENO *native_lineno;
4492
1.92k
  alent *lineno_cache;
4493
1.92k
  unsigned int counter;
4494
1.92k
  alent *cache_ptr;
4495
1.92k
  bfd_vma prev_offset = 0;
4496
1.92k
  bool ordered = true;
4497
1.92k
  unsigned int nbr_func;
4498
1.92k
  LINENO *src;
4499
1.92k
  bool have_func;
4500
1.92k
  bool ret = true;
4501
1.92k
  size_t amt;
4502
4503
1.92k
  if (asect->lineno_count == 0)
4504
1.45k
    return true;
4505
4506
467
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
467
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
467
             asect->lineno_count,
4510
467
             bfd_coff_linesz (abfd));
4511
467
  if (native_lineno == NULL)
4512
116
    {
4513
116
      _bfd_error_handler
4514
116
  (_("%pB: warning: line number table read failed"), abfd);
4515
116
      return false;
4516
116
    }
4517
4518
351
  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
351
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
351
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
351
  cache_ptr = lineno_cache;
4532
351
  asect->lineno = lineno_cache;
4533
351
  src = native_lineno;
4534
351
  nbr_func = 0;
4535
351
  have_func = false;
4536
4537
395k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
395k
    {
4539
395k
      struct internal_lineno dst;
4540
4541
395k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
395k
      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
395k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
395k
      if (cache_ptr->line_number == 0)
4549
167k
  {
4550
167k
    combined_entry_type * ent;
4551
167k
    unsigned long symndx;
4552
167k
    coff_symbol_type *sym;
4553
4554
167k
    have_func = false;
4555
167k
    symndx = dst.l_addr.l_symndx;
4556
167k
    if (symndx >= obj_raw_syment_count (abfd))
4557
75.3k
      {
4558
75.3k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
75.3k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
75.3k
     abfd, symndx, counter);
4562
75.3k
        cache_ptr->line_number = -1;
4563
75.3k
        ret = false;
4564
75.3k
        continue;
4565
75.3k
      }
4566
4567
92.4k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
92.4k
    if (! ent->is_sym)
4571
10.9k
      {
4572
10.9k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
10.9k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
10.9k
     abfd, symndx, counter);
4576
10.9k
        cache_ptr->line_number = -1;
4577
10.9k
        ret = false;
4578
10.9k
        continue;
4579
10.9k
      }
4580
81.4k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
81.4k
    if (sym < obj_symbols (abfd)
4584
81.4k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
81.4k
    have_func = true;
4596
81.4k
    nbr_func++;
4597
81.4k
    cache_ptr->u.sym = (asymbol *) sym;
4598
81.4k
    if (sym->lineno != NULL)
4599
80.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
80.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
80.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
81.4k
    sym->lineno = cache_ptr;
4605
81.4k
    if (sym->symbol.value < prev_offset)
4606
1.13k
      ordered = false;
4607
81.4k
    prev_offset = sym->symbol.value;
4608
81.4k
  }
4609
227k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
143k
  continue;
4613
84.4k
      else
4614
84.4k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
165k
      cache_ptr++;
4616
165k
    }
4617
4618
351
  asect->lineno_count = cache_ptr - lineno_cache;
4619
351
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
351
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
351
  if (!ordered)
4624
140
    {
4625
      /* Sort the table.  */
4626
140
      alent **func_table;
4627
140
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
140
      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
140
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
140
  {
4637
140
    alent **p = func_table;
4638
140
    unsigned int i;
4639
4640
146k
    for (i = 0; i < asect->lineno_count; i++)
4641
145k
      if (lineno_cache[i].line_number == 0)
4642
71.3k
        *p++ = &lineno_cache[i];
4643
4644
140
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
140
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
140
    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
140
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
140
      {
4657
140
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
71.4k
        for (i = 0; i < nbr_func; i++)
4660
71.3k
    {
4661
71.3k
      coff_symbol_type *sym;
4662
71.3k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
71.3k
      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
71.3k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
71.3k
      do
4671
145k
        *n_cache_ptr++ = *old_ptr++;
4672
145k
      while (old_ptr->line_number != 0);
4673
71.3k
    }
4674
4675
140
        memcpy (lineno_cache, n_lineno_cache,
4676
140
          asect->lineno_count * sizeof (alent));
4677
140
      }
4678
0
    else
4679
0
      ret = false;
4680
140
    bfd_release (abfd, func_table);
4681
140
  }
4682
0
      else
4683
0
  ret = false;
4684
140
    }
4685
4686
351
  return ret;
4687
351
}
pe-sh.c:coff_slurp_line_table
Line
Count
Source
4490
2.13k
{
4491
2.13k
  LINENO *native_lineno;
4492
2.13k
  alent *lineno_cache;
4493
2.13k
  unsigned int counter;
4494
2.13k
  alent *cache_ptr;
4495
2.13k
  bfd_vma prev_offset = 0;
4496
2.13k
  bool ordered = true;
4497
2.13k
  unsigned int nbr_func;
4498
2.13k
  LINENO *src;
4499
2.13k
  bool have_func;
4500
2.13k
  bool ret = true;
4501
2.13k
  size_t amt;
4502
4503
2.13k
  if (asect->lineno_count == 0)
4504
1.73k
    return true;
4505
4506
402
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
402
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
402
             asect->lineno_count,
4510
402
             bfd_coff_linesz (abfd));
4511
402
  if (native_lineno == NULL)
4512
95
    {
4513
95
      _bfd_error_handler
4514
95
  (_("%pB: warning: line number table read failed"), abfd);
4515
95
      return false;
4516
95
    }
4517
4518
307
  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
307
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
307
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
307
  cache_ptr = lineno_cache;
4532
307
  asect->lineno = lineno_cache;
4533
307
  src = native_lineno;
4534
307
  nbr_func = 0;
4535
307
  have_func = false;
4536
4537
564k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
563k
    {
4539
563k
      struct internal_lineno dst;
4540
4541
563k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
563k
      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
563k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
563k
      if (cache_ptr->line_number == 0)
4549
225k
  {
4550
225k
    combined_entry_type * ent;
4551
225k
    unsigned long symndx;
4552
225k
    coff_symbol_type *sym;
4553
4554
225k
    have_func = false;
4555
225k
    symndx = dst.l_addr.l_symndx;
4556
225k
    if (symndx >= obj_raw_syment_count (abfd))
4557
79.1k
      {
4558
79.1k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
79.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
79.1k
     abfd, symndx, counter);
4562
79.1k
        cache_ptr->line_number = -1;
4563
79.1k
        ret = false;
4564
79.1k
        continue;
4565
79.1k
      }
4566
4567
146k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
146k
    if (! ent->is_sym)
4571
12.6k
      {
4572
12.6k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
12.6k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
12.6k
     abfd, symndx, counter);
4576
12.6k
        cache_ptr->line_number = -1;
4577
12.6k
        ret = false;
4578
12.6k
        continue;
4579
12.6k
      }
4580
134k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
134k
    if (sym < obj_symbols (abfd)
4584
134k
        || 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
134k
    have_func = true;
4596
134k
    nbr_func++;
4597
134k
    cache_ptr->u.sym = (asymbol *) sym;
4598
134k
    if (sym->lineno != NULL)
4599
132k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
132k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
132k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
134k
    sym->lineno = cache_ptr;
4605
134k
    if (sym->symbol.value < prev_offset)
4606
3.09k
      ordered = false;
4607
134k
    prev_offset = sym->symbol.value;
4608
134k
  }
4609
337k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
245k
  continue;
4613
92.7k
      else
4614
92.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
226k
      cache_ptr++;
4616
226k
    }
4617
4618
307
  asect->lineno_count = cache_ptr - lineno_cache;
4619
307
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
307
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
307
  if (!ordered)
4624
151
    {
4625
      /* Sort the table.  */
4626
151
      alent **func_table;
4627
151
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
151
      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
151
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
151
  {
4637
151
    alent **p = func_table;
4638
151
    unsigned int i;
4639
4640
223k
    for (i = 0; i < asect->lineno_count; i++)
4641
223k
      if (lineno_cache[i].line_number == 0)
4642
132k
        *p++ = &lineno_cache[i];
4643
4644
151
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
151
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
151
    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
151
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
151
      {
4657
151
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
132k
        for (i = 0; i < nbr_func; i++)
4660
132k
    {
4661
132k
      coff_symbol_type *sym;
4662
132k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
132k
      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
132k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
132k
      do
4671
223k
        *n_cache_ptr++ = *old_ptr++;
4672
223k
      while (old_ptr->line_number != 0);
4673
132k
    }
4674
4675
151
        memcpy (lineno_cache, n_lineno_cache,
4676
151
          asect->lineno_count * sizeof (alent));
4677
151
      }
4678
0
    else
4679
0
      ret = false;
4680
151
    bfd_release (abfd, func_table);
4681
151
  }
4682
0
      else
4683
0
  ret = false;
4684
151
    }
4685
4686
307
  return ret;
4687
307
}
pei-arm-wince.c:coff_slurp_line_table
Line
Count
Source
4490
4.43k
{
4491
4.43k
  LINENO *native_lineno;
4492
4.43k
  alent *lineno_cache;
4493
4.43k
  unsigned int counter;
4494
4.43k
  alent *cache_ptr;
4495
4.43k
  bfd_vma prev_offset = 0;
4496
4.43k
  bool ordered = true;
4497
4.43k
  unsigned int nbr_func;
4498
4.43k
  LINENO *src;
4499
4.43k
  bool have_func;
4500
4.43k
  bool ret = true;
4501
4.43k
  size_t amt;
4502
4503
4.43k
  if (asect->lineno_count == 0)
4504
4.17k
    return true;
4505
4506
265
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
265
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
265
             asect->lineno_count,
4510
265
             bfd_coff_linesz (abfd));
4511
265
  if (native_lineno == NULL)
4512
63
    {
4513
63
      _bfd_error_handler
4514
63
  (_("%pB: warning: line number table read failed"), abfd);
4515
63
      return false;
4516
63
    }
4517
4518
202
  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
202
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
202
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
202
  cache_ptr = lineno_cache;
4532
202
  asect->lineno = lineno_cache;
4533
202
  src = native_lineno;
4534
202
  nbr_func = 0;
4535
202
  have_func = false;
4536
4537
454k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
454k
    {
4539
454k
      struct internal_lineno dst;
4540
4541
454k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
454k
      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
454k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
454k
      if (cache_ptr->line_number == 0)
4549
201k
  {
4550
201k
    combined_entry_type * ent;
4551
201k
    unsigned long symndx;
4552
201k
    coff_symbol_type *sym;
4553
4554
201k
    have_func = false;
4555
201k
    symndx = dst.l_addr.l_symndx;
4556
201k
    if (symndx >= obj_raw_syment_count (abfd))
4557
97.8k
      {
4558
97.8k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
97.8k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
97.8k
     abfd, symndx, counter);
4562
97.8k
        cache_ptr->line_number = -1;
4563
97.8k
        ret = false;
4564
97.8k
        continue;
4565
97.8k
      }
4566
4567
103k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
103k
    if (! ent->is_sym)
4571
14.1k
      {
4572
14.1k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
14.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
14.1k
     abfd, symndx, counter);
4576
14.1k
        cache_ptr->line_number = -1;
4577
14.1k
        ret = false;
4578
14.1k
        continue;
4579
14.1k
      }
4580
89.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
89.2k
    if (sym < obj_symbols (abfd)
4584
89.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
89.2k
    have_func = true;
4596
89.2k
    nbr_func++;
4597
89.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
89.2k
    if (sym->lineno != NULL)
4599
87.8k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
87.8k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
87.8k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
89.2k
    sym->lineno = cache_ptr;
4605
89.2k
    if (sym->symbol.value < prev_offset)
4606
2.27k
      ordered = false;
4607
89.2k
    prev_offset = sym->symbol.value;
4608
89.2k
  }
4609
252k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
175k
  continue;
4613
77.6k
      else
4614
77.6k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
166k
      cache_ptr++;
4616
166k
    }
4617
4618
202
  asect->lineno_count = cache_ptr - lineno_cache;
4619
202
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
202
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
202
  if (!ordered)
4624
134
    {
4625
      /* Sort the table.  */
4626
134
      alent **func_table;
4627
134
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
134
      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
134
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
134
  {
4637
134
    alent **p = func_table;
4638
134
    unsigned int i;
4639
4640
152k
    for (i = 0; i < asect->lineno_count; i++)
4641
152k
      if (lineno_cache[i].line_number == 0)
4642
77.5k
        *p++ = &lineno_cache[i];
4643
4644
134
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
134
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
134
    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
134
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
134
      {
4657
134
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
77.6k
        for (i = 0; i < nbr_func; i++)
4660
77.5k
    {
4661
77.5k
      coff_symbol_type *sym;
4662
77.5k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
77.5k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
77.5k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
77.5k
      do
4671
152k
        *n_cache_ptr++ = *old_ptr++;
4672
152k
      while (old_ptr->line_number != 0);
4673
77.5k
    }
4674
4675
134
        memcpy (lineno_cache, n_lineno_cache,
4676
134
          asect->lineno_count * sizeof (alent));
4677
134
      }
4678
0
    else
4679
0
      ret = false;
4680
134
    bfd_release (abfd, func_table);
4681
134
  }
4682
0
      else
4683
0
  ret = false;
4684
134
    }
4685
4686
202
  return ret;
4687
202
}
pei-arm.c:coff_slurp_line_table
Line
Count
Source
4490
1.06k
{
4491
1.06k
  LINENO *native_lineno;
4492
1.06k
  alent *lineno_cache;
4493
1.06k
  unsigned int counter;
4494
1.06k
  alent *cache_ptr;
4495
1.06k
  bfd_vma prev_offset = 0;
4496
1.06k
  bool ordered = true;
4497
1.06k
  unsigned int nbr_func;
4498
1.06k
  LINENO *src;
4499
1.06k
  bool have_func;
4500
1.06k
  bool ret = true;
4501
1.06k
  size_t amt;
4502
4503
1.06k
  if (asect->lineno_count == 0)
4504
699
    return true;
4505
4506
362
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
362
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
362
             asect->lineno_count,
4510
362
             bfd_coff_linesz (abfd));
4511
362
  if (native_lineno == NULL)
4512
120
    {
4513
120
      _bfd_error_handler
4514
120
  (_("%pB: warning: line number table read failed"), abfd);
4515
120
      return false;
4516
120
    }
4517
4518
242
  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
242
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
242
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
242
  cache_ptr = lineno_cache;
4532
242
  asect->lineno = lineno_cache;
4533
242
  src = native_lineno;
4534
242
  nbr_func = 0;
4535
242
  have_func = false;
4536
4537
390k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
390k
    {
4539
390k
      struct internal_lineno dst;
4540
4541
390k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
390k
      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
390k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
390k
      if (cache_ptr->line_number == 0)
4549
165k
  {
4550
165k
    combined_entry_type * ent;
4551
165k
    unsigned long symndx;
4552
165k
    coff_symbol_type *sym;
4553
4554
165k
    have_func = false;
4555
165k
    symndx = dst.l_addr.l_symndx;
4556
165k
    if (symndx >= obj_raw_syment_count (abfd))
4557
73.7k
      {
4558
73.7k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
73.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
73.7k
     abfd, symndx, counter);
4562
73.7k
        cache_ptr->line_number = -1;
4563
73.7k
        ret = false;
4564
73.7k
        continue;
4565
73.7k
      }
4566
4567
91.9k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
91.9k
    if (! ent->is_sym)
4571
11.7k
      {
4572
11.7k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
11.7k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
11.7k
     abfd, symndx, counter);
4576
11.7k
        cache_ptr->line_number = -1;
4577
11.7k
        ret = false;
4578
11.7k
        continue;
4579
11.7k
      }
4580
80.2k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
80.2k
    if (sym < obj_symbols (abfd)
4584
80.2k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
80.2k
    have_func = true;
4596
80.2k
    nbr_func++;
4597
80.2k
    cache_ptr->u.sym = (asymbol *) sym;
4598
80.2k
    if (sym->lineno != NULL)
4599
78.4k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
78.4k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
78.4k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
80.2k
    sym->lineno = cache_ptr;
4605
80.2k
    if (sym->symbol.value < prev_offset)
4606
2.74k
      ordered = false;
4607
80.2k
    prev_offset = sym->symbol.value;
4608
80.2k
  }
4609
224k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
147k
  continue;
4613
77.2k
      else
4614
77.2k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
157k
      cache_ptr++;
4616
157k
    }
4617
4618
242
  asect->lineno_count = cache_ptr - lineno_cache;
4619
242
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
242
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
242
  if (!ordered)
4624
153
    {
4625
      /* Sort the table.  */
4626
153
      alent **func_table;
4627
153
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
153
      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
153
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
153
  {
4637
153
    alent **p = func_table;
4638
153
    unsigned int i;
4639
4640
139k
    for (i = 0; i < asect->lineno_count; i++)
4641
139k
      if (lineno_cache[i].line_number == 0)
4642
72.9k
        *p++ = &lineno_cache[i];
4643
4644
153
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
153
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
153
    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
153
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
153
      {
4657
153
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
73.0k
        for (i = 0; i < nbr_func; i++)
4660
72.9k
    {
4661
72.9k
      coff_symbol_type *sym;
4662
72.9k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
72.9k
      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
72.9k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
72.9k
      do
4671
139k
        *n_cache_ptr++ = *old_ptr++;
4672
139k
      while (old_ptr->line_number != 0);
4673
72.9k
    }
4674
4675
153
        memcpy (lineno_cache, n_lineno_cache,
4676
153
          asect->lineno_count * sizeof (alent));
4677
153
      }
4678
0
    else
4679
0
      ret = false;
4680
153
    bfd_release (abfd, func_table);
4681
153
  }
4682
0
      else
4683
0
  ret = false;
4684
153
    }
4685
4686
242
  return ret;
4687
242
}
pei-mcore.c:coff_slurp_line_table
Line
Count
Source
4490
788
{
4491
788
  LINENO *native_lineno;
4492
788
  alent *lineno_cache;
4493
788
  unsigned int counter;
4494
788
  alent *cache_ptr;
4495
788
  bfd_vma prev_offset = 0;
4496
788
  bool ordered = true;
4497
788
  unsigned int nbr_func;
4498
788
  LINENO *src;
4499
788
  bool have_func;
4500
788
  bool ret = true;
4501
788
  size_t amt;
4502
4503
788
  if (asect->lineno_count == 0)
4504
476
    return true;
4505
4506
312
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
312
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
312
             asect->lineno_count,
4510
312
             bfd_coff_linesz (abfd));
4511
312
  if (native_lineno == NULL)
4512
78
    {
4513
78
      _bfd_error_handler
4514
78
  (_("%pB: warning: line number table read failed"), abfd);
4515
78
      return false;
4516
78
    }
4517
4518
234
  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
234
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
234
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
234
  cache_ptr = lineno_cache;
4532
234
  asect->lineno = lineno_cache;
4533
234
  src = native_lineno;
4534
234
  nbr_func = 0;
4535
234
  have_func = false;
4536
4537
240k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
240k
    {
4539
240k
      struct internal_lineno dst;
4540
4541
240k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
240k
      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
240k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
240k
      if (cache_ptr->line_number == 0)
4549
98.7k
  {
4550
98.7k
    combined_entry_type * ent;
4551
98.7k
    unsigned long symndx;
4552
98.7k
    coff_symbol_type *sym;
4553
4554
98.7k
    have_func = false;
4555
98.7k
    symndx = dst.l_addr.l_symndx;
4556
98.7k
    if (symndx >= obj_raw_syment_count (abfd))
4557
33.2k
      {
4558
33.2k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
33.2k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
33.2k
     abfd, symndx, counter);
4562
33.2k
        cache_ptr->line_number = -1;
4563
33.2k
        ret = false;
4564
33.2k
        continue;
4565
33.2k
      }
4566
4567
65.5k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
65.5k
    if (! ent->is_sym)
4571
1.15k
      {
4572
1.15k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.15k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.15k
     abfd, symndx, counter);
4576
1.15k
        cache_ptr->line_number = -1;
4577
1.15k
        ret = false;
4578
1.15k
        continue;
4579
1.15k
      }
4580
64.3k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
64.3k
    if (sym < obj_symbols (abfd)
4584
64.3k
        || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
4585
0
      {
4586
0
        _bfd_error_handler
4587
    /* xgettext:c-format */
4588
0
    (_("%pB: warning: illegal symbol in line number entry %d"),
4589
0
     abfd, counter);
4590
0
        cache_ptr->line_number = -1;
4591
0
        ret = false;
4592
0
        continue;
4593
0
      }
4594
4595
64.3k
    have_func = true;
4596
64.3k
    nbr_func++;
4597
64.3k
    cache_ptr->u.sym = (asymbol *) sym;
4598
64.3k
    if (sym->lineno != NULL)
4599
63.9k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
63.9k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
63.9k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
64.3k
    sym->lineno = cache_ptr;
4605
64.3k
    if (sym->symbol.value < prev_offset)
4606
917
      ordered = false;
4607
64.3k
    prev_offset = sym->symbol.value;
4608
64.3k
  }
4609
141k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
78.2k
  continue;
4613
63.7k
      else
4614
63.7k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
128k
      cache_ptr++;
4616
128k
    }
4617
4618
234
  asect->lineno_count = cache_ptr - lineno_cache;
4619
234
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
234
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
234
  if (!ordered)
4624
110
    {
4625
      /* Sort the table.  */
4626
110
      alent **func_table;
4627
110
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
110
      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
110
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
110
  {
4637
110
    alent **p = func_table;
4638
110
    unsigned int i;
4639
4640
126k
    for (i = 0; i < asect->lineno_count; i++)
4641
126k
      if (lineno_cache[i].line_number == 0)
4642
63.4k
        *p++ = &lineno_cache[i];
4643
4644
110
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
110
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
110
    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
110
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
110
      {
4657
110
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
63.5k
        for (i = 0; i < nbr_func; i++)
4660
63.4k
    {
4661
63.4k
      coff_symbol_type *sym;
4662
63.4k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
63.4k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
63.4k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
63.4k
      do
4671
126k
        *n_cache_ptr++ = *old_ptr++;
4672
126k
      while (old_ptr->line_number != 0);
4673
63.4k
    }
4674
4675
110
        memcpy (lineno_cache, n_lineno_cache,
4676
110
          asect->lineno_count * sizeof (alent));
4677
110
      }
4678
0
    else
4679
0
      ret = false;
4680
110
    bfd_release (abfd, func_table);
4681
110
  }
4682
0
      else
4683
0
  ret = false;
4684
110
    }
4685
4686
234
  return ret;
4687
234
}
pei-sh.c:coff_slurp_line_table
Line
Count
Source
4490
1.61k
{
4491
1.61k
  LINENO *native_lineno;
4492
1.61k
  alent *lineno_cache;
4493
1.61k
  unsigned int counter;
4494
1.61k
  alent *cache_ptr;
4495
1.61k
  bfd_vma prev_offset = 0;
4496
1.61k
  bool ordered = true;
4497
1.61k
  unsigned int nbr_func;
4498
1.61k
  LINENO *src;
4499
1.61k
  bool have_func;
4500
1.61k
  bool ret = true;
4501
1.61k
  size_t amt;
4502
4503
1.61k
  if (asect->lineno_count == 0)
4504
1.27k
    return true;
4505
4506
344
  BFD_ASSERT (asect->lineno == NULL);
4507
4508
344
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos,
4509
344
             asect->lineno_count,
4510
344
             bfd_coff_linesz (abfd));
4511
344
  if (native_lineno == NULL)
4512
112
    {
4513
112
      _bfd_error_handler
4514
112
  (_("%pB: warning: line number table read failed"), abfd);
4515
112
      return false;
4516
112
    }
4517
4518
232
  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
232
  lineno_cache = (alent *) bfd_alloc (abfd, amt);
4525
232
  if (lineno_cache == NULL)
4526
0
    {
4527
0
      free (native_lineno);
4528
0
      return false;
4529
0
    }
4530
4531
232
  cache_ptr = lineno_cache;
4532
232
  asect->lineno = lineno_cache;
4533
232
  src = native_lineno;
4534
232
  nbr_func = 0;
4535
232
  have_func = false;
4536
4537
155k
  for (counter = 0; counter < asect->lineno_count; counter++, src++)
4538
155k
    {
4539
155k
      struct internal_lineno dst;
4540
4541
155k
      bfd_coff_swap_lineno_in (abfd, src, &dst);
4542
155k
      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
155k
      memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
4547
4548
155k
      if (cache_ptr->line_number == 0)
4549
66.7k
  {
4550
66.7k
    combined_entry_type * ent;
4551
66.7k
    unsigned long symndx;
4552
66.7k
    coff_symbol_type *sym;
4553
4554
66.7k
    have_func = false;
4555
66.7k
    symndx = dst.l_addr.l_symndx;
4556
66.7k
    if (symndx >= obj_raw_syment_count (abfd))
4557
34.1k
      {
4558
34.1k
        _bfd_error_handler
4559
    /* xgettext:c-format */
4560
34.1k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4561
34.1k
     abfd, symndx, counter);
4562
34.1k
        cache_ptr->line_number = -1;
4563
34.1k
        ret = false;
4564
34.1k
        continue;
4565
34.1k
      }
4566
4567
32.6k
    ent = obj_raw_syments (abfd) + symndx;
4568
    /* FIXME: We should not be casting between ints and
4569
       pointers like this.  */
4570
32.6k
    if (! ent->is_sym)
4571
1.67k
      {
4572
1.67k
        _bfd_error_handler
4573
    /* xgettext:c-format */
4574
1.67k
    (_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
4575
1.67k
     abfd, symndx, counter);
4576
1.67k
        cache_ptr->line_number = -1;
4577
1.67k
        ret = false;
4578
1.67k
        continue;
4579
1.67k
      }
4580
30.9k
    sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
4581
4582
    /* PR 17512 file: 078-10659-0.004  */
4583
30.9k
    if (sym < obj_symbols (abfd)
4584
30.9k
        || 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
30.9k
    have_func = true;
4596
30.9k
    nbr_func++;
4597
30.9k
    cache_ptr->u.sym = (asymbol *) sym;
4598
30.9k
    if (sym->lineno != NULL)
4599
30.2k
      _bfd_error_handler
4600
        /* xgettext:c-format */
4601
30.2k
        (_("%pB: warning: duplicate line number information for `%s'"),
4602
30.2k
         abfd, bfd_asymbol_name (&sym->symbol));
4603
4604
30.9k
    sym->lineno = cache_ptr;
4605
30.9k
    if (sym->symbol.value < prev_offset)
4606
1.01k
      ordered = false;
4607
30.9k
    prev_offset = sym->symbol.value;
4608
30.9k
  }
4609
88.6k
      else if (!have_func)
4610
  /* Drop line information that has no associated function.
4611
     PR 17521: file: 078-10659-0.004.  */
4612
52.2k
  continue;
4613
36.3k
      else
4614
36.3k
  cache_ptr->u.offset = dst.l_addr.l_paddr - bfd_section_vma (asect);
4615
67.3k
      cache_ptr++;
4616
67.3k
    }
4617
4618
232
  asect->lineno_count = cache_ptr - lineno_cache;
4619
232
  memset (cache_ptr, 0, sizeof (*cache_ptr));
4620
232
  free (native_lineno);
4621
4622
  /* On some systems (eg AIX5.3) the lineno table may not be sorted.  */
4623
232
  if (!ordered)
4624
130
    {
4625
      /* Sort the table.  */
4626
130
      alent **func_table;
4627
130
      alent *n_lineno_cache;
4628
4629
      /* Create a table of functions.  */
4630
130
      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
130
      else if ((func_table = (alent **) bfd_alloc (abfd, amt)) != NULL)
4636
130
  {
4637
130
    alent **p = func_table;
4638
130
    unsigned int i;
4639
4640
65.7k
    for (i = 0; i < asect->lineno_count; i++)
4641
65.6k
      if (lineno_cache[i].line_number == 0)
4642
30.0k
        *p++ = &lineno_cache[i];
4643
4644
130
    BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
4645
4646
    /* Sort by functions.  */
4647
130
    qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
4648
4649
    /* Create the new sorted table.  */
4650
130
    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
130
    else if ((n_lineno_cache = (alent *) bfd_alloc (abfd, amt)) != NULL)
4656
130
      {
4657
130
        alent *n_cache_ptr = n_lineno_cache;
4658
4659
30.2k
        for (i = 0; i < nbr_func; i++)
4660
30.0k
    {
4661
30.0k
      coff_symbol_type *sym;
4662
30.0k
      alent *old_ptr = func_table[i];
4663
4664
      /* Update the function entry.  */
4665
30.0k
      sym = (coff_symbol_type *) old_ptr->u.sym;
4666
      /* PR binutils/17512: Point the lineno to where
4667
         this entry will be after the memcpy below.  */
4668
30.0k
      sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
4669
      /* Copy the function and line number entries.  */
4670
30.0k
      do
4671
65.6k
        *n_cache_ptr++ = *old_ptr++;
4672
65.6k
      while (old_ptr->line_number != 0);
4673
30.0k
    }
4674
4675
130
        memcpy (lineno_cache, n_lineno_cache,
4676
130
          asect->lineno_count * sizeof (alent));
4677
130
      }
4678
0
    else
4679
0
      ret = false;
4680
130
    bfd_release (abfd, func_table);
4681
130
  }
4682
0
      else
4683
0
  ret = false;
4684
130
    }
4685
4686
232
  return ret;
4687
232
}
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
46.6k
{
4696
46.6k
  combined_entry_type *native_symbols;
4697
46.6k
  coff_symbol_type *cached_area;
4698
46.6k
  unsigned int *table_ptr;
4699
46.6k
  unsigned int number_of_symbols = 0;
4700
46.6k
  bool ret = true;
4701
46.6k
  size_t amt;
4702
4703
46.6k
  if (obj_symbols (abfd))
4704
18.1k
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
28.4k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
14.5k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
13.9k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
13.9k
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
13.9k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
13.9k
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
13.9k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
13.9k
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
13.9k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
13.9k
  if (table_ptr == NULL)
4729
0
    return false;
4730
13.9k
  else
4731
13.9k
    {
4732
13.9k
      coff_symbol_type *dst = cached_area;
4733
13.9k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
13.9k
      unsigned int this_index = 0;
4735
4736
2.51M
      while (this_index < last_native_index)
4737
2.50M
  {
4738
2.50M
    combined_entry_type *src = native_symbols + this_index;
4739
2.50M
    table_ptr[this_index] = number_of_symbols;
4740
4741
2.50M
    dst->symbol.the_bfd = abfd;
4742
2.50M
    BFD_ASSERT (src->is_sym);
4743
2.50M
    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
2.50M
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
2.50M
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
2.50M
                 src->u.syment.n_scnum);
4748
2.50M
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
2.50M
    dst->symbol.value = 0;
4751
2.50M
    dst->done_lineno = false;
4752
4753
2.50M
    switch (src->u.syment.n_sclass)
4754
2.50M
      {
4755
52.1k
      case C_EXT:
4756
55.9k
      case C_WEAKEXT:
4757
#if defined ARM
4758
1.05k
      case C_THUMBEXT:
4759
1.10k
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
11.4k
      case C_HIDEXT:
4763
11.4k
#ifndef AIX_WEAK_SUPPORT
4764
13.6k
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
13.6k
#ifdef C_SYSTEM
4768
63.2k
      case C_SYSTEM: /* System Wide variable.  */
4769
63.2k
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
34.2k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
43.7k
      case C_NT_WEAK:
4775
#endif
4776
43.7k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
43.7k
    {
4778
61.7k
    case COFF_SYMBOL_GLOBAL:
4779
61.7k
      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
61.7k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
2.16k
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
61.7k
      break;
4793
4794
7.91k
    case COFF_SYMBOL_COMMON:
4795
7.91k
      dst->symbol.section = bfd_com_section_ptr;
4796
7.91k
      dst->symbol.value = src->u.syment.n_value;
4797
7.91k
      break;
4798
4799
2.96k
    case COFF_SYMBOL_UNDEFINED:
4800
2.96k
      dst->symbol.section = bfd_und_section_ptr;
4801
2.96k
      dst->symbol.value = 0;
4802
2.96k
      break;
4803
4804
20
    case COFF_SYMBOL_PE_SECTION:
4805
20
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
20
      dst->symbol.value = 0;
4807
20
      break;
4808
4809
587
    case COFF_SYMBOL_LOCAL:
4810
587
      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
587
      if (ISFCN ((src->u.syment.n_type)))
4820
239
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
587
      break;
4822
43.7k
    }
4823
4824
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
14.3k
        if (src->u.syment.n_numaux > 0)
4827
9.20k
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
#endif
4829
4830
#ifdef COFF_WITH_PE
4831
43.7k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
9.46k
    dst->symbol.flags |= BSF_WEAK;
4833
4834
43.7k
        if (src->u.syment.n_sclass == C_SECTION
4835
43.7k
      && src->u.syment.n_scnum > 0)
4836
18
    dst->symbol.flags = BSF_LOCAL;
4837
#endif
4838
73.2k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
13.9k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
15.0k
      )
4843
6.05k
    dst->symbol.flags |= BSF_WEAK;
4844
4845
15.0k
        break;
4846
4847
25.0k
      case C_STAT:  /* Static.  */
4848
#if defined ARM
4849
1.25k
      case C_THUMBSTAT:    /* Thumb static.  */
4850
1.26k
      case C_THUMBLABEL:   /* Thumb label.  */
4851
1.34k
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
#endif
4853
#ifdef RS6000COFF_C
4854
6.55k
      case C_DWARF:  /* A label in a dwarf section.  */
4855
9.71k
      case C_INFO:  /* A label in a comment section.  */
4856
#endif
4857
48.5k
      case C_LABEL:  /* Label.  */
4858
48.5k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
19
    dst->symbol.flags = BSF_DEBUGGING;
4860
48.4k
        else
4861
48.4k
    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
48.5k
        if (dst->symbol.section)
4866
48.5k
    {
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
48.5k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
48.5k
        break;
4879
4880
11.6k
      case C_FILE: /* File name.  */
4881
11.6k
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
22.0k
      case C_MOS:   /* Member of structure.  */
4884
28.7k
      case C_EOS:   /* End of structure.  */
4885
35.3k
      case C_REGPARM: /* Register parameter.  */
4886
52.3k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
61.5k
      case C_TPDEF: /* Type definition.  */
4889
69.5k
      case C_ARG:
4890
179k
      case C_AUTO: /* Automatic variable.  */
4891
189k
      case C_FIELD: /* Bit field.  */
4892
195k
      case C_ENTAG: /* Enumeration tag.  */
4893
210k
      case C_MOE:   /* Member of enumeration.  */
4894
220k
      case C_MOU:   /* Member of union.  */
4895
232k
      case C_UNTAG: /* Union tag.  */
4896
249k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
51.2k
      case C_GSYM:
4899
52.2k
      case C_LSYM:
4900
52.5k
      case C_PSYM:
4901
53.1k
      case C_RSYM:
4902
54.2k
      case C_RPSYM:
4903
54.6k
      case C_STSYM:
4904
55.0k
      case C_TCSYM:
4905
55.2k
      case C_BCOMM:
4906
55.8k
      case C_ECOML:
4907
56.3k
      case C_ECOMM:
4908
56.7k
      case C_DECL:
4909
56.9k
      case C_ENTRY:
4910
57.2k
      case C_FUN:
4911
58.4k
      case C_ESTAT:
4912
#endif
4913
258k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
58.4k
        dst->symbol.value = (src->u.syment.n_value);
4915
58.4k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
2.58k
      case C_BINCL: /* Beginning of include file.  */
4919
4.24k
      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
4.24k
        {
4925
4.24k
    asection *sec;
4926
4927
4.24k
    dst->symbol.flags = BSF_DEBUGGING;
4928
1.80M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
1.80M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
1.80M
          && ((file_ptr) (sec->line_filepos
4931
1.55M
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
1.55M
        > (file_ptr) src->u.syment.n_value))
4933
1.95k
        break;
4934
4.24k
    if (sec == NULL)
4935
2.29k
      dst->symbol.value = 0;
4936
1.95k
    else
4937
1.95k
      {
4938
1.95k
        dst->symbol.section = sec;
4939
1.95k
        dst->symbol.value = ((src->u.syment.n_value
4940
1.95k
            - sec->line_filepos)
4941
1.95k
           / bfd_coff_linesz (abfd));
4942
1.95k
        src->fix_line = 1;
4943
1.95k
      }
4944
4.24k
        }
4945
4.24k
        break;
4946
4947
255
      case C_BSTAT:
4948
255
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
255
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
230
    dst->symbol.value = 0;
4952
25
        else
4953
25
    {
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
25
      src->u.syment.n_value
4958
25
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
25
      dst->symbol.value = src->u.syment.n_value;
4960
25
      src->fix_value = 1;
4961
25
    }
4962
255
        break;
4963
0
#endif
4964
4965
4.54k
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
27.2k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
36.8k
      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
21.1k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
21.0k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
21.0k
      dst->symbol.flags = BSF_DEBUGGING;
4977
21.0k
    }
4978
10
        else
4979
10
    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
15.7k
        dst->symbol.flags = BSF_LOCAL;
4984
        dst->symbol.value = (src->u.syment.n_value
4985
           - dst->symbol.section->vma);
4986
#endif
4987
36.8k
        break;
4988
4989
4.35k
      case C_STATLAB: /* Static load time label.  */
4990
4.35k
        dst->symbol.value = src->u.syment.n_value;
4991
4.35k
        dst->symbol.flags = BSF_GLOBAL;
4992
4.35k
        break;
4993
4994
1.70M
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
1.70M
        if (src->u.syment.n_type == 0
4998
1.70M
      && src->u.syment.n_value == 0
4999
1.70M
      && src->u.syment.n_scnum == 0)
5000
764k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
214k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
3
    break;
5005
214k
#endif
5006
        /* Fall through.  */
5007
944k
      case C_EXTDEF: /* External definition.  */
5008
947k
      case C_ULABEL: /* Undefined label.  */
5009
949k
      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
461k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
466k
      case C_ALIAS: /* Duplicate tag.  */
5016
466k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
52.9k
      case C_UEXT: /* Tentative external definition.  */
5020
#endif
5021
960k
      case C_EXTLAB: /* External load time label.  */
5022
1.31M
      default:
5023
1.31M
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
1.31M
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
1.31M
     abfd, src->u.syment.n_sclass,
5027
1.31M
     dst->symbol.section->name, dst->symbol.name);
5028
1.31M
        ret = false;
5029
        /* Fall through.  */
5030
1.31M
      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.31M
        dst->symbol.flags = BSF_DEBUGGING;
5034
1.31M
        dst->symbol.value = (src->u.syment.n_value);
5035
1.31M
        break;
5036
2.50M
      }
5037
5038
2.50M
    dst->native = src;
5039
2.50M
    dst->symbol.udata.i = 0;
5040
2.50M
    dst->lineno = NULL;
5041
5042
2.50M
    this_index += (src->u.syment.n_numaux) + 1;
5043
2.50M
    dst++;
5044
2.50M
    number_of_symbols++;
5045
2.50M
  }
5046
13.9k
    }
5047
5048
13.9k
  obj_symbols (abfd) = cached_area;
5049
13.9k
  obj_raw_syments (abfd) = native_symbols;
5050
5051
13.9k
  abfd->symcount = number_of_symbols;
5052
13.9k
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
13.9k
  {
5055
13.9k
    asection *p;
5056
5057
13.9k
    p = abfd->sections;
5058
112k
    while (p)
5059
108k
      {
5060
108k
  if (! coff_slurp_line_table (abfd, p))
5061
9.30k
    return false;
5062
98.8k
  p = p->next;
5063
98.8k
      }
5064
13.9k
  }
5065
5066
4.61k
  return ret;
5067
13.9k
}
pei-i386.c:coff_slurp_symbol_table
Line
Count
Source
4695
693
{
4696
693
  combined_entry_type *native_symbols;
4697
693
  coff_symbol_type *cached_area;
4698
693
  unsigned int *table_ptr;
4699
693
  unsigned int number_of_symbols = 0;
4700
693
  bool ret = true;
4701
693
  size_t amt;
4702
4703
693
  if (obj_symbols (abfd))
4704
135
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
558
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
204
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
354
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
354
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
354
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
354
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
354
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
354
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
354
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
354
  if (table_ptr == NULL)
4729
0
    return false;
4730
354
  else
4731
354
    {
4732
354
      coff_symbol_type *dst = cached_area;
4733
354
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
354
      unsigned int this_index = 0;
4735
4736
44.9k
      while (this_index < last_native_index)
4737
44.6k
  {
4738
44.6k
    combined_entry_type *src = native_symbols + this_index;
4739
44.6k
    table_ptr[this_index] = number_of_symbols;
4740
4741
44.6k
    dst->symbol.the_bfd = abfd;
4742
44.6k
    BFD_ASSERT (src->is_sym);
4743
44.6k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
44.6k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
44.6k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
44.6k
                 src->u.syment.n_scnum);
4748
44.6k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
44.6k
    dst->symbol.value = 0;
4751
44.6k
    dst->done_lineno = false;
4752
4753
44.6k
    switch (src->u.syment.n_sclass)
4754
44.6k
      {
4755
966
      case C_EXT:
4756
1.11k
      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.11k
#ifdef C_SYSTEM
4768
1.17k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.17k
#endif
4770
1.17k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.19k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
1.51k
      case C_NT_WEAK:
4775
1.51k
#endif
4776
1.51k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.51k
    {
4778
1.34k
    case COFF_SYMBOL_GLOBAL:
4779
1.34k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.34k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.34k
      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.34k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
37
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.34k
      break;
4793
4794
101
    case COFF_SYMBOL_COMMON:
4795
101
      dst->symbol.section = bfd_com_section_ptr;
4796
101
      dst->symbol.value = src->u.syment.n_value;
4797
101
      break;
4798
4799
72
    case COFF_SYMBOL_UNDEFINED:
4800
72
      dst->symbol.section = bfd_und_section_ptr;
4801
72
      dst->symbol.value = 0;
4802
72
      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.51k
    }
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.51k
#ifdef COFF_WITH_PE
4831
1.51k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
315
    dst->symbol.flags |= BSF_WEAK;
4833
4834
1.51k
        if (src->u.syment.n_sclass == C_SECTION
4835
1.51k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
1.51k
#endif
4838
1.51k
        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.51k
      )
4843
151
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.51k
        break;
4846
4847
836
      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
969
      case C_LABEL:  /* Label.  */
4858
969
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
969
        else
4861
969
    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
969
        if (dst->symbol.section)
4866
969
    {
4867
969
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
969
      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
969
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
969
        break;
4879
4880
214
      case C_FILE: /* File name.  */
4881
214
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
469
      case C_MOS:   /* Member of structure.  */
4884
534
      case C_EOS:   /* End of structure.  */
4885
956
      case C_REGPARM: /* Register parameter.  */
4886
1.40k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.56k
      case C_TPDEF: /* Type definition.  */
4889
1.72k
      case C_ARG:
4890
3.53k
      case C_AUTO: /* Automatic variable.  */
4891
3.73k
      case C_FIELD: /* Bit field.  */
4892
3.79k
      case C_ENTAG: /* Enumeration tag.  */
4893
4.00k
      case C_MOE:   /* Member of enumeration.  */
4894
4.13k
      case C_MOU:   /* Member of union.  */
4895
4.34k
      case C_UNTAG: /* Union tag.  */
4896
4.51k
      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.51k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
4.51k
        dst->symbol.value = (src->u.syment.n_value);
4915
4.51k
        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
115
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
634
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
794
      case C_EFCN: /* Physical end of function.  */
4968
794
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
794
        dst->symbol.value = src->u.syment.n_value;
4972
794
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
794
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
794
      dst->symbol.flags = BSF_DEBUGGING;
4977
794
    }
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
794
        break;
4988
4989
139
      case C_STATLAB: /* Static load time label.  */
4990
139
        dst->symbol.value = src->u.syment.n_value;
4991
139
        dst->symbol.flags = BSF_GLOBAL;
4992
139
        break;
4993
4994
28.9k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
28.9k
        if (src->u.syment.n_type == 0
4998
28.9k
      && src->u.syment.n_value == 0
4999
28.9k
      && src->u.syment.n_scnum == 0)
5000
11.9k
    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
17.0k
      case C_EXTDEF: /* External definition.  */
5008
17.1k
      case C_ULABEL: /* Undefined label.  */
5009
17.1k
      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
17.1k
      case C_EXTLAB: /* External load time label.  */
5022
24.7k
      default:
5023
24.7k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
24.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
24.7k
     abfd, src->u.syment.n_sclass,
5027
24.7k
     dst->symbol.section->name, dst->symbol.name);
5028
24.7k
        ret = false;
5029
        /* Fall through.  */
5030
24.7k
      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.7k
        dst->symbol.flags = BSF_DEBUGGING;
5034
24.7k
        dst->symbol.value = (src->u.syment.n_value);
5035
24.7k
        break;
5036
44.6k
      }
5037
5038
44.6k
    dst->native = src;
5039
44.6k
    dst->symbol.udata.i = 0;
5040
44.6k
    dst->lineno = NULL;
5041
5042
44.6k
    this_index += (src->u.syment.n_numaux) + 1;
5043
44.6k
    dst++;
5044
44.6k
    number_of_symbols++;
5045
44.6k
  }
5046
354
    }
5047
5048
354
  obj_symbols (abfd) = cached_area;
5049
354
  obj_raw_syments (abfd) = native_symbols;
5050
5051
354
  abfd->symcount = number_of_symbols;
5052
354
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
354
  {
5055
354
    asection *p;
5056
5057
354
    p = abfd->sections;
5058
8.96k
    while (p)
5059
8.88k
      {
5060
8.88k
  if (! coff_slurp_line_table (abfd, p))
5061
273
    return false;
5062
8.61k
  p = p->next;
5063
8.61k
      }
5064
354
  }
5065
5066
81
  return ret;
5067
354
}
pe-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.89k
{
4696
1.89k
  combined_entry_type *native_symbols;
4697
1.89k
  coff_symbol_type *cached_area;
4698
1.89k
  unsigned int *table_ptr;
4699
1.89k
  unsigned int number_of_symbols = 0;
4700
1.89k
  bool ret = true;
4701
1.89k
  size_t amt;
4702
4703
1.89k
  if (obj_symbols (abfd))
4704
547
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.35k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
538
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
812
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
812
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
812
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
812
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
812
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
812
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
812
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
812
  if (table_ptr == NULL)
4729
0
    return false;
4730
812
  else
4731
812
    {
4732
812
      coff_symbol_type *dst = cached_area;
4733
812
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
812
      unsigned int this_index = 0;
4735
4736
108k
      while (this_index < last_native_index)
4737
107k
  {
4738
107k
    combined_entry_type *src = native_symbols + this_index;
4739
107k
    table_ptr[this_index] = number_of_symbols;
4740
4741
107k
    dst->symbol.the_bfd = abfd;
4742
107k
    BFD_ASSERT (src->is_sym);
4743
107k
    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
107k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
107k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
107k
                 src->u.syment.n_scnum);
4748
107k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
107k
    dst->symbol.value = 0;
4751
107k
    dst->done_lineno = false;
4752
4753
107k
    switch (src->u.syment.n_sclass)
4754
107k
      {
4755
2.69k
      case C_EXT:
4756
2.97k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.97k
#ifdef C_SYSTEM
4768
3.25k
      case C_SYSTEM: /* System Wide variable.  */
4769
3.25k
#endif
4770
3.25k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
3.40k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
3.72k
      case C_NT_WEAK:
4775
3.72k
#endif
4776
3.72k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
3.72k
    {
4778
2.96k
    case COFF_SYMBOL_GLOBAL:
4779
2.96k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2.96k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2.96k
      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.96k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
78
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.96k
      break;
4793
4794
457
    case COFF_SYMBOL_COMMON:
4795
457
      dst->symbol.section = bfd_com_section_ptr;
4796
457
      dst->symbol.value = src->u.syment.n_value;
4797
457
      break;
4798
4799
286
    case COFF_SYMBOL_UNDEFINED:
4800
286
      dst->symbol.section = bfd_und_section_ptr;
4801
286
      dst->symbol.value = 0;
4802
286
      break;
4803
4804
20
    case COFF_SYMBOL_PE_SECTION:
4805
20
      dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
4806
20
      dst->symbol.value = 0;
4807
20
      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.72k
    }
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.72k
#ifdef COFF_WITH_PE
4831
3.72k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
321
    dst->symbol.flags |= BSF_WEAK;
4833
4834
3.72k
        if (src->u.syment.n_sclass == C_SECTION
4835
3.72k
      && src->u.syment.n_scnum > 0)
4836
18
    dst->symbol.flags = BSF_LOCAL;
4837
3.72k
#endif
4838
3.72k
        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.72k
      )
4843
276
    dst->symbol.flags |= BSF_WEAK;
4844
4845
3.72k
        break;
4846
4847
1.14k
      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.75k
      case C_LABEL:  /* Label.  */
4858
1.75k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
1
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.75k
        else
4861
1.75k
    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.75k
        if (dst->symbol.section)
4866
1.75k
    {
4867
1.75k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.75k
      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.75k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.75k
        break;
4879
4880
362
      case C_FILE: /* File name.  */
4881
362
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
970
      case C_MOS:   /* Member of structure.  */
4884
1.08k
      case C_EOS:   /* End of structure.  */
4885
1.33k
      case C_REGPARM: /* Register parameter.  */
4886
2.15k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.63k
      case C_TPDEF: /* Type definition.  */
4889
3.41k
      case C_ARG:
4890
8.73k
      case C_AUTO: /* Automatic variable.  */
4891
9.17k
      case C_FIELD: /* Bit field.  */
4892
9.50k
      case C_ENTAG: /* Enumeration tag.  */
4893
10.2k
      case C_MOE:   /* Member of enumeration.  */
4894
10.6k
      case C_MOU:   /* Member of union.  */
4895
11.0k
      case C_UNTAG: /* Union tag.  */
4896
11.7k
      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
11.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
11.7k
        dst->symbol.value = (src->u.syment.n_value);
4915
11.7k
        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
139
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
542
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.10k
      case C_EFCN: /* Physical end of function.  */
4968
1.10k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.10k
        dst->symbol.value = src->u.syment.n_value;
4972
1.10k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.10k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.10k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.10k
    }
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.10k
        break;
4988
4989
385
      case C_STATLAB: /* Static load time label.  */
4990
385
        dst->symbol.value = src->u.syment.n_value;
4991
385
        dst->symbol.flags = BSF_GLOBAL;
4992
385
        break;
4993
4994
73.8k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
73.8k
        if (src->u.syment.n_type == 0
4998
73.8k
      && src->u.syment.n_value == 0
4999
73.8k
      && src->u.syment.n_scnum == 0)
5000
23.4k
    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
50.6k
      case C_EXTDEF: /* External definition.  */
5008
50.8k
      case C_ULABEL: /* Undefined label.  */
5009
50.9k
      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
51.0k
      case C_EXTLAB: /* External load time label.  */
5022
65.0k
      default:
5023
65.0k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
65.0k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
65.0k
     abfd, src->u.syment.n_sclass,
5027
65.0k
     dst->symbol.section->name, dst->symbol.name);
5028
65.0k
        ret = false;
5029
        /* Fall through.  */
5030
65.1k
      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
65.1k
        dst->symbol.flags = BSF_DEBUGGING;
5034
65.1k
        dst->symbol.value = (src->u.syment.n_value);
5035
65.1k
        break;
5036
107k
      }
5037
5038
107k
    dst->native = src;
5039
107k
    dst->symbol.udata.i = 0;
5040
107k
    dst->lineno = NULL;
5041
5042
107k
    this_index += (src->u.syment.n_numaux) + 1;
5043
107k
    dst++;
5044
107k
    number_of_symbols++;
5045
107k
  }
5046
812
    }
5047
5048
812
  obj_symbols (abfd) = cached_area;
5049
812
  obj_raw_syments (abfd) = native_symbols;
5050
5051
812
  abfd->symcount = number_of_symbols;
5052
812
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
812
  {
5055
812
    asection *p;
5056
5057
812
    p = abfd->sections;
5058
10.8k
    while (p)
5059
10.5k
      {
5060
10.5k
  if (! coff_slurp_line_table (abfd, p))
5061
478
    return false;
5062
10.0k
  p = p->next;
5063
10.0k
      }
5064
812
  }
5065
5066
334
  return ret;
5067
812
}
pei-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
877
{
4696
877
  combined_entry_type *native_symbols;
4697
877
  coff_symbol_type *cached_area;
4698
877
  unsigned int *table_ptr;
4699
877
  unsigned int number_of_symbols = 0;
4700
877
  bool ret = true;
4701
877
  size_t amt;
4702
4703
877
  if (obj_symbols (abfd))
4704
166
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
711
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
246
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
465
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
465
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
465
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
465
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
465
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
465
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
465
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
465
  if (table_ptr == NULL)
4729
0
    return false;
4730
465
  else
4731
465
    {
4732
465
      coff_symbol_type *dst = cached_area;
4733
465
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
465
      unsigned int this_index = 0;
4735
4736
54.2k
      while (this_index < last_native_index)
4737
53.8k
  {
4738
53.8k
    combined_entry_type *src = native_symbols + this_index;
4739
53.8k
    table_ptr[this_index] = number_of_symbols;
4740
4741
53.8k
    dst->symbol.the_bfd = abfd;
4742
53.8k
    BFD_ASSERT (src->is_sym);
4743
53.8k
    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
53.8k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
53.8k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
53.8k
                 src->u.syment.n_scnum);
4748
53.8k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
53.8k
    dst->symbol.value = 0;
4751
53.8k
    dst->done_lineno = false;
4752
4753
53.8k
    switch (src->u.syment.n_sclass)
4754
53.8k
      {
4755
2.20k
      case C_EXT:
4756
2.28k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.28k
#ifdef C_SYSTEM
4768
2.38k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.38k
#endif
4770
2.38k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
2.40k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.98k
      case C_NT_WEAK:
4775
2.98k
#endif
4776
2.98k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.98k
    {
4778
2.52k
    case COFF_SYMBOL_GLOBAL:
4779
2.52k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2.52k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2.52k
      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.52k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
255
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.52k
      break;
4793
4794
123
    case COFF_SYMBOL_COMMON:
4795
123
      dst->symbol.section = bfd_com_section_ptr;
4796
123
      dst->symbol.value = src->u.syment.n_value;
4797
123
      break;
4798
4799
337
    case COFF_SYMBOL_UNDEFINED:
4800
337
      dst->symbol.section = bfd_und_section_ptr;
4801
337
      dst->symbol.value = 0;
4802
337
      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.98k
    }
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.98k
#ifdef COFF_WITH_PE
4831
2.98k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
579
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.98k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.98k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.98k
#endif
4838
2.98k
        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.98k
      )
4843
84
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.98k
        break;
4846
4847
2.56k
      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.72k
      case C_LABEL:  /* Label.  */
4858
2.72k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
2.72k
        else
4861
2.72k
    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.72k
        if (dst->symbol.section)
4866
2.72k
    {
4867
2.72k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
2.72k
      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.72k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
2.72k
        break;
4879
4880
538
      case C_FILE: /* File name.  */
4881
538
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
906
      case C_MOS:   /* Member of structure.  */
4884
1.14k
      case C_EOS:   /* End of structure.  */
4885
1.90k
      case C_REGPARM: /* Register parameter.  */
4886
2.07k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.27k
      case C_TPDEF: /* Type definition.  */
4889
2.35k
      case C_ARG:
4890
3.56k
      case C_AUTO: /* Automatic variable.  */
4891
3.63k
      case C_FIELD: /* Bit field.  */
4892
3.72k
      case C_ENTAG: /* Enumeration tag.  */
4893
3.88k
      case C_MOE:   /* Member of enumeration.  */
4894
3.92k
      case C_MOU:   /* Member of union.  */
4895
4.02k
      case C_UNTAG: /* Union tag.  */
4896
4.32k
      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.32k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
4.32k
        dst->symbol.value = (src->u.syment.n_value);
4915
4.32k
        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
134
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
981
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.22k
      case C_EFCN: /* Physical end of function.  */
4968
1.22k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.22k
        dst->symbol.value = src->u.syment.n_value;
4972
1.22k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.22k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.22k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.22k
    }
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.22k
        break;
4988
4989
81
      case C_STATLAB: /* Static load time label.  */
4990
81
        dst->symbol.value = src->u.syment.n_value;
4991
81
        dst->symbol.flags = BSF_GLOBAL;
4992
81
        break;
4993
4994
31.5k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
31.5k
        if (src->u.syment.n_type == 0
4998
31.5k
      && src->u.syment.n_value == 0
4999
31.5k
      && src->u.syment.n_scnum == 0)
5000
12.9k
    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.6k
      case C_EXTDEF: /* External definition.  */
5008
18.6k
      case C_ULABEL: /* Undefined label.  */
5009
18.7k
      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.7k
      case C_EXTLAB: /* External load time label.  */
5022
29.4k
      default:
5023
29.4k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
29.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
29.4k
     abfd, src->u.syment.n_sclass,
5027
29.4k
     dst->symbol.section->name, dst->symbol.name);
5028
29.4k
        ret = false;
5029
        /* Fall through.  */
5030
29.4k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
29.4k
        dst->symbol.flags = BSF_DEBUGGING;
5034
29.4k
        dst->symbol.value = (src->u.syment.n_value);
5035
29.4k
        break;
5036
53.8k
      }
5037
5038
53.8k
    dst->native = src;
5039
53.8k
    dst->symbol.udata.i = 0;
5040
53.8k
    dst->lineno = NULL;
5041
5042
53.8k
    this_index += (src->u.syment.n_numaux) + 1;
5043
53.8k
    dst++;
5044
53.8k
    number_of_symbols++;
5045
53.8k
  }
5046
465
    }
5047
5048
465
  obj_symbols (abfd) = cached_area;
5049
465
  obj_raw_syments (abfd) = native_symbols;
5050
5051
465
  abfd->symcount = number_of_symbols;
5052
465
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
465
  {
5055
465
    asection *p;
5056
5057
465
    p = abfd->sections;
5058
1.60k
    while (p)
5059
1.45k
      {
5060
1.45k
  if (! coff_slurp_line_table (abfd, p))
5061
316
    return false;
5062
1.14k
  p = p->next;
5063
1.14k
      }
5064
465
  }
5065
5066
149
  return ret;
5067
465
}
coff-x86_64.c:coff_slurp_symbol_table
Line
Count
Source
4695
4.56k
{
4696
4.56k
  combined_entry_type *native_symbols;
4697
4.56k
  coff_symbol_type *cached_area;
4698
4.56k
  unsigned int *table_ptr;
4699
4.56k
  unsigned int number_of_symbols = 0;
4700
4.56k
  bool ret = true;
4701
4.56k
  size_t amt;
4702
4703
4.56k
  if (obj_symbols (abfd))
4704
920
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
3.64k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
2.50k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
1.13k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
1.13k
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
1.13k
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
1.13k
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
1.13k
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
1.13k
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
1.13k
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
1.13k
  if (table_ptr == NULL)
4729
0
    return false;
4730
1.13k
  else
4731
1.13k
    {
4732
1.13k
      coff_symbol_type *dst = cached_area;
4733
1.13k
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
1.13k
      unsigned int this_index = 0;
4735
4736
80.9k
      while (this_index < last_native_index)
4737
79.8k
  {
4738
79.8k
    combined_entry_type *src = native_symbols + this_index;
4739
79.8k
    table_ptr[this_index] = number_of_symbols;
4740
4741
79.8k
    dst->symbol.the_bfd = abfd;
4742
79.8k
    BFD_ASSERT (src->is_sym);
4743
79.8k
    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
79.8k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
79.8k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
79.8k
                 src->u.syment.n_scnum);
4748
79.8k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
79.8k
    dst->symbol.value = 0;
4751
79.8k
    dst->done_lineno = false;
4752
4753
79.8k
    switch (src->u.syment.n_sclass)
4754
79.8k
      {
4755
1.90k
      case C_EXT:
4756
2.35k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.35k
#ifdef C_SYSTEM
4768
2.54k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.54k
#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
2.54k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.54k
    {
4778
2.00k
    case COFF_SYMBOL_GLOBAL:
4779
2.00k
      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.00k
      dst->symbol.value = (src->u.syment.n_value
4786
2.00k
               - dst->symbol.section->vma);
4787
2.00k
#endif
4788
2.00k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
42
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.00k
      break;
4793
4794
447
    case COFF_SYMBOL_COMMON:
4795
447
      dst->symbol.section = bfd_com_section_ptr;
4796
447
      dst->symbol.value = src->u.syment.n_value;
4797
447
      break;
4798
4799
101
    case COFF_SYMBOL_UNDEFINED:
4800
101
      dst->symbol.section = bfd_und_section_ptr;
4801
101
      dst->symbol.value = 0;
4802
101
      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
2.54k
    }
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
2.54k
        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.54k
      )
4843
451
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.54k
        break;
4846
4847
591
      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.30k
      case C_LABEL:  /* Label.  */
4858
1.30k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
2
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.30k
        else
4861
1.30k
    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.30k
        if (dst->symbol.section)
4866
1.30k
    {
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.30k
      dst->symbol.value = (src->u.syment.n_value
4873
1.30k
               - dst->symbol.section->vma);
4874
1.30k
#endif
4875
1.30k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.30k
        break;
4879
4880
322
      case C_FILE: /* File name.  */
4881
322
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
688
      case C_MOS:   /* Member of structure.  */
4884
848
      case C_EOS:   /* End of structure.  */
4885
1.56k
      case C_REGPARM: /* Register parameter.  */
4886
2.26k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.56k
      case C_TPDEF: /* Type definition.  */
4889
3.31k
      case C_ARG:
4890
7.33k
      case C_AUTO: /* Automatic variable.  */
4891
7.75k
      case C_FIELD: /* Bit field.  */
4892
8.02k
      case C_ENTAG: /* Enumeration tag.  */
4893
8.65k
      case C_MOE:   /* Member of enumeration.  */
4894
8.87k
      case C_MOU:   /* Member of union.  */
4895
9.18k
      case C_UNTAG: /* Union tag.  */
4896
9.64k
      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
9.64k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
9.64k
        dst->symbol.value = (src->u.syment.n_value);
4915
9.64k
        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
197
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
616
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
962
      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
962
        dst->symbol.flags = BSF_LOCAL;
4984
962
        dst->symbol.value = (src->u.syment.n_value
4985
962
           - dst->symbol.section->vma);
4986
962
#endif
4987
962
        break;
4988
4989
255
      case C_STATLAB: /* Static load time label.  */
4990
255
        dst->symbol.value = src->u.syment.n_value;
4991
255
        dst->symbol.flags = BSF_GLOBAL;
4992
255
        break;
4993
4994
53.1k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
53.1k
        if (src->u.syment.n_type == 0
4998
53.1k
      && src->u.syment.n_value == 0
4999
53.1k
      && src->u.syment.n_scnum == 0)
5000
19.5k
    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
33.7k
      case C_EXTDEF: /* External definition.  */
5008
33.9k
      case C_ULABEL: /* Undefined label.  */
5009
33.9k
      case C_USTATIC: /* Undefined static.  */
5010
33.9k
#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
34.2k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
34.4k
      case C_ALIAS: /* Duplicate tag.  */
5016
34.4k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
34.5k
      case C_EXTLAB: /* External load time label.  */
5022
45.4k
      default:
5023
45.4k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
45.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
45.4k
     abfd, src->u.syment.n_sclass,
5027
45.4k
     dst->symbol.section->name, dst->symbol.name);
5028
45.4k
        ret = false;
5029
        /* Fall through.  */
5030
45.5k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
45.5k
        dst->symbol.flags = BSF_DEBUGGING;
5034
45.5k
        dst->symbol.value = (src->u.syment.n_value);
5035
45.5k
        break;
5036
79.8k
      }
5037
5038
79.8k
    dst->native = src;
5039
79.8k
    dst->symbol.udata.i = 0;
5040
79.8k
    dst->lineno = NULL;
5041
5042
79.8k
    this_index += (src->u.syment.n_numaux) + 1;
5043
79.8k
    dst++;
5044
79.8k
    number_of_symbols++;
5045
79.8k
  }
5046
1.13k
    }
5047
5048
1.13k
  obj_symbols (abfd) = cached_area;
5049
1.13k
  obj_raw_syments (abfd) = native_symbols;
5050
5051
1.13k
  abfd->symcount = number_of_symbols;
5052
1.13k
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
1.13k
  {
5055
1.13k
    asection *p;
5056
5057
1.13k
    p = abfd->sections;
5058
31.0k
    while (p)
5059
30.7k
      {
5060
30.7k
  if (! coff_slurp_line_table (abfd, p))
5061
828
    return false;
5062
29.9k
  p = p->next;
5063
29.9k
      }
5064
1.13k
  }
5065
5066
311
  return ret;
5067
1.13k
}
coff64-rs6000.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.73k
{
4696
1.73k
  combined_entry_type *native_symbols;
4697
1.73k
  coff_symbol_type *cached_area;
4698
1.73k
  unsigned int *table_ptr;
4699
1.73k
  unsigned int number_of_symbols = 0;
4700
1.73k
  bool ret = true;
4701
1.73k
  size_t amt;
4702
4703
1.73k
  if (obj_symbols (abfd))
4704
206
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.52k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
615
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
910
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
910
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
910
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
910
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
910
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
910
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
910
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
910
  if (table_ptr == NULL)
4729
0
    return false;
4730
910
  else
4731
910
    {
4732
910
      coff_symbol_type *dst = cached_area;
4733
910
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
910
      unsigned int this_index = 0;
4735
4736
223k
      while (this_index < last_native_index)
4737
222k
  {
4738
222k
    combined_entry_type *src = native_symbols + this_index;
4739
222k
    table_ptr[this_index] = number_of_symbols;
4740
4741
222k
    dst->symbol.the_bfd = abfd;
4742
222k
    BFD_ASSERT (src->is_sym);
4743
222k
    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
222k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
222k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
222k
                 src->u.syment.n_scnum);
4748
222k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
222k
    dst->symbol.value = 0;
4751
222k
    dst->done_lineno = false;
4752
4753
222k
    switch (src->u.syment.n_sclass)
4754
222k
      {
4755
4.78k
      case C_EXT:
4756
4.96k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
4.96k
#ifdef RS6000COFF_C
4762
5.20k
      case C_HIDEXT:
4763
5.20k
#ifndef AIX_WEAK_SUPPORT
4764
6.44k
      case C_AIX_WEAKEXT:
4765
6.44k
#endif
4766
6.44k
#endif
4767
6.44k
#ifdef C_SYSTEM
4768
6.88k
      case C_SYSTEM: /* System Wide variable.  */
4769
6.88k
#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.88k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
6.88k
    {
4778
5.19k
    case COFF_SYMBOL_GLOBAL:
4779
5.19k
      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
5.19k
      dst->symbol.value = (src->u.syment.n_value
4786
5.19k
               - dst->symbol.section->vma);
4787
5.19k
#endif
4788
5.19k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
79
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
5.19k
      break;
4793
4794
1.17k
    case COFF_SYMBOL_COMMON:
4795
1.17k
      dst->symbol.section = bfd_com_section_ptr;
4796
1.17k
      dst->symbol.value = src->u.syment.n_value;
4797
1.17k
      break;
4798
4799
307
    case COFF_SYMBOL_UNDEFINED:
4800
307
      dst->symbol.section = bfd_und_section_ptr;
4801
307
      dst->symbol.value = 0;
4802
307
      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
212
    case COFF_SYMBOL_LOCAL:
4810
212
      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
212
      dst->symbol.value = (src->u.syment.n_value
4817
212
               - dst->symbol.section->vma);
4818
212
#endif
4819
212
      if (ISFCN ((src->u.syment.n_type)))
4820
57
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
212
      break;
4822
6.88k
    }
4823
4824
6.88k
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
6.88k
        if (src->u.syment.n_numaux > 0)
4827
3.90k
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
6.88k
#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.88k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
6.88k
#ifdef RS6000COFF_C
4840
6.88k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
6.88k
#endif
4842
6.88k
      )
4843
1.41k
    dst->symbol.flags |= BSF_WEAK;
4844
4845
6.88k
        break;
4846
4847
1.37k
      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
1.37k
#ifdef RS6000COFF_C
4854
3.90k
      case C_DWARF:  /* A label in a dwarf section.  */
4855
5.82k
      case C_INFO:  /* A label in a comment section.  */
4856
5.82k
#endif
4857
6.62k
      case C_LABEL:  /* Label.  */
4858
6.62k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
2
    dst->symbol.flags = BSF_DEBUGGING;
4860
6.62k
        else
4861
6.62k
    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
6.62k
        if (dst->symbol.section)
4866
6.62k
    {
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
6.62k
      dst->symbol.value = (src->u.syment.n_value
4873
6.62k
               - dst->symbol.section->vma);
4874
6.62k
#endif
4875
6.62k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
6.62k
        break;
4879
4880
1.50k
      case C_FILE: /* File name.  */
4881
1.50k
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
2.33k
      case C_MOS:   /* Member of structure.  */
4884
2.83k
      case C_EOS:   /* End of structure.  */
4885
3.05k
      case C_REGPARM: /* Register parameter.  */
4886
3.98k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
4.69k
      case C_TPDEF: /* Type definition.  */
4889
5.20k
      case C_ARG:
4890
15.8k
      case C_AUTO: /* Automatic variable.  */
4891
16.3k
      case C_FIELD: /* Bit field.  */
4892
16.8k
      case C_ENTAG: /* Enumeration tag.  */
4893
19.2k
      case C_MOE:   /* Member of enumeration.  */
4894
19.8k
      case C_MOU:   /* Member of union.  */
4895
20.3k
      case C_UNTAG: /* Union tag.  */
4896
21.3k
      case C_STRTAG: /* Structure tag.  */
4897
21.3k
#ifdef RS6000COFF_C
4898
21.7k
      case C_GSYM:
4899
21.8k
      case C_LSYM:
4900
21.9k
      case C_PSYM:
4901
22.0k
      case C_RSYM:
4902
22.2k
      case C_RPSYM:
4903
22.4k
      case C_STSYM:
4904
22.6k
      case C_TCSYM:
4905
22.7k
      case C_BCOMM:
4906
22.9k
      case C_ECOML:
4907
23.1k
      case C_ECOMM:
4908
23.4k
      case C_DECL:
4909
23.4k
      case C_ENTRY:
4910
23.5k
      case C_FUN:
4911
24.0k
      case C_ESTAT:
4912
24.0k
#endif
4913
24.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
24.0k
        dst->symbol.value = (src->u.syment.n_value);
4915
24.0k
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
1.53k
      case C_BINCL: /* Beginning of include file.  */
4919
2.65k
      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
2.65k
        {
4925
2.65k
    asection *sec;
4926
4927
2.65k
    dst->symbol.flags = BSF_DEBUGGING;
4928
1.68M
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
1.68M
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
1.68M
          && ((file_ptr) (sec->line_filepos
4931
1.48M
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
1.48M
        > (file_ptr) src->u.syment.n_value))
4933
1.59k
        break;
4934
2.65k
    if (sec == NULL)
4935
1.06k
      dst->symbol.value = 0;
4936
1.59k
    else
4937
1.59k
      {
4938
1.59k
        dst->symbol.section = sec;
4939
1.59k
        dst->symbol.value = ((src->u.syment.n_value
4940
1.59k
            - sec->line_filepos)
4941
1.59k
           / bfd_coff_linesz (abfd));
4942
1.59k
        src->fix_line = 1;
4943
1.59k
      }
4944
2.65k
        }
4945
2.65k
        break;
4946
4947
88
      case C_BSTAT:
4948
88
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
88
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
79
    dst->symbol.value = 0;
4952
9
        else
4953
9
    {
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
9
      src->u.syment.n_value
4958
9
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
9
      dst->symbol.value = src->u.syment.n_value;
4960
9
      src->fix_value = 1;
4961
9
    }
4962
88
        break;
4963
0
#endif
4964
4965
398
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
3.48k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
4.24k
      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.24k
        dst->symbol.flags = BSF_LOCAL;
4984
4.24k
        dst->symbol.value = (src->u.syment.n_value
4985
4.24k
           - dst->symbol.section->vma);
4986
4.24k
#endif
4987
4.24k
        break;
4988
4989
424
      case C_STATLAB: /* Static load time label.  */
4990
424
        dst->symbol.value = src->u.syment.n_value;
4991
424
        dst->symbol.flags = BSF_GLOBAL;
4992
424
        break;
4993
4994
142k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
142k
        if (src->u.syment.n_type == 0
4998
142k
      && src->u.syment.n_value == 0
4999
142k
      && src->u.syment.n_scnum == 0)
5000
34.4k
    break;
5001
108k
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
108k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
2
    break;
5005
108k
#endif
5006
        /* Fall through.  */
5007
108k
      case C_EXTDEF: /* External definition.  */
5008
108k
      case C_ULABEL: /* Undefined label.  */
5009
108k
      case C_USTATIC: /* Undefined static.  */
5010
108k
#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
110k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
112k
      case C_ALIAS: /* Duplicate tag.  */
5016
112k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
112k
      case C_EXTLAB: /* External load time label.  */
5022
143k
      default:
5023
143k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
143k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
143k
     abfd, src->u.syment.n_sclass,
5027
143k
     dst->symbol.section->name, dst->symbol.name);
5028
143k
        ret = false;
5029
        /* Fall through.  */
5030
143k
      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
143k
        dst->symbol.flags = BSF_DEBUGGING;
5034
143k
        dst->symbol.value = (src->u.syment.n_value);
5035
143k
        break;
5036
222k
      }
5037
5038
222k
    dst->native = src;
5039
222k
    dst->symbol.udata.i = 0;
5040
222k
    dst->lineno = NULL;
5041
5042
222k
    this_index += (src->u.syment.n_numaux) + 1;
5043
222k
    dst++;
5044
222k
    number_of_symbols++;
5045
222k
  }
5046
910
    }
5047
5048
910
  obj_symbols (abfd) = cached_area;
5049
910
  obj_raw_syments (abfd) = native_symbols;
5050
5051
910
  abfd->symcount = number_of_symbols;
5052
910
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
910
  {
5055
910
    asection *p;
5056
5057
910
    p = abfd->sections;
5058
4.78k
    while (p)
5059
4.62k
      {
5060
4.62k
  if (! coff_slurp_line_table (abfd, p))
5061
744
    return false;
5062
3.87k
  p = p->next;
5063
3.87k
      }
5064
910
  }
5065
5066
166
  return ret;
5067
910
}
pe-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
2.64k
{
4696
2.64k
  combined_entry_type *native_symbols;
4697
2.64k
  coff_symbol_type *cached_area;
4698
2.64k
  unsigned int *table_ptr;
4699
2.64k
  unsigned int number_of_symbols = 0;
4700
2.64k
  bool ret = true;
4701
2.64k
  size_t amt;
4702
4703
2.64k
  if (obj_symbols (abfd))
4704
876
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.76k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
1.11k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
650
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
650
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
650
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
650
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
650
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
650
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
650
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
650
  if (table_ptr == NULL)
4729
0
    return false;
4730
650
  else
4731
650
    {
4732
650
      coff_symbol_type *dst = cached_area;
4733
650
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
650
      unsigned int this_index = 0;
4735
4736
128k
      while (this_index < last_native_index)
4737
128k
  {
4738
128k
    combined_entry_type *src = native_symbols + this_index;
4739
128k
    table_ptr[this_index] = number_of_symbols;
4740
4741
128k
    dst->symbol.the_bfd = abfd;
4742
128k
    BFD_ASSERT (src->is_sym);
4743
128k
    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
128k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
128k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
128k
                 src->u.syment.n_scnum);
4748
128k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
128k
    dst->symbol.value = 0;
4751
128k
    dst->done_lineno = false;
4752
4753
128k
    switch (src->u.syment.n_sclass)
4754
128k
      {
4755
1.14k
      case C_EXT:
4756
1.31k
      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.31k
#ifdef C_SYSTEM
4768
1.46k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.46k
#endif
4770
1.46k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.47k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.67k
      case C_NT_WEAK:
4775
2.67k
#endif
4776
2.67k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.67k
    {
4778
2.34k
    case COFF_SYMBOL_GLOBAL:
4779
2.34k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2.34k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2.34k
      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.34k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
58
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.34k
      break;
4793
4794
236
    case COFF_SYMBOL_COMMON:
4795
236
      dst->symbol.section = bfd_com_section_ptr;
4796
236
      dst->symbol.value = src->u.syment.n_value;
4797
236
      break;
4798
4799
88
    case COFF_SYMBOL_UNDEFINED:
4800
88
      dst->symbol.section = bfd_und_section_ptr;
4801
88
      dst->symbol.value = 0;
4802
88
      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.67k
    }
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.67k
#ifdef COFF_WITH_PE
4831
2.67k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1.19k
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.67k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.67k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.67k
#endif
4838
2.67k
        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.67k
      )
4843
170
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.67k
        break;
4846
4847
1.45k
      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.78k
      case C_LABEL:  /* Label.  */
4858
1.78k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
1
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.78k
        else
4861
1.78k
    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.78k
        if (dst->symbol.section)
4866
1.78k
    {
4867
1.78k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.78k
      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.78k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.78k
        break;
4879
4880
759
      case C_FILE: /* File name.  */
4881
759
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.06k
      case C_MOS:   /* Member of structure.  */
4884
1.41k
      case C_EOS:   /* End of structure.  */
4885
1.67k
      case C_REGPARM: /* Register parameter.  */
4886
2.07k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.30k
      case C_TPDEF: /* Type definition.  */
4889
2.64k
      case C_ARG:
4890
6.48k
      case C_AUTO: /* Automatic variable.  */
4891
6.67k
      case C_FIELD: /* Bit field.  */
4892
7.01k
      case C_ENTAG: /* Enumeration tag.  */
4893
7.41k
      case C_MOE:   /* Member of enumeration.  */
4894
7.83k
      case C_MOU:   /* Member of union.  */
4895
8.50k
      case C_UNTAG: /* Union tag.  */
4896
8.90k
      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.90k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8.90k
        dst->symbol.value = (src->u.syment.n_value);
4915
8.90k
        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
241
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.94k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2.30k
      case C_EFCN: /* Physical end of function.  */
4968
2.30k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
2.30k
        dst->symbol.value = src->u.syment.n_value;
4972
2.30k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
2.30k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
2.30k
      dst->symbol.flags = BSF_DEBUGGING;
4977
2.30k
    }
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.30k
        break;
4988
4989
126
      case C_STATLAB: /* Static load time label.  */
4990
126
        dst->symbol.value = src->u.syment.n_value;
4991
126
        dst->symbol.flags = BSF_GLOBAL;
4992
126
        break;
4993
4994
92.7k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
92.7k
        if (src->u.syment.n_type == 0
4998
92.7k
      && src->u.syment.n_value == 0
4999
92.7k
      && src->u.syment.n_scnum == 0)
5000
50.1k
    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
42.7k
      case C_EXTDEF: /* External definition.  */
5008
42.8k
      case C_ULABEL: /* Undefined label.  */
5009
42.8k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
42.9k
      case C_EXTLAB: /* External load time label.  */
5022
62.1k
      default:
5023
62.1k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
62.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
62.1k
     abfd, src->u.syment.n_sclass,
5027
62.1k
     dst->symbol.section->name, dst->symbol.name);
5028
62.1k
        ret = false;
5029
        /* Fall through.  */
5030
62.2k
      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
62.2k
        dst->symbol.flags = BSF_DEBUGGING;
5034
62.2k
        dst->symbol.value = (src->u.syment.n_value);
5035
62.2k
        break;
5036
128k
      }
5037
5038
128k
    dst->native = src;
5039
128k
    dst->symbol.udata.i = 0;
5040
128k
    dst->lineno = NULL;
5041
5042
128k
    this_index += (src->u.syment.n_numaux) + 1;
5043
128k
    dst++;
5044
128k
    number_of_symbols++;
5045
128k
  }
5046
650
    }
5047
5048
650
  obj_symbols (abfd) = cached_area;
5049
650
  obj_raw_syments (abfd) = native_symbols;
5050
5051
650
  abfd->symcount = number_of_symbols;
5052
650
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
650
  {
5055
650
    asection *p;
5056
5057
650
    p = abfd->sections;
5058
3.33k
    while (p)
5059
3.02k
      {
5060
3.02k
  if (! coff_slurp_line_table (abfd, p))
5061
338
    return false;
5062
2.68k
  p = p->next;
5063
2.68k
      }
5064
650
  }
5065
5066
312
  return ret;
5067
650
}
pei-aarch64.c:coff_slurp_symbol_table
Line
Count
Source
4695
933
{
4696
933
  combined_entry_type *native_symbols;
4697
933
  coff_symbol_type *cached_area;
4698
933
  unsigned int *table_ptr;
4699
933
  unsigned int number_of_symbols = 0;
4700
933
  bool ret = true;
4701
933
  size_t amt;
4702
4703
933
  if (obj_symbols (abfd))
4704
138
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
795
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
307
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
488
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
488
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
488
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
488
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
488
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
488
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
488
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
488
  if (table_ptr == NULL)
4729
0
    return false;
4730
488
  else
4731
488
    {
4732
488
      coff_symbol_type *dst = cached_area;
4733
488
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
488
      unsigned int this_index = 0;
4735
4736
78.0k
      while (this_index < last_native_index)
4737
77.5k
  {
4738
77.5k
    combined_entry_type *src = native_symbols + this_index;
4739
77.5k
    table_ptr[this_index] = number_of_symbols;
4740
4741
77.5k
    dst->symbol.the_bfd = abfd;
4742
77.5k
    BFD_ASSERT (src->is_sym);
4743
77.5k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
77.5k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
77.5k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
77.5k
                 src->u.syment.n_scnum);
4748
77.5k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
77.5k
    dst->symbol.value = 0;
4751
77.5k
    dst->done_lineno = false;
4752
4753
77.5k
    switch (src->u.syment.n_sclass)
4754
77.5k
      {
4755
1.49k
      case C_EXT:
4756
1.59k
      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.59k
#ifdef C_SYSTEM
4768
1.82k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.82k
#endif
4770
1.82k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.84k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.53k
      case C_NT_WEAK:
4775
2.53k
#endif
4776
2.53k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.53k
    {
4778
1.88k
    case COFF_SYMBOL_GLOBAL:
4779
1.88k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.88k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.88k
      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.88k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
80
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.88k
      break;
4793
4794
561
    case COFF_SYMBOL_COMMON:
4795
561
      dst->symbol.section = bfd_com_section_ptr;
4796
561
      dst->symbol.value = src->u.syment.n_value;
4797
561
      break;
4798
4799
90
    case COFF_SYMBOL_UNDEFINED:
4800
90
      dst->symbol.section = bfd_und_section_ptr;
4801
90
      dst->symbol.value = 0;
4802
90
      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.53k
    }
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.53k
#ifdef COFF_WITH_PE
4831
2.53k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
686
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.53k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.53k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.53k
#endif
4838
2.53k
        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.53k
      )
4843
99
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.53k
        break;
4846
4847
942
      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.09k
      case C_LABEL:  /* Label.  */
4858
1.09k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.09k
        else
4861
1.09k
    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.09k
        if (dst->symbol.section)
4866
1.09k
    {
4867
1.09k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.09k
      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.09k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.09k
        break;
4879
4880
484
      case C_FILE: /* File name.  */
4881
484
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
801
      case C_MOS:   /* Member of structure.  */
4884
1.05k
      case C_EOS:   /* End of structure.  */
4885
1.14k
      case C_REGPARM: /* Register parameter.  */
4886
1.33k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.51k
      case C_TPDEF: /* Type definition.  */
4889
1.58k
      case C_ARG:
4890
4.05k
      case C_AUTO: /* Automatic variable.  */
4891
4.20k
      case C_FIELD: /* Bit field.  */
4892
4.79k
      case C_ENTAG: /* Enumeration tag.  */
4893
5.22k
      case C_MOE:   /* Member of enumeration.  */
4894
5.32k
      case C_MOU:   /* Member of union.  */
4895
5.70k
      case C_UNTAG: /* Union tag.  */
4896
6.24k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
6.24k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
6.24k
        dst->symbol.value = (src->u.syment.n_value);
4915
6.24k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
211
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.13k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.48k
      case C_EFCN: /* Physical end of function.  */
4968
1.48k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.48k
        dst->symbol.value = src->u.syment.n_value;
4972
1.48k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.48k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.48k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.48k
    }
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.48k
        break;
4988
4989
155
      case C_STATLAB: /* Static load time label.  */
4990
155
        dst->symbol.value = src->u.syment.n_value;
4991
155
        dst->symbol.flags = BSF_GLOBAL;
4992
155
        break;
4993
4994
53.3k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
53.3k
        if (src->u.syment.n_type == 0
4998
53.3k
      && src->u.syment.n_value == 0
4999
53.3k
      && src->u.syment.n_scnum == 0)
5000
21.8k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
31.6k
      case C_EXTDEF: /* External definition.  */
5008
31.7k
      case C_ULABEL: /* Undefined label.  */
5009
31.8k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
31.9k
      case C_EXTLAB: /* External load time label.  */
5022
44.2k
      default:
5023
44.2k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
44.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
44.2k
     abfd, src->u.syment.n_sclass,
5027
44.2k
     dst->symbol.section->name, dst->symbol.name);
5028
44.2k
        ret = false;
5029
        /* Fall through.  */
5030
44.2k
      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
44.2k
        dst->symbol.flags = BSF_DEBUGGING;
5034
44.2k
        dst->symbol.value = (src->u.syment.n_value);
5035
44.2k
        break;
5036
77.5k
      }
5037
5038
77.5k
    dst->native = src;
5039
77.5k
    dst->symbol.udata.i = 0;
5040
77.5k
    dst->lineno = NULL;
5041
5042
77.5k
    this_index += (src->u.syment.n_numaux) + 1;
5043
77.5k
    dst++;
5044
77.5k
    number_of_symbols++;
5045
77.5k
  }
5046
488
    }
5047
5048
488
  obj_symbols (abfd) = cached_area;
5049
488
  obj_raw_syments (abfd) = native_symbols;
5050
5051
488
  abfd->symcount = number_of_symbols;
5052
488
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
488
  {
5055
488
    asection *p;
5056
5057
488
    p = abfd->sections;
5058
2.45k
    while (p)
5059
2.33k
      {
5060
2.33k
  if (! coff_slurp_line_table (abfd, p))
5061
367
    return false;
5062
1.96k
  p = p->next;
5063
1.96k
      }
5064
488
  }
5065
5066
121
  return ret;
5067
488
}
pei-ia64.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.18k
{
4696
1.18k
  combined_entry_type *native_symbols;
4697
1.18k
  coff_symbol_type *cached_area;
4698
1.18k
  unsigned int *table_ptr;
4699
1.18k
  unsigned int number_of_symbols = 0;
4700
1.18k
  bool ret = true;
4701
1.18k
  size_t amt;
4702
4703
1.18k
  if (obj_symbols (abfd))
4704
150
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.03k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
422
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
617
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
617
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
617
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
617
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
617
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
617
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
617
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
617
  if (table_ptr == NULL)
4729
0
    return false;
4730
617
  else
4731
617
    {
4732
617
      coff_symbol_type *dst = cached_area;
4733
617
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
617
      unsigned int this_index = 0;
4735
4736
74.2k
      while (this_index < last_native_index)
4737
73.6k
  {
4738
73.6k
    combined_entry_type *src = native_symbols + this_index;
4739
73.6k
    table_ptr[this_index] = number_of_symbols;
4740
4741
73.6k
    dst->symbol.the_bfd = abfd;
4742
73.6k
    BFD_ASSERT (src->is_sym);
4743
73.6k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
73.6k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
73.6k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
73.6k
                 src->u.syment.n_scnum);
4748
73.6k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
73.6k
    dst->symbol.value = 0;
4751
73.6k
    dst->done_lineno = false;
4752
4753
73.6k
    switch (src->u.syment.n_sclass)
4754
73.6k
      {
4755
1.56k
      case C_EXT:
4756
1.69k
      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.69k
#ifdef C_SYSTEM
4768
1.74k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.74k
#endif
4770
1.74k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.78k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.67k
      case C_NT_WEAK:
4775
2.67k
#endif
4776
2.67k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.67k
    {
4778
2.31k
    case COFF_SYMBOL_GLOBAL:
4779
2.31k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
2.31k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
2.31k
      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.31k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
113
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.31k
      break;
4793
4794
283
    case COFF_SYMBOL_COMMON:
4795
283
      dst->symbol.section = bfd_com_section_ptr;
4796
283
      dst->symbol.value = src->u.syment.n_value;
4797
283
      break;
4798
4799
80
    case COFF_SYMBOL_UNDEFINED:
4800
80
      dst->symbol.section = bfd_und_section_ptr;
4801
80
      dst->symbol.value = 0;
4802
80
      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.67k
    }
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.67k
#ifdef COFF_WITH_PE
4831
2.67k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
899
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.67k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.67k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.67k
#endif
4838
2.67k
        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.67k
      )
4843
128
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.67k
        break;
4846
4847
1.07k
      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.37k
      case C_LABEL:  /* Label.  */
4858
1.37k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
2
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.37k
        else
4861
1.37k
    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.37k
        if (dst->symbol.section)
4866
1.37k
    {
4867
1.37k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.37k
      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.37k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.37k
        break;
4879
4880
491
      case C_FILE: /* File name.  */
4881
491
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
728
      case C_MOS:   /* Member of structure.  */
4884
1.06k
      case C_EOS:   /* End of structure.  */
4885
1.21k
      case C_REGPARM: /* Register parameter.  */
4886
1.55k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.83k
      case C_TPDEF: /* Type definition.  */
4889
2.01k
      case C_ARG:
4890
6.27k
      case C_AUTO: /* Automatic variable.  */
4891
6.55k
      case C_FIELD: /* Bit field.  */
4892
6.90k
      case C_ENTAG: /* Enumeration tag.  */
4893
7.36k
      case C_MOE:   /* Member of enumeration.  */
4894
7.53k
      case C_MOU:   /* Member of union.  */
4895
8.06k
      case C_UNTAG: /* Union tag.  */
4896
8.54k
      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.54k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8.54k
        dst->symbol.value = (src->u.syment.n_value);
4915
8.54k
        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
216
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.26k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.57k
      case C_EFCN: /* Physical end of function.  */
4968
1.57k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.57k
        dst->symbol.value = src->u.syment.n_value;
4972
1.57k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.56k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.56k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.56k
    }
4978
3
        else
4979
3
    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.57k
        break;
4988
4989
165
      case C_STATLAB: /* Static load time label.  */
4990
165
        dst->symbol.value = src->u.syment.n_value;
4991
165
        dst->symbol.flags = BSF_GLOBAL;
4992
165
        break;
4993
4994
45.5k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
45.5k
        if (src->u.syment.n_type == 0
4998
45.5k
      && src->u.syment.n_value == 0
4999
45.5k
      && src->u.syment.n_scnum == 0)
5000
13.6k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
31.9k
      case C_EXTDEF: /* External definition.  */
5008
32.1k
      case C_ULABEL: /* Undefined label.  */
5009
32.2k
      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
32.2k
      case C_EXTLAB: /* External load time label.  */
5022
45.6k
      default:
5023
45.6k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
45.6k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
45.6k
     abfd, src->u.syment.n_sclass,
5027
45.6k
     dst->symbol.section->name, dst->symbol.name);
5028
45.6k
        ret = false;
5029
        /* Fall through.  */
5030
45.6k
      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
45.6k
        dst->symbol.flags = BSF_DEBUGGING;
5034
45.6k
        dst->symbol.value = (src->u.syment.n_value);
5035
45.6k
        break;
5036
73.6k
      }
5037
5038
73.6k
    dst->native = src;
5039
73.6k
    dst->symbol.udata.i = 0;
5040
73.6k
    dst->lineno = NULL;
5041
5042
73.6k
    this_index += (src->u.syment.n_numaux) + 1;
5043
73.6k
    dst++;
5044
73.6k
    number_of_symbols++;
5045
73.6k
  }
5046
617
    }
5047
5048
617
  obj_symbols (abfd) = cached_area;
5049
617
  obj_raw_syments (abfd) = native_symbols;
5050
5051
617
  abfd->symcount = number_of_symbols;
5052
617
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
617
  {
5055
617
    asection *p;
5056
5057
617
    p = abfd->sections;
5058
1.50k
    while (p)
5059
1.31k
      {
5060
1.31k
  if (! coff_slurp_line_table (abfd, p))
5061
427
    return false;
5062
887
  p = p->next;
5063
887
      }
5064
617
  }
5065
5066
190
  return ret;
5067
617
}
pei-loongarch64.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
219
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
875
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
378
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
497
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
497
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
497
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
497
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
497
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
497
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
497
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
497
  if (table_ptr == NULL)
4729
0
    return false;
4730
497
  else
4731
497
    {
4732
497
      coff_symbol_type *dst = cached_area;
4733
497
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
497
      unsigned int this_index = 0;
4735
4736
101k
      while (this_index < last_native_index)
4737
101k
  {
4738
101k
    combined_entry_type *src = native_symbols + this_index;
4739
101k
    table_ptr[this_index] = number_of_symbols;
4740
4741
101k
    dst->symbol.the_bfd = abfd;
4742
101k
    BFD_ASSERT (src->is_sym);
4743
101k
    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
101k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
101k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
101k
                 src->u.syment.n_scnum);
4748
101k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
101k
    dst->symbol.value = 0;
4751
101k
    dst->done_lineno = false;
4752
4753
101k
    switch (src->u.syment.n_sclass)
4754
101k
      {
4755
1.36k
      case C_EXT:
4756
1.53k
      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.53k
#ifdef C_SYSTEM
4768
1.75k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.75k
#endif
4770
1.75k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
1.76k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
2.29k
      case C_NT_WEAK:
4775
2.29k
#endif
4776
2.29k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.29k
    {
4778
1.61k
    case COFF_SYMBOL_GLOBAL:
4779
1.61k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.61k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.61k
      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.61k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
53
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.61k
      break;
4793
4794
461
    case COFF_SYMBOL_COMMON:
4795
461
      dst->symbol.section = bfd_com_section_ptr;
4796
461
      dst->symbol.value = src->u.syment.n_value;
4797
461
      break;
4798
4799
221
    case COFF_SYMBOL_UNDEFINED:
4800
221
      dst->symbol.section = bfd_und_section_ptr;
4801
221
      dst->symbol.value = 0;
4802
221
      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.29k
    }
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.29k
#ifdef COFF_WITH_PE
4831
2.29k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
530
    dst->symbol.flags |= BSF_WEAK;
4833
4834
2.29k
        if (src->u.syment.n_sclass == C_SECTION
4835
2.29k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
2.29k
#endif
4838
2.29k
        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.29k
      )
4843
169
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.29k
        break;
4846
4847
1.27k
      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.82k
      case C_LABEL:  /* Label.  */
4858
1.82k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.82k
        else
4861
1.82k
    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.82k
        if (dst->symbol.section)
4866
1.82k
    {
4867
1.82k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.82k
      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.82k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.82k
        break;
4879
4880
490
      case C_FILE: /* File name.  */
4881
490
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.11k
      case C_MOS:   /* Member of structure.  */
4884
1.30k
      case C_EOS:   /* End of structure.  */
4885
1.57k
      case C_REGPARM: /* Register parameter.  */
4886
2.01k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.24k
      case C_TPDEF: /* Type definition.  */
4889
2.46k
      case C_ARG:
4890
9.92k
      case C_AUTO: /* Automatic variable.  */
4891
10.5k
      case C_FIELD: /* Bit field.  */
4892
10.8k
      case C_ENTAG: /* Enumeration tag.  */
4893
11.4k
      case C_MOE:   /* Member of enumeration.  */
4894
12.1k
      case C_MOU:   /* Member of union.  */
4895
12.3k
      case C_UNTAG: /* Union tag.  */
4896
13.2k
      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
13.2k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
13.2k
        dst->symbol.value = (src->u.syment.n_value);
4915
13.2k
        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
214
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
988
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.63k
      case C_EFCN: /* Physical end of function.  */
4968
1.63k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.63k
        dst->symbol.value = src->u.syment.n_value;
4972
1.63k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.62k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.62k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.62k
    }
4978
4
        else
4979
4
    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.63k
        break;
4988
4989
120
      case C_STATLAB: /* Static load time label.  */
4990
120
        dst->symbol.value = src->u.syment.n_value;
4991
120
        dst->symbol.flags = BSF_GLOBAL;
4992
120
        break;
4993
4994
65.0k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
65.0k
        if (src->u.syment.n_type == 0
4998
65.0k
      && src->u.syment.n_value == 0
4999
65.0k
      && src->u.syment.n_scnum == 0)
5000
12.3k
    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
52.8k
      case C_EXTDEF: /* External definition.  */
5008
52.9k
      case C_ULABEL: /* Undefined label.  */
5009
53.0k
      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
53.1k
      case C_EXTLAB: /* External load time label.  */
5022
69.5k
      default:
5023
69.5k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
69.5k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
69.5k
     abfd, src->u.syment.n_sclass,
5027
69.5k
     dst->symbol.section->name, dst->symbol.name);
5028
69.5k
        ret = false;
5029
        /* Fall through.  */
5030
69.6k
      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
69.6k
        dst->symbol.flags = BSF_DEBUGGING;
5034
69.6k
        dst->symbol.value = (src->u.syment.n_value);
5035
69.6k
        break;
5036
101k
      }
5037
5038
101k
    dst->native = src;
5039
101k
    dst->symbol.udata.i = 0;
5040
101k
    dst->lineno = NULL;
5041
5042
101k
    this_index += (src->u.syment.n_numaux) + 1;
5043
101k
    dst++;
5044
101k
    number_of_symbols++;
5045
101k
  }
5046
497
    }
5047
5048
497
  obj_symbols (abfd) = cached_area;
5049
497
  obj_raw_syments (abfd) = native_symbols;
5050
5051
497
  abfd->symcount = number_of_symbols;
5052
497
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
497
  {
5055
497
    asection *p;
5056
5057
497
    p = abfd->sections;
5058
1.10k
    while (p)
5059
911
      {
5060
911
  if (! coff_slurp_line_table (abfd, p))
5061
299
    return false;
5062
612
  p = p->next;
5063
612
      }
5064
497
  }
5065
5066
198
  return ret;
5067
497
}
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
1.69k
{
4696
1.69k
  combined_entry_type *native_symbols;
4697
1.69k
  coff_symbol_type *cached_area;
4698
1.69k
  unsigned int *table_ptr;
4699
1.69k
  unsigned int number_of_symbols = 0;
4700
1.69k
  bool ret = true;
4701
1.69k
  size_t amt;
4702
4703
1.69k
  if (obj_symbols (abfd))
4704
215
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.48k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
592
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
892
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
892
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
892
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
892
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
892
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
892
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
892
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
892
  if (table_ptr == NULL)
4729
0
    return false;
4730
892
  else
4731
892
    {
4732
892
      coff_symbol_type *dst = cached_area;
4733
892
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
892
      unsigned int this_index = 0;
4735
4736
294k
      while (this_index < last_native_index)
4737
294k
  {
4738
294k
    combined_entry_type *src = native_symbols + this_index;
4739
294k
    table_ptr[this_index] = number_of_symbols;
4740
4741
294k
    dst->symbol.the_bfd = abfd;
4742
294k
    BFD_ASSERT (src->is_sym);
4743
294k
    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
294k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
294k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
294k
                 src->u.syment.n_scnum);
4748
294k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
294k
    dst->symbol.value = 0;
4751
294k
    dst->done_lineno = false;
4752
4753
294k
    switch (src->u.syment.n_sclass)
4754
294k
      {
4755
5.53k
      case C_EXT:
4756
5.84k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
5.84k
#ifdef RS6000COFF_C
4762
6.24k
      case C_HIDEXT:
4763
6.24k
#ifndef AIX_WEAK_SUPPORT
4764
7.19k
      case C_AIX_WEAKEXT:
4765
7.19k
#endif
4766
7.19k
#endif
4767
7.19k
#ifdef C_SYSTEM
4768
7.50k
      case C_SYSTEM: /* System Wide variable.  */
4769
7.50k
#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.50k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
7.50k
    {
4778
6.02k
    case COFF_SYMBOL_GLOBAL:
4779
6.02k
      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
6.02k
      dst->symbol.value = (src->u.syment.n_value
4786
6.02k
               - dst->symbol.section->vma);
4787
6.02k
#endif
4788
6.02k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
145
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
6.02k
      break;
4793
4794
1.00k
    case COFF_SYMBOL_COMMON:
4795
1.00k
      dst->symbol.section = bfd_com_section_ptr;
4796
1.00k
      dst->symbol.value = src->u.syment.n_value;
4797
1.00k
      break;
4798
4799
102
    case COFF_SYMBOL_UNDEFINED:
4800
102
      dst->symbol.section = bfd_und_section_ptr;
4801
102
      dst->symbol.value = 0;
4802
102
      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
375
    case COFF_SYMBOL_LOCAL:
4810
375
      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
375
      dst->symbol.value = (src->u.syment.n_value
4817
375
               - dst->symbol.section->vma);
4818
375
#endif
4819
375
      if (ISFCN ((src->u.syment.n_type)))
4820
182
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4821
375
      break;
4822
7.50k
    }
4823
4824
7.50k
#ifdef RS6000COFF_C
4825
        /* A symbol with a csect entry should not go at the end.  */
4826
7.50k
        if (src->u.syment.n_numaux > 0)
4827
5.29k
    dst->symbol.flags |= BSF_NOT_AT_END;
4828
7.50k
#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.50k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
7.50k
#ifdef RS6000COFF_C
4840
7.50k
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
7.50k
#endif
4842
7.50k
      )
4843
1.25k
    dst->symbol.flags |= BSF_WEAK;
4844
4845
7.50k
        break;
4846
4847
877
      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
877
#ifdef RS6000COFF_C
4854
2.64k
      case C_DWARF:  /* A label in a dwarf section.  */
4855
3.88k
      case C_INFO:  /* A label in a comment section.  */
4856
3.88k
#endif
4857
4.31k
      case C_LABEL:  /* Label.  */
4858
4.31k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
4.31k
        else
4861
4.31k
    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.31k
        if (dst->symbol.section)
4866
4.31k
    {
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.31k
      dst->symbol.value = (src->u.syment.n_value
4873
4.31k
               - dst->symbol.section->vma);
4874
4.31k
#endif
4875
4.31k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
4.31k
        break;
4879
4880
936
      case C_FILE: /* File name.  */
4881
936
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.47k
      case C_MOS:   /* Member of structure.  */
4884
3.28k
      case C_EOS:   /* End of structure.  */
4885
3.54k
      case C_REGPARM: /* Register parameter.  */
4886
4.68k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
5.52k
      case C_TPDEF: /* Type definition.  */
4889
6.25k
      case C_ARG:
4890
22.2k
      case C_AUTO: /* Automatic variable.  */
4891
23.1k
      case C_FIELD: /* Bit field.  */
4892
23.6k
      case C_ENTAG: /* Enumeration tag.  */
4893
25.1k
      case C_MOE:   /* Member of enumeration.  */
4894
25.7k
      case C_MOU:   /* Member of union.  */
4895
27.8k
      case C_UNTAG: /* Union tag.  */
4896
28.5k
      case C_STRTAG: /* Structure tag.  */
4897
28.5k
#ifdef RS6000COFF_C
4898
29.5k
      case C_GSYM:
4899
30.4k
      case C_LSYM:
4900
30.6k
      case C_PSYM:
4901
31.0k
      case C_RSYM:
4902
32.0k
      case C_RPSYM:
4903
32.2k
      case C_STSYM:
4904
32.3k
      case C_TCSYM:
4905
32.5k
      case C_BCOMM:
4906
32.8k
      case C_ECOML:
4907
33.1k
      case C_ECOMM:
4908
33.3k
      case C_DECL:
4909
33.4k
      case C_ENTRY:
4910
33.7k
      case C_FUN:
4911
34.4k
      case C_ESTAT:
4912
34.4k
#endif
4913
34.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
34.4k
        dst->symbol.value = (src->u.syment.n_value);
4915
34.4k
        break;
4916
4917
0
#ifdef RS6000COFF_C
4918
1.04k
      case C_BINCL: /* Beginning of include file.  */
4919
1.59k
      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
1.59k
        {
4925
1.59k
    asection *sec;
4926
4927
1.59k
    dst->symbol.flags = BSF_DEBUGGING;
4928
121k
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
120k
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
120k
          && ((file_ptr) (sec->line_filepos
4931
74.2k
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
74.2k
        > (file_ptr) src->u.syment.n_value))
4933
361
        break;
4934
1.59k
    if (sec == NULL)
4935
1.23k
      dst->symbol.value = 0;
4936
361
    else
4937
361
      {
4938
361
        dst->symbol.section = sec;
4939
361
        dst->symbol.value = ((src->u.syment.n_value
4940
361
            - sec->line_filepos)
4941
361
           / bfd_coff_linesz (abfd));
4942
361
        src->fix_line = 1;
4943
361
      }
4944
1.59k
        }
4945
1.59k
        break;
4946
4947
167
      case C_BSTAT:
4948
167
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
167
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
151
    dst->symbol.value = 0;
4952
16
        else
4953
16
    {
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
16
      src->u.syment.n_value
4958
16
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
16
      dst->symbol.value = src->u.syment.n_value;
4960
16
      src->fix_value = 1;
4961
16
    }
4962
167
        break;
4963
0
#endif
4964
4965
451
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
2.41k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
3.18k
      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.18k
        dst->symbol.flags = BSF_LOCAL;
4984
3.18k
        dst->symbol.value = (src->u.syment.n_value
4985
3.18k
           - dst->symbol.section->vma);
4986
3.18k
#endif
4987
3.18k
        break;
4988
4989
339
      case C_STATLAB: /* Static load time label.  */
4990
339
        dst->symbol.value = src->u.syment.n_value;
4991
339
        dst->symbol.flags = BSF_GLOBAL;
4992
339
        break;
4993
4994
199k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
199k
        if (src->u.syment.n_type == 0
4998
199k
      && src->u.syment.n_value == 0
4999
199k
      && src->u.syment.n_scnum == 0)
5000
93.2k
    break;
5001
106k
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
106k
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
1
    break;
5005
106k
#endif
5006
        /* Fall through.  */
5007
106k
      case C_EXTDEF: /* External definition.  */
5008
106k
      case C_ULABEL: /* Undefined label.  */
5009
107k
      case C_USTATIC: /* Undefined static.  */
5010
107k
#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
108k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
109k
      case C_ALIAS: /* Duplicate tag.  */
5016
109k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
109k
      case C_EXTLAB: /* External load time label.  */
5022
148k
      default:
5023
148k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
148k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
148k
     abfd, src->u.syment.n_sclass,
5027
148k
     dst->symbol.section->name, dst->symbol.name);
5028
148k
        ret = false;
5029
        /* Fall through.  */
5030
149k
      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
149k
        dst->symbol.flags = BSF_DEBUGGING;
5034
149k
        dst->symbol.value = (src->u.syment.n_value);
5035
149k
        break;
5036
294k
      }
5037
5038
294k
    dst->native = src;
5039
294k
    dst->symbol.udata.i = 0;
5040
294k
    dst->lineno = NULL;
5041
5042
294k
    this_index += (src->u.syment.n_numaux) + 1;
5043
294k
    dst++;
5044
294k
    number_of_symbols++;
5045
294k
  }
5046
892
    }
5047
5048
892
  obj_symbols (abfd) = cached_area;
5049
892
  obj_raw_syments (abfd) = native_symbols;
5050
5051
892
  abfd->symcount = number_of_symbols;
5052
892
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
892
  {
5055
892
    asection *p;
5056
5057
892
    p = abfd->sections;
5058
10.3k
    while (p)
5059
10.0k
      {
5060
10.0k
  if (! coff_slurp_line_table (abfd, p))
5061
547
    return false;
5062
9.45k
  p = p->next;
5063
9.45k
      }
5064
892
  }
5065
5066
345
  return ret;
5067
892
}
coff-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
2.56k
{
4696
2.56k
  combined_entry_type *native_symbols;
4697
2.56k
  coff_symbol_type *cached_area;
4698
2.56k
  unsigned int *table_ptr;
4699
2.56k
  unsigned int number_of_symbols = 0;
4700
2.56k
  bool ret = true;
4701
2.56k
  size_t amt;
4702
4703
2.56k
  if (obj_symbols (abfd))
4704
962
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.60k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
925
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
679
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
679
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
679
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
679
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
679
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
679
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
679
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
679
  if (table_ptr == NULL)
4729
0
    return false;
4730
679
  else
4731
679
    {
4732
679
      coff_symbol_type *dst = cached_area;
4733
679
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
679
      unsigned int this_index = 0;
4735
4736
95.9k
      while (this_index < last_native_index)
4737
95.2k
  {
4738
95.2k
    combined_entry_type *src = native_symbols + this_index;
4739
95.2k
    table_ptr[this_index] = number_of_symbols;
4740
4741
95.2k
    dst->symbol.the_bfd = abfd;
4742
95.2k
    BFD_ASSERT (src->is_sym);
4743
95.2k
    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
95.2k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
95.2k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
95.2k
                 src->u.syment.n_scnum);
4748
95.2k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
95.2k
    dst->symbol.value = 0;
4751
95.2k
    dst->done_lineno = false;
4752
4753
95.2k
    switch (src->u.syment.n_sclass)
4754
95.2k
      {
4755
1.77k
      case C_EXT:
4756
1.93k
      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.93k
#ifdef C_SYSTEM
4768
2.15k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.15k
#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
2.15k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.15k
    {
4778
1.79k
    case COFF_SYMBOL_GLOBAL:
4779
1.79k
      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.79k
      dst->symbol.value = (src->u.syment.n_value
4786
1.79k
               - dst->symbol.section->vma);
4787
1.79k
#endif
4788
1.79k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
22
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.79k
      break;
4793
4794
242
    case COFF_SYMBOL_COMMON:
4795
242
      dst->symbol.section = bfd_com_section_ptr;
4796
242
      dst->symbol.value = src->u.syment.n_value;
4797
242
      break;
4798
4799
115
    case COFF_SYMBOL_UNDEFINED:
4800
115
      dst->symbol.section = bfd_und_section_ptr;
4801
115
      dst->symbol.value = 0;
4802
115
      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
2.15k
    }
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
2.15k
        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.15k
      )
4843
164
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.15k
        break;
4846
4847
847
      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.78k
      case C_LABEL:  /* Label.  */
4858
1.78k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
1
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.78k
        else
4861
1.78k
    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.78k
        if (dst->symbol.section)
4866
1.78k
    {
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.78k
      dst->symbol.value = (src->u.syment.n_value
4873
1.78k
               - dst->symbol.section->vma);
4874
1.78k
#endif
4875
1.78k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.78k
        break;
4879
4880
574
      case C_FILE: /* File name.  */
4881
574
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
687
      case C_MOS:   /* Member of structure.  */
4884
951
      case C_EOS:   /* End of structure.  */
4885
1.06k
      case C_REGPARM: /* Register parameter.  */
4886
1.31k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.70k
      case C_TPDEF: /* Type definition.  */
4889
2.07k
      case C_ARG:
4890
6.35k
      case C_AUTO: /* Automatic variable.  */
4891
6.58k
      case C_FIELD: /* Bit field.  */
4892
6.73k
      case C_ENTAG: /* Enumeration tag.  */
4893
7.24k
      case C_MOE:   /* Member of enumeration.  */
4894
7.37k
      case C_MOU:   /* Member of union.  */
4895
7.58k
      case C_UNTAG: /* Union tag.  */
4896
8.08k
      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.08k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
8.08k
        dst->symbol.value = (src->u.syment.n_value);
4915
8.08k
        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
209
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.46k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.90k
      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.90k
        dst->symbol.flags = BSF_LOCAL;
4984
1.90k
        dst->symbol.value = (src->u.syment.n_value
4985
1.90k
           - dst->symbol.section->vma);
4986
1.90k
#endif
4987
1.90k
        break;
4988
4989
124
      case C_STATLAB: /* Static load time label.  */
4990
124
        dst->symbol.value = src->u.syment.n_value;
4991
124
        dst->symbol.flags = BSF_GLOBAL;
4992
124
        break;
4993
4994
64.6k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
64.6k
        if (src->u.syment.n_type == 0
4998
64.6k
      && src->u.syment.n_value == 0
4999
64.6k
      && src->u.syment.n_scnum == 0)
5000
21.7k
    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
42.9k
      case C_EXTDEF: /* External definition.  */
5008
43.0k
      case C_ULABEL: /* Undefined label.  */
5009
43.0k
      case C_USTATIC: /* Undefined static.  */
5010
43.0k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
43.6k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
44.4k
      case C_ALIAS: /* Duplicate tag.  */
5016
44.4k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
44.4k
      case C_EXTLAB: /* External load time label.  */
5022
59.4k
      default:
5023
59.4k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
59.4k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
59.4k
     abfd, src->u.syment.n_sclass,
5027
59.4k
     dst->symbol.section->name, dst->symbol.name);
5028
59.4k
        ret = false;
5029
        /* Fall through.  */
5030
59.4k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
59.4k
        dst->symbol.flags = BSF_DEBUGGING;
5034
59.4k
        dst->symbol.value = (src->u.syment.n_value);
5035
59.4k
        break;
5036
95.2k
      }
5037
5038
95.2k
    dst->native = src;
5039
95.2k
    dst->symbol.udata.i = 0;
5040
95.2k
    dst->lineno = NULL;
5041
5042
95.2k
    this_index += (src->u.syment.n_numaux) + 1;
5043
95.2k
    dst++;
5044
95.2k
    number_of_symbols++;
5045
95.2k
  }
5046
679
    }
5047
5048
679
  obj_symbols (abfd) = cached_area;
5049
679
  obj_raw_syments (abfd) = native_symbols;
5050
5051
679
  abfd->symcount = number_of_symbols;
5052
679
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
679
  {
5055
679
    asection *p;
5056
5057
679
    p = abfd->sections;
5058
4.50k
    while (p)
5059
4.29k
      {
5060
4.29k
  if (! coff_slurp_line_table (abfd, p))
5061
468
    return false;
5062
3.82k
  p = p->next;
5063
3.82k
      }
5064
679
  }
5065
5066
211
  return ret;
5067
679
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_symbol_table
coff-tic30.c:coff_slurp_symbol_table
Line
Count
Source
4695
14.0k
{
4696
14.0k
  combined_entry_type *native_symbols;
4697
14.0k
  coff_symbol_type *cached_area;
4698
14.0k
  unsigned int *table_ptr;
4699
14.0k
  unsigned int number_of_symbols = 0;
4700
14.0k
  bool ret = true;
4701
14.0k
  size_t amt;
4702
4703
14.0k
  if (obj_symbols (abfd))
4704
10.1k
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
3.86k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
2.87k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
986
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
986
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
986
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
986
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
986
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
986
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
986
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
986
  if (table_ptr == NULL)
4729
0
    return false;
4730
986
  else
4731
986
    {
4732
986
      coff_symbol_type *dst = cached_area;
4733
986
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
986
      unsigned int this_index = 0;
4735
4736
74.8k
      while (this_index < last_native_index)
4737
73.8k
  {
4738
73.8k
    combined_entry_type *src = native_symbols + this_index;
4739
73.8k
    table_ptr[this_index] = number_of_symbols;
4740
4741
73.8k
    dst->symbol.the_bfd = abfd;
4742
73.8k
    BFD_ASSERT (src->is_sym);
4743
73.8k
    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
73.8k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
73.8k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
73.8k
                 src->u.syment.n_scnum);
4748
73.8k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
73.8k
    dst->symbol.value = 0;
4751
73.8k
    dst->done_lineno = false;
4752
4753
73.8k
    switch (src->u.syment.n_sclass)
4754
73.8k
      {
4755
1.10k
      case C_EXT:
4756
1.30k
      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.30k
#ifdef C_SYSTEM
4768
1.42k
      case C_SYSTEM: /* System Wide variable.  */
4769
1.42k
#endif
4770
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
      case C_NT_WEAK:
4775
#endif
4776
1.42k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.42k
    {
4778
1.19k
    case COFF_SYMBOL_GLOBAL:
4779
1.19k
      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.19k
      dst->symbol.value = (src->u.syment.n_value
4786
1.19k
               - dst->symbol.section->vma);
4787
1.19k
#endif
4788
1.19k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
51
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.19k
      break;
4793
4794
180
    case COFF_SYMBOL_COMMON:
4795
180
      dst->symbol.section = bfd_com_section_ptr;
4796
180
      dst->symbol.value = src->u.syment.n_value;
4797
180
      break;
4798
4799
56
    case COFF_SYMBOL_UNDEFINED:
4800
56
      dst->symbol.section = bfd_und_section_ptr;
4801
56
      dst->symbol.value = 0;
4802
56
      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
1.42k
    }
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
1.42k
        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.42k
      )
4843
200
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.42k
        break;
4846
4847
656
      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
898
      case C_LABEL:  /* Label.  */
4858
898
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
898
        else
4861
898
    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
898
        if (dst->symbol.section)
4866
898
    {
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
898
      dst->symbol.value = (src->u.syment.n_value
4873
898
               - dst->symbol.section->vma);
4874
898
#endif
4875
898
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
898
        break;
4879
4880
266
      case C_FILE: /* File name.  */
4881
266
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
467
      case C_MOS:   /* Member of structure.  */
4884
574
      case C_EOS:   /* End of structure.  */
4885
716
      case C_REGPARM: /* Register parameter.  */
4886
1.86k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.02k
      case C_TPDEF: /* Type definition.  */
4889
2.19k
      case C_ARG:
4890
5.84k
      case C_AUTO: /* Automatic variable.  */
4891
6.11k
      case C_FIELD: /* Bit field.  */
4892
6.23k
      case C_ENTAG: /* Enumeration tag.  */
4893
6.73k
      case C_MOE:   /* Member of enumeration.  */
4894
7.05k
      case C_MOU:   /* Member of union.  */
4895
7.25k
      case C_UNTAG: /* Union tag.  */
4896
7.63k
      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.63k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7.63k
        dst->symbol.value = (src->u.syment.n_value);
4915
7.63k
        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
142
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
717
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.02k
      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.02k
        dst->symbol.flags = BSF_LOCAL;
4984
1.02k
        dst->symbol.value = (src->u.syment.n_value
4985
1.02k
           - dst->symbol.section->vma);
4986
1.02k
#endif
4987
1.02k
        break;
4988
4989
290
      case C_STATLAB: /* Static load time label.  */
4990
290
        dst->symbol.value = src->u.syment.n_value;
4991
290
        dst->symbol.flags = BSF_GLOBAL;
4992
290
        break;
4993
4994
50.9k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
50.9k
        if (src->u.syment.n_type == 0
4998
50.9k
      && src->u.syment.n_value == 0
4999
50.9k
      && src->u.syment.n_scnum == 0)
5000
22.9k
    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
28.1k
      case C_EXTDEF: /* External definition.  */
5008
28.2k
      case C_ULABEL: /* Undefined label.  */
5009
28.2k
      case C_USTATIC: /* Undefined static.  */
5010
28.2k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
28.5k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
28.7k
      case C_ALIAS: /* Duplicate tag.  */
5016
28.7k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
28.8k
      case C_EXTLAB: /* External load time label.  */
5022
39.5k
      default:
5023
39.5k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
39.5k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
39.5k
     abfd, src->u.syment.n_sclass,
5027
39.5k
     dst->symbol.section->name, dst->symbol.name);
5028
39.5k
        ret = false;
5029
        /* Fall through.  */
5030
39.5k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
39.5k
        dst->symbol.flags = BSF_DEBUGGING;
5034
39.5k
        dst->symbol.value = (src->u.syment.n_value);
5035
39.5k
        break;
5036
73.8k
      }
5037
5038
73.8k
    dst->native = src;
5039
73.8k
    dst->symbol.udata.i = 0;
5040
73.8k
    dst->lineno = NULL;
5041
5042
73.8k
    this_index += (src->u.syment.n_numaux) + 1;
5043
73.8k
    dst++;
5044
73.8k
    number_of_symbols++;
5045
73.8k
  }
5046
986
    }
5047
5048
986
  obj_symbols (abfd) = cached_area;
5049
986
  obj_raw_syments (abfd) = native_symbols;
5050
5051
986
  abfd->symcount = number_of_symbols;
5052
986
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
986
  {
5055
986
    asection *p;
5056
5057
986
    p = abfd->sections;
5058
4.76k
    while (p)
5059
4.49k
      {
5060
4.49k
  if (! coff_slurp_line_table (abfd, p))
5061
724
    return false;
5062
3.77k
  p = p->next;
5063
3.77k
      }
5064
986
  }
5065
5066
262
  return ret;
5067
986
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_symbol_table
coff-tic54x.c:coff_slurp_symbol_table
Line
Count
Source
4695
3.37k
{
4696
3.37k
  combined_entry_type *native_symbols;
4697
3.37k
  coff_symbol_type *cached_area;
4698
3.37k
  unsigned int *table_ptr;
4699
3.37k
  unsigned int number_of_symbols = 0;
4700
3.37k
  bool ret = true;
4701
3.37k
  size_t amt;
4702
4703
3.37k
  if (obj_symbols (abfd))
4704
764
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
2.61k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
1.67k
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
937
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
937
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
937
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
937
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
937
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
937
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
937
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
937
  if (table_ptr == NULL)
4729
0
    return false;
4730
937
  else
4731
937
    {
4732
937
      coff_symbol_type *dst = cached_area;
4733
937
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
937
      unsigned int this_index = 0;
4735
4736
124k
      while (this_index < last_native_index)
4737
123k
  {
4738
123k
    combined_entry_type *src = native_symbols + this_index;
4739
123k
    table_ptr[this_index] = number_of_symbols;
4740
4741
123k
    dst->symbol.the_bfd = abfd;
4742
123k
    BFD_ASSERT (src->is_sym);
4743
123k
    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
123k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
123k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
123k
                 src->u.syment.n_scnum);
4748
123k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
123k
    dst->symbol.value = 0;
4751
123k
    dst->done_lineno = false;
4752
4753
123k
    switch (src->u.syment.n_sclass)
4754
123k
      {
4755
3.26k
      case C_EXT:
4756
3.62k
      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.62k
#ifdef C_SYSTEM
4768
3.97k
      case C_SYSTEM: /* System Wide variable.  */
4769
3.97k
#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.97k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
3.97k
    {
4778
3.24k
    case COFF_SYMBOL_GLOBAL:
4779
3.24k
      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.24k
      dst->symbol.value = (src->u.syment.n_value
4786
3.24k
               - dst->symbol.section->vma);
4787
3.24k
#endif
4788
3.24k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
44
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
3.24k
      break;
4793
4794
540
    case COFF_SYMBOL_COMMON:
4795
540
      dst->symbol.section = bfd_com_section_ptr;
4796
540
      dst->symbol.value = src->u.syment.n_value;
4797
540
      break;
4798
4799
184
    case COFF_SYMBOL_UNDEFINED:
4800
184
      dst->symbol.section = bfd_und_section_ptr;
4801
184
      dst->symbol.value = 0;
4802
184
      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.97k
    }
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
3.97k
        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.97k
      )
4843
356
    dst->symbol.flags |= BSF_WEAK;
4844
4845
3.97k
        break;
4846
4847
1.58k
      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.90k
      case C_LABEL:  /* Label.  */
4858
2.90k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
2.90k
        else
4861
2.90k
    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.90k
        if (dst->symbol.section)
4866
2.90k
    {
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
2.90k
      dst->symbol.value = (src->u.syment.n_value
4873
2.90k
               - dst->symbol.section->vma);
4874
2.90k
#endif
4875
2.90k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
2.90k
        break;
4879
4880
658
      case C_FILE: /* File name.  */
4881
658
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.15k
      case C_MOS:   /* Member of structure.  */
4884
1.38k
      case C_EOS:   /* End of structure.  */
4885
1.62k
      case C_REGPARM: /* Register parameter.  */
4886
2.40k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.77k
      case C_TPDEF: /* Type definition.  */
4889
3.55k
      case C_ARG:
4890
9.00k
      case C_AUTO: /* Automatic variable.  */
4891
9.41k
      case C_FIELD: /* Bit field.  */
4892
9.74k
      case C_ENTAG: /* Enumeration tag.  */
4893
10.7k
      case C_MOE:   /* Member of enumeration.  */
4894
11.5k
      case C_MOU:   /* Member of union.  */
4895
13.0k
      case C_UNTAG: /* Union tag.  */
4896
13.6k
      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
13.6k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
13.6k
        dst->symbol.value = (src->u.syment.n_value);
4915
13.6k
        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
223
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.24k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2.03k
      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.03k
        dst->symbol.flags = BSF_LOCAL;
4984
2.03k
        dst->symbol.value = (src->u.syment.n_value
4985
2.03k
           - dst->symbol.section->vma);
4986
2.03k
#endif
4987
2.03k
        break;
4988
4989
209
      case C_STATLAB: /* Static load time label.  */
4990
209
        dst->symbol.value = src->u.syment.n_value;
4991
209
        dst->symbol.flags = BSF_GLOBAL;
4992
209
        break;
4993
4994
77.6k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
77.6k
        if (src->u.syment.n_type == 0
4998
77.6k
      && src->u.syment.n_value == 0
4999
77.6k
      && src->u.syment.n_scnum == 0)
5000
26.3k
    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
51.5k
      case C_EXTDEF: /* External definition.  */
5008
51.7k
      case C_ULABEL: /* Undefined label.  */
5009
51.8k
      case C_USTATIC: /* Undefined static.  */
5010
51.8k
#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
52.2k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
52.8k
      case C_ALIAS: /* Duplicate tag.  */
5016
52.8k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
52.8k
#ifdef TICOFF
5019
52.9k
      case C_UEXT: /* Tentative external definition.  */
5020
52.9k
#endif
5021
53.0k
      case C_EXTLAB: /* External load time label.  */
5022
74.2k
      default:
5023
74.2k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
74.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
74.2k
     abfd, src->u.syment.n_sclass,
5027
74.2k
     dst->symbol.section->name, dst->symbol.name);
5028
74.2k
        ret = false;
5029
        /* Fall through.  */
5030
74.4k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
74.4k
        dst->symbol.flags = BSF_DEBUGGING;
5034
74.4k
        dst->symbol.value = (src->u.syment.n_value);
5035
74.4k
        break;
5036
123k
      }
5037
5038
123k
    dst->native = src;
5039
123k
    dst->symbol.udata.i = 0;
5040
123k
    dst->lineno = NULL;
5041
5042
123k
    this_index += (src->u.syment.n_numaux) + 1;
5043
123k
    dst++;
5044
123k
    number_of_symbols++;
5045
123k
  }
5046
937
    }
5047
5048
937
  obj_symbols (abfd) = cached_area;
5049
937
  obj_raw_syments (abfd) = native_symbols;
5050
5051
937
  abfd->symcount = number_of_symbols;
5052
937
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
937
  {
5055
937
    asection *p;
5056
5057
937
    p = abfd->sections;
5058
4.70k
    while (p)
5059
4.47k
      {
5060
4.47k
  if (! coff_slurp_line_table (abfd, p))
5061
711
    return false;
5062
3.76k
  p = p->next;
5063
3.76k
      }
5064
937
  }
5065
5066
226
  return ret;
5067
937
}
coff-z80.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.62k
{
4696
1.62k
  combined_entry_type *native_symbols;
4697
1.62k
  coff_symbol_type *cached_area;
4698
1.62k
  unsigned int *table_ptr;
4699
1.62k
  unsigned int number_of_symbols = 0;
4700
1.62k
  bool ret = true;
4701
1.62k
  size_t amt;
4702
4703
1.62k
  if (obj_symbols (abfd))
4704
439
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.18k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
476
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
711
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
711
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
711
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
711
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
711
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
711
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
711
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
711
  if (table_ptr == NULL)
4729
0
    return false;
4730
711
  else
4731
711
    {
4732
711
      coff_symbol_type *dst = cached_area;
4733
711
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
711
      unsigned int this_index = 0;
4735
4736
72.8k
      while (this_index < last_native_index)
4737
72.1k
  {
4738
72.1k
    combined_entry_type *src = native_symbols + this_index;
4739
72.1k
    table_ptr[this_index] = number_of_symbols;
4740
4741
72.1k
    dst->symbol.the_bfd = abfd;
4742
72.1k
    BFD_ASSERT (src->is_sym);
4743
72.1k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
72.1k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
72.1k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
72.1k
                 src->u.syment.n_scnum);
4748
72.1k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
72.1k
    dst->symbol.value = 0;
4751
72.1k
    dst->done_lineno = false;
4752
4753
72.1k
    switch (src->u.syment.n_sclass)
4754
72.1k
      {
4755
2.22k
      case C_EXT:
4756
2.39k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.39k
#ifdef C_SYSTEM
4768
2.51k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.51k
#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
2.51k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.51k
    {
4778
2.20k
    case COFF_SYMBOL_GLOBAL:
4779
2.20k
      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.20k
      dst->symbol.value = (src->u.syment.n_value
4786
2.20k
               - dst->symbol.section->vma);
4787
2.20k
#endif
4788
2.20k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
150
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
2.20k
      break;
4793
4794
201
    case COFF_SYMBOL_COMMON:
4795
201
      dst->symbol.section = bfd_com_section_ptr;
4796
201
      dst->symbol.value = src->u.syment.n_value;
4797
201
      break;
4798
4799
114
    case COFF_SYMBOL_UNDEFINED:
4800
114
      dst->symbol.section = bfd_und_section_ptr;
4801
114
      dst->symbol.value = 0;
4802
114
      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
2.51k
    }
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
2.51k
        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.51k
      )
4843
172
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.51k
        break;
4846
4847
869
      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.47k
      case C_LABEL:  /* Label.  */
4858
1.47k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.47k
        else
4861
1.47k
    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.47k
        if (dst->symbol.section)
4866
1.47k
    {
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.47k
      dst->symbol.value = (src->u.syment.n_value
4873
1.47k
               - dst->symbol.section->vma);
4874
1.47k
#endif
4875
1.47k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.47k
        break;
4879
4880
276
      case C_FILE: /* File name.  */
4881
276
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
778
      case C_MOS:   /* Member of structure.  */
4884
898
      case C_EOS:   /* End of structure.  */
4885
1.20k
      case C_REGPARM: /* Register parameter.  */
4886
1.54k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.07k
      case C_TPDEF: /* Type definition.  */
4889
2.38k
      case C_ARG:
4890
5.48k
      case C_AUTO: /* Automatic variable.  */
4891
5.77k
      case C_FIELD: /* Bit field.  */
4892
6.03k
      case C_ENTAG: /* Enumeration tag.  */
4893
6.78k
      case C_MOE:   /* Member of enumeration.  */
4894
6.96k
      case C_MOU:   /* Member of union.  */
4895
7.39k
      case C_UNTAG: /* Union tag.  */
4896
7.89k
      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.89k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
7.89k
        dst->symbol.value = (src->u.syment.n_value);
4915
7.89k
        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
113
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
546
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
927
      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
927
        dst->symbol.flags = BSF_LOCAL;
4984
927
        dst->symbol.value = (src->u.syment.n_value
4985
927
           - dst->symbol.section->vma);
4986
927
#endif
4987
927
        break;
4988
4989
278
      case C_STATLAB: /* Static load time label.  */
4990
278
        dst->symbol.value = src->u.syment.n_value;
4991
278
        dst->symbol.flags = BSF_GLOBAL;
4992
278
        break;
4993
4994
48.5k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
48.5k
        if (src->u.syment.n_type == 0
4998
48.5k
      && src->u.syment.n_value == 0
4999
48.5k
      && src->u.syment.n_scnum == 0)
5000
21.7k
    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
27.0k
      case C_EXTDEF: /* External definition.  */
5008
27.0k
      case C_ULABEL: /* Undefined label.  */
5009
27.2k
      case C_USTATIC: /* Undefined static.  */
5010
27.2k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
27.3k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
27.6k
      case C_ALIAS: /* Duplicate tag.  */
5016
27.6k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
27.7k
      case C_EXTLAB: /* External load time label.  */
5022
37.2k
      default:
5023
37.2k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
37.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
37.2k
     abfd, src->u.syment.n_sclass,
5027
37.2k
     dst->symbol.section->name, dst->symbol.name);
5028
37.2k
        ret = false;
5029
        /* Fall through.  */
5030
37.3k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
37.3k
        dst->symbol.flags = BSF_DEBUGGING;
5034
37.3k
        dst->symbol.value = (src->u.syment.n_value);
5035
37.3k
        break;
5036
72.1k
      }
5037
5038
72.1k
    dst->native = src;
5039
72.1k
    dst->symbol.udata.i = 0;
5040
72.1k
    dst->lineno = NULL;
5041
5042
72.1k
    this_index += (src->u.syment.n_numaux) + 1;
5043
72.1k
    dst++;
5044
72.1k
    number_of_symbols++;
5045
72.1k
  }
5046
711
    }
5047
5048
711
  obj_symbols (abfd) = cached_area;
5049
711
  obj_raw_syments (abfd) = native_symbols;
5050
5051
711
  abfd->symcount = number_of_symbols;
5052
711
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
711
  {
5055
711
    asection *p;
5056
5057
711
    p = abfd->sections;
5058
2.56k
    while (p)
5059
2.34k
      {
5060
2.34k
  if (! coff_slurp_line_table (abfd, p))
5061
485
    return false;
5062
1.85k
  p = p->next;
5063
1.85k
      }
5064
711
  }
5065
5066
226
  return ret;
5067
711
}
coff-z8k.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.65k
{
4696
1.65k
  combined_entry_type *native_symbols;
4697
1.65k
  coff_symbol_type *cached_area;
4698
1.65k
  unsigned int *table_ptr;
4699
1.65k
  unsigned int number_of_symbols = 0;
4700
1.65k
  bool ret = true;
4701
1.65k
  size_t amt;
4702
4703
1.65k
  if (obj_symbols (abfd))
4704
440
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
1.21k
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
574
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
639
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
639
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
639
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
639
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
639
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
639
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
639
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
639
  if (table_ptr == NULL)
4729
0
    return false;
4730
639
  else
4731
639
    {
4732
639
      coff_symbol_type *dst = cached_area;
4733
639
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
639
      unsigned int this_index = 0;
4735
4736
104k
      while (this_index < last_native_index)
4737
103k
  {
4738
103k
    combined_entry_type *src = native_symbols + this_index;
4739
103k
    table_ptr[this_index] = number_of_symbols;
4740
4741
103k
    dst->symbol.the_bfd = abfd;
4742
103k
    BFD_ASSERT (src->is_sym);
4743
103k
    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
103k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
103k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
103k
                 src->u.syment.n_scnum);
4748
103k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
103k
    dst->symbol.value = 0;
4751
103k
    dst->done_lineno = false;
4752
4753
103k
    switch (src->u.syment.n_sclass)
4754
103k
      {
4755
2.11k
      case C_EXT:
4756
2.30k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.30k
#ifdef C_SYSTEM
4768
2.45k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.45k
#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
2.45k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
2.45k
    {
4778
1.90k
    case COFF_SYMBOL_GLOBAL:
4779
1.90k
      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.90k
      dst->symbol.value = (src->u.syment.n_value
4786
1.90k
               - dst->symbol.section->vma);
4787
1.90k
#endif
4788
1.90k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
28
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.90k
      break;
4793
4794
477
    case COFF_SYMBOL_COMMON:
4795
477
      dst->symbol.section = bfd_com_section_ptr;
4796
477
      dst->symbol.value = src->u.syment.n_value;
4797
477
      break;
4798
4799
71
    case COFF_SYMBOL_UNDEFINED:
4800
71
      dst->symbol.section = bfd_und_section_ptr;
4801
71
      dst->symbol.value = 0;
4802
71
      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
2.45k
    }
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
2.45k
        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.45k
      )
4843
189
    dst->symbol.flags |= BSF_WEAK;
4844
4845
2.45k
        break;
4846
4847
656
      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
861
      case C_LABEL:  /* Label.  */
4858
861
        if (src->u.syment.n_scnum == N_DEBUG)
4859
1
    dst->symbol.flags = BSF_DEBUGGING;
4860
860
        else
4861
860
    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
861
        if (dst->symbol.section)
4866
861
    {
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
861
      dst->symbol.value = (src->u.syment.n_value
4873
861
               - dst->symbol.section->vma);
4874
861
#endif
4875
861
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
861
        break;
4879
4880
362
      case C_FILE: /* File name.  */
4881
362
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
625
      case C_MOS:   /* Member of structure.  */
4884
863
      case C_EOS:   /* End of structure.  */
4885
1.03k
      case C_REGPARM: /* Register parameter.  */
4886
1.86k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.31k
      case C_TPDEF: /* Type definition.  */
4889
2.68k
      case C_ARG:
4890
11.7k
      case C_AUTO: /* Automatic variable.  */
4891
11.8k
      case C_FIELD: /* Bit field.  */
4892
12.0k
      case C_ENTAG: /* Enumeration tag.  */
4893
12.7k
      case C_MOE:   /* Member of enumeration.  */
4894
13.0k
      case C_MOU:   /* Member of union.  */
4895
13.3k
      case C_UNTAG: /* Union tag.  */
4896
13.7k
      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
13.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
13.7k
        dst->symbol.value = (src->u.syment.n_value);
4915
13.7k
        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
193
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.01k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.45k
      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.45k
        dst->symbol.flags = BSF_LOCAL;
4984
1.45k
        dst->symbol.value = (src->u.syment.n_value
4985
1.45k
           - dst->symbol.section->vma);
4986
1.45k
#endif
4987
1.45k
        break;
4988
4989
90
      case C_STATLAB: /* Static load time label.  */
4990
90
        dst->symbol.value = src->u.syment.n_value;
4991
90
        dst->symbol.flags = BSF_GLOBAL;
4992
90
        break;
4993
4994
64.2k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
64.2k
        if (src->u.syment.n_type == 0
4998
64.2k
      && src->u.syment.n_value == 0
4999
64.2k
      && src->u.syment.n_scnum == 0)
5000
8.49k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
55.8k
      case C_EXTDEF: /* External definition.  */
5008
56.0k
      case C_ULABEL: /* Undefined label.  */
5009
56.0k
      case C_USTATIC: /* Undefined static.  */
5010
56.0k
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
56.4k
      case C_LINE: /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
56.9k
      case C_ALIAS: /* Duplicate tag.  */
5016
56.9k
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
56.9k
      case C_EXTLAB: /* External load time label.  */
5022
76.2k
      default:
5023
76.2k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
76.2k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
76.2k
     abfd, src->u.syment.n_sclass,
5027
76.2k
     dst->symbol.section->name, dst->symbol.name);
5028
76.2k
        ret = false;
5029
        /* Fall through.  */
5030
76.3k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
76.3k
        dst->symbol.flags = BSF_DEBUGGING;
5034
76.3k
        dst->symbol.value = (src->u.syment.n_value);
5035
76.3k
        break;
5036
103k
      }
5037
5038
103k
    dst->native = src;
5039
103k
    dst->symbol.udata.i = 0;
5040
103k
    dst->lineno = NULL;
5041
5042
103k
    this_index += (src->u.syment.n_numaux) + 1;
5043
103k
    dst++;
5044
103k
    number_of_symbols++;
5045
103k
  }
5046
639
    }
5047
5048
639
  obj_symbols (abfd) = cached_area;
5049
639
  obj_raw_syments (abfd) = native_symbols;
5050
5051
639
  abfd->symcount = number_of_symbols;
5052
639
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
639
  {
5055
639
    asection *p;
5056
5057
639
    p = abfd->sections;
5058
4.81k
    while (p)
5059
4.60k
      {
5060
4.60k
  if (! coff_slurp_line_table (abfd, p))
5061
424
    return false;
5062
4.17k
  p = p->next;
5063
4.17k
      }
5064
639
  }
5065
5066
215
  return ret;
5067
639
}
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
849
{
4696
849
  combined_entry_type *native_symbols;
4697
849
  coff_symbol_type *cached_area;
4698
849
  unsigned int *table_ptr;
4699
849
  unsigned int number_of_symbols = 0;
4700
849
  bool ret = true;
4701
849
  size_t amt;
4702
4703
849
  if (obj_symbols (abfd))
4704
342
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
507
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
45
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
462
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
462
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
462
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
462
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
462
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
462
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
462
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
462
  if (table_ptr == NULL)
4729
0
    return false;
4730
462
  else
4731
462
    {
4732
462
      coff_symbol_type *dst = cached_area;
4733
462
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
462
      unsigned int this_index = 0;
4735
4736
245k
      while (this_index < last_native_index)
4737
244k
  {
4738
244k
    combined_entry_type *src = native_symbols + this_index;
4739
244k
    table_ptr[this_index] = number_of_symbols;
4740
4741
244k
    dst->symbol.the_bfd = abfd;
4742
244k
    BFD_ASSERT (src->is_sym);
4743
244k
    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
244k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
244k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
244k
                 src->u.syment.n_scnum);
4748
244k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
244k
    dst->symbol.value = 0;
4751
244k
    dst->done_lineno = false;
4752
4753
244k
    switch (src->u.syment.n_sclass)
4754
244k
      {
4755
3.13k
      case C_EXT:
4756
3.30k
      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.30k
#ifdef C_SYSTEM
4768
3.52k
      case C_SYSTEM: /* System Wide variable.  */
4769
3.52k
#endif
4770
3.52k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
3.57k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
4.81k
      case C_NT_WEAK:
4775
4.81k
#endif
4776
4.81k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4.81k
    {
4778
4.23k
    case COFF_SYMBOL_GLOBAL:
4779
4.23k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
4.23k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
4.23k
      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.23k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
318
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
4.23k
      break;
4793
4794
411
    case COFF_SYMBOL_COMMON:
4795
411
      dst->symbol.section = bfd_com_section_ptr;
4796
411
      dst->symbol.value = src->u.syment.n_value;
4797
411
      break;
4798
4799
166
    case COFF_SYMBOL_UNDEFINED:
4800
166
      dst->symbol.section = bfd_und_section_ptr;
4801
166
      dst->symbol.value = 0;
4802
166
      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.81k
    }
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.81k
#ifdef COFF_WITH_PE
4831
4.81k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1.23k
    dst->symbol.flags |= BSF_WEAK;
4833
4834
4.81k
        if (src->u.syment.n_sclass == C_SECTION
4835
4.81k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
4.81k
#endif
4838
4.81k
        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.81k
      )
4843
172
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4.81k
        break;
4846
4847
1.31k
      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
3.33k
      case C_LABEL:  /* Label.  */
4858
3.33k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
3.33k
        else
4861
3.33k
    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
3.33k
        if (dst->symbol.section)
4866
3.33k
    {
4867
3.33k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
3.33k
      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
3.33k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
3.33k
        break;
4879
4880
632
      case C_FILE: /* File name.  */
4881
632
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.11k
      case C_MOS:   /* Member of structure.  */
4884
1.52k
      case C_EOS:   /* End of structure.  */
4885
1.89k
      case C_REGPARM: /* Register parameter.  */
4886
3.55k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
3.92k
      case C_TPDEF: /* Type definition.  */
4889
4.45k
      case C_ARG:
4890
9.23k
      case C_AUTO: /* Automatic variable.  */
4891
9.58k
      case C_FIELD: /* Bit field.  */
4892
9.99k
      case C_ENTAG: /* Enumeration tag.  */
4893
10.4k
      case C_MOE:   /* Member of enumeration.  */
4894
10.8k
      case C_MOU:   /* Member of union.  */
4895
11.2k
      case C_UNTAG: /* Union tag.  */
4896
11.7k
      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
11.7k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
11.7k
        dst->symbol.value = (src->u.syment.n_value);
4915
11.7k
        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
284
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.95k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2.47k
      case C_EFCN: /* Physical end of function.  */
4968
2.47k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
2.47k
        dst->symbol.value = src->u.syment.n_value;
4972
2.47k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
2.47k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
2.47k
      dst->symbol.flags = BSF_DEBUGGING;
4977
2.47k
    }
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.47k
        break;
4988
4989
214
      case C_STATLAB: /* Static load time label.  */
4990
214
        dst->symbol.value = src->u.syment.n_value;
4991
214
        dst->symbol.flags = BSF_GLOBAL;
4992
214
        break;
4993
4994
198k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
198k
        if (src->u.syment.n_type == 0
4998
198k
      && src->u.syment.n_value == 0
4999
198k
      && src->u.syment.n_scnum == 0)
5000
144k
    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.5k
      case C_EXTDEF: /* External definition.  */
5008
54.6k
      case C_ULABEL: /* Undefined label.  */
5009
54.7k
      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.8k
      case C_EXTLAB: /* External load time label.  */
5022
77.8k
      default:
5023
77.8k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
77.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
77.8k
     abfd, src->u.syment.n_sclass,
5027
77.8k
     dst->symbol.section->name, dst->symbol.name);
5028
77.8k
        ret = false;
5029
        /* Fall through.  */
5030
77.8k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
77.8k
        dst->symbol.flags = BSF_DEBUGGING;
5034
77.8k
        dst->symbol.value = (src->u.syment.n_value);
5035
77.8k
        break;
5036
244k
      }
5037
5038
244k
    dst->native = src;
5039
244k
    dst->symbol.udata.i = 0;
5040
244k
    dst->lineno = NULL;
5041
5042
244k
    this_index += (src->u.syment.n_numaux) + 1;
5043
244k
    dst++;
5044
244k
    number_of_symbols++;
5045
244k
  }
5046
462
    }
5047
5048
462
  obj_symbols (abfd) = cached_area;
5049
462
  obj_raw_syments (abfd) = native_symbols;
5050
5051
462
  abfd->symcount = number_of_symbols;
5052
462
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
462
  {
5055
462
    asection *p;
5056
5057
462
    p = abfd->sections;
5058
2.38k
    while (p)
5059
2.15k
      {
5060
2.15k
  if (! coff_slurp_line_table (abfd, p))
5061
226
    return false;
5062
1.92k
  p = p->next;
5063
1.92k
      }
5064
462
  }
5065
5066
236
  return ret;
5067
462
}
pe-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.36k
{
4696
1.36k
  combined_entry_type *native_symbols;
4697
1.36k
  coff_symbol_type *cached_area;
4698
1.36k
  unsigned int *table_ptr;
4699
1.36k
  unsigned int number_of_symbols = 0;
4700
1.36k
  bool ret = true;
4701
1.36k
  size_t amt;
4702
4703
1.36k
  if (obj_symbols (abfd))
4704
535
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
833
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
235
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
598
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
598
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
598
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
598
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
598
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
598
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
598
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
598
  if (table_ptr == NULL)
4729
0
    return false;
4730
598
  else
4731
598
    {
4732
598
      coff_symbol_type *dst = cached_area;
4733
598
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
598
      unsigned int this_index = 0;
4735
4736
198k
      while (this_index < last_native_index)
4737
197k
  {
4738
197k
    combined_entry_type *src = native_symbols + this_index;
4739
197k
    table_ptr[this_index] = number_of_symbols;
4740
4741
197k
    dst->symbol.the_bfd = abfd;
4742
197k
    BFD_ASSERT (src->is_sym);
4743
197k
    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
197k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
197k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
197k
                 src->u.syment.n_scnum);
4748
197k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
197k
    dst->symbol.value = 0;
4751
197k
    dst->done_lineno = false;
4752
4753
197k
    switch (src->u.syment.n_sclass)
4754
197k
      {
4755
3.38k
      case C_EXT:
4756
3.62k
      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.62k
#ifdef C_SYSTEM
4768
4.10k
      case C_SYSTEM: /* System Wide variable.  */
4769
4.10k
#endif
4770
4.10k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
4.15k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
5.43k
      case C_NT_WEAK:
4775
5.43k
#endif
4776
5.43k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
5.43k
    {
4778
5.01k
    case COFF_SYMBOL_GLOBAL:
4779
5.01k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
5.01k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
5.01k
      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.01k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
222
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
5.01k
      break;
4793
4794
295
    case COFF_SYMBOL_COMMON:
4795
295
      dst->symbol.section = bfd_com_section_ptr;
4796
295
      dst->symbol.value = src->u.syment.n_value;
4797
295
      break;
4798
4799
128
    case COFF_SYMBOL_UNDEFINED:
4800
128
      dst->symbol.section = bfd_und_section_ptr;
4801
128
      dst->symbol.value = 0;
4802
128
      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
5.43k
    }
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
5.43k
#ifdef COFF_WITH_PE
4831
5.43k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
1.28k
    dst->symbol.flags |= BSF_WEAK;
4833
4834
5.43k
        if (src->u.syment.n_sclass == C_SECTION
4835
5.43k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
5.43k
#endif
4838
5.43k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
5.43k
      )
4843
242
    dst->symbol.flags |= BSF_WEAK;
4844
4845
5.43k
        break;
4846
4847
1.78k
      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.03k
      case C_LABEL:  /* Label.  */
4858
5.03k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
3
    dst->symbol.flags = BSF_DEBUGGING;
4860
5.03k
        else
4861
5.03k
    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.03k
        if (dst->symbol.section)
4866
5.03k
    {
4867
5.03k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
5.03k
      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.03k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
5.03k
        break;
4879
4880
1.00k
      case C_FILE: /* File name.  */
4881
1.00k
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.78k
      case C_MOS:   /* Member of structure.  */
4884
2.24k
      case C_EOS:   /* End of structure.  */
4885
2.71k
      case C_REGPARM: /* Register parameter.  */
4886
4.84k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
5.32k
      case C_TPDEF: /* Type definition.  */
4889
5.66k
      case C_ARG:
4890
15.0k
      case C_AUTO: /* Automatic variable.  */
4891
15.8k
      case C_FIELD: /* Bit field.  */
4892
16.2k
      case C_ENTAG: /* Enumeration tag.  */
4893
16.9k
      case C_MOE:   /* Member of enumeration.  */
4894
18.9k
      case C_MOU:   /* Member of union.  */
4895
21.1k
      case C_UNTAG: /* Union tag.  */
4896
23.0k
      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
23.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
23.0k
        dst->symbol.value = (src->u.syment.n_value);
4915
23.0k
        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
412
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
2.18k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
2.84k
      case C_EFCN: /* Physical end of function.  */
4968
2.84k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
2.84k
        dst->symbol.value = src->u.syment.n_value;
4972
2.84k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
2.84k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
2.84k
      dst->symbol.flags = BSF_DEBUGGING;
4977
2.84k
    }
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.84k
        break;
4988
4989
225
      case C_STATLAB: /* Static load time label.  */
4990
225
        dst->symbol.value = src->u.syment.n_value;
4991
225
        dst->symbol.flags = BSF_GLOBAL;
4992
225
        break;
4993
4994
132k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
132k
        if (src->u.syment.n_type == 0
4998
132k
      && src->u.syment.n_value == 0
4999
132k
      && src->u.syment.n_scnum == 0)
5000
75.3k
    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
57.5k
      case C_EXTDEF: /* External definition.  */
5008
57.7k
      case C_ULABEL: /* Undefined label.  */
5009
57.8k
      case C_USTATIC: /* Undefined static.  */
5010
#ifndef COFF_WITH_PE
5011
      /* C_LINE in regular coff is 0x68.  NT has taken over this storage
5012
         class to represent a section symbol.  */
5013
      case C_LINE:  /* line # reformatted as symbol table entry.  */
5014
        /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
5015
      case C_ALIAS: /* Duplicate tag.  */
5016
#endif
5017
        /* New storage classes for TI COFF.  */
5018
#ifdef TICOFF
5019
      case C_UEXT:  /* Tentative external definition.  */
5020
#endif
5021
57.9k
      case C_EXTLAB: /* External load time label.  */
5022
85.8k
      default:
5023
85.8k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
85.8k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
85.8k
     abfd, src->u.syment.n_sclass,
5027
85.8k
     dst->symbol.section->name, dst->symbol.name);
5028
85.8k
        ret = false;
5029
        /* Fall through.  */
5030
85.9k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
85.9k
        dst->symbol.flags = BSF_DEBUGGING;
5034
85.9k
        dst->symbol.value = (src->u.syment.n_value);
5035
85.9k
        break;
5036
197k
      }
5037
5038
197k
    dst->native = src;
5039
197k
    dst->symbol.udata.i = 0;
5040
197k
    dst->lineno = NULL;
5041
5042
197k
    this_index += (src->u.syment.n_numaux) + 1;
5043
197k
    dst++;
5044
197k
    number_of_symbols++;
5045
197k
  }
5046
598
    }
5047
5048
598
  obj_symbols (abfd) = cached_area;
5049
598
  obj_raw_syments (abfd) = native_symbols;
5050
5051
598
  abfd->symcount = number_of_symbols;
5052
598
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
598
  {
5055
598
    asection *p;
5056
5057
598
    p = abfd->sections;
5058
2.21k
    while (p)
5059
1.92k
      {
5060
1.92k
  if (! coff_slurp_line_table (abfd, p))
5061
304
    return false;
5062
1.62k
  p = p->next;
5063
1.62k
      }
5064
598
  }
5065
5066
294
  return ret;
5067
598
}
pe-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.06k
{
4696
1.06k
  combined_entry_type *native_symbols;
4697
1.06k
  coff_symbol_type *cached_area;
4698
1.06k
  unsigned int *table_ptr;
4699
1.06k
  unsigned int number_of_symbols = 0;
4700
1.06k
  bool ret = true;
4701
1.06k
  size_t amt;
4702
4703
1.06k
  if (obj_symbols (abfd))
4704
410
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
650
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
84
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
566
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
566
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
566
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
566
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
566
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
566
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
566
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
566
  if (table_ptr == NULL)
4729
0
    return false;
4730
566
  else
4731
566
    {
4732
566
      coff_symbol_type *dst = cached_area;
4733
566
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
566
      unsigned int this_index = 0;
4735
4736
108k
      while (this_index < last_native_index)
4737
107k
  {
4738
107k
    combined_entry_type *src = native_symbols + this_index;
4739
107k
    table_ptr[this_index] = number_of_symbols;
4740
4741
107k
    dst->symbol.the_bfd = abfd;
4742
107k
    BFD_ASSERT (src->is_sym);
4743
107k
    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
107k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
107k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
107k
                 src->u.syment.n_scnum);
4748
107k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
107k
    dst->symbol.value = 0;
4751
107k
    dst->done_lineno = false;
4752
4753
107k
    switch (src->u.syment.n_sclass)
4754
107k
      {
4755
4.31k
      case C_EXT:
4756
4.45k
      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.45k
#ifdef C_SYSTEM
4768
4.62k
      case C_SYSTEM: /* System Wide variable.  */
4769
4.62k
#endif
4770
4.62k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
4.64k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
5.08k
      case C_NT_WEAK:
4775
5.08k
#endif
4776
5.08k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
5.08k
    {
4778
4.69k
    case COFF_SYMBOL_GLOBAL:
4779
4.69k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
4.69k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
4.69k
      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.69k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
135
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
4.69k
      break;
4793
4794
259
    case COFF_SYMBOL_COMMON:
4795
259
      dst->symbol.section = bfd_com_section_ptr;
4796
259
      dst->symbol.value = src->u.syment.n_value;
4797
259
      break;
4798
4799
129
    case COFF_SYMBOL_UNDEFINED:
4800
129
      dst->symbol.section = bfd_und_section_ptr;
4801
129
      dst->symbol.value = 0;
4802
129
      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
5.08k
    }
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
5.08k
#ifdef COFF_WITH_PE
4831
5.08k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
446
    dst->symbol.flags |= BSF_WEAK;
4833
4834
5.08k
        if (src->u.syment.n_sclass == C_SECTION
4835
5.08k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
5.08k
#endif
4838
5.08k
        if (src->u.syment.n_sclass == C_WEAKEXT
4839
#ifdef RS6000COFF_C
4840
      || src->u.syment.n_sclass == C_AIX_WEAKEXT
4841
#endif
4842
5.08k
      )
4843
137
    dst->symbol.flags |= BSF_WEAK;
4844
4845
5.08k
        break;
4846
4847
1.53k
      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
3.59k
      case C_LABEL:  /* Label.  */
4858
3.59k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
4
    dst->symbol.flags = BSF_DEBUGGING;
4860
3.59k
        else
4861
3.59k
    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
3.59k
        if (dst->symbol.section)
4866
3.59k
    {
4867
3.59k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
3.59k
      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
3.59k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
3.59k
        break;
4879
4880
492
      case C_FILE: /* File name.  */
4881
492
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.13k
      case C_MOS:   /* Member of structure.  */
4884
1.27k
      case C_EOS:   /* End of structure.  */
4885
1.60k
      case C_REGPARM: /* Register parameter.  */
4886
3.84k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
4.80k
      case C_TPDEF: /* Type definition.  */
4889
5.33k
      case C_ARG:
4890
9.18k
      case C_AUTO: /* Automatic variable.  */
4891
9.62k
      case C_FIELD: /* Bit field.  */
4892
9.88k
      case C_ENTAG: /* Enumeration tag.  */
4893
10.6k
      case C_MOE:   /* Member of enumeration.  */
4894
11.0k
      case C_MOU:   /* Member of union.  */
4895
11.3k
      case C_UNTAG: /* Union tag.  */
4896
12.0k
      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.0k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
12.0k
        dst->symbol.value = (src->u.syment.n_value);
4915
12.0k
        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
146
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
742
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.16k
      case C_EFCN: /* Physical end of function.  */
4968
1.16k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.16k
        dst->symbol.value = src->u.syment.n_value;
4972
1.16k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.16k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.16k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.16k
    }
4978
1
        else
4979
1
    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.16k
        break;
4988
4989
204
      case C_STATLAB: /* Static load time label.  */
4990
204
        dst->symbol.value = src->u.syment.n_value;
4991
204
        dst->symbol.flags = BSF_GLOBAL;
4992
204
        break;
4993
4994
72.3k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
72.3k
        if (src->u.syment.n_type == 0
4998
72.3k
      && src->u.syment.n_value == 0
4999
72.3k
      && src->u.syment.n_scnum == 0)
5000
35.5k
    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
37.1k
      case C_EXTDEF: /* External definition.  */
5008
37.2k
      case C_ULABEL: /* Undefined label.  */
5009
37.3k
      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
37.3k
      case C_EXTLAB: /* External load time label.  */
5022
50.1k
      default:
5023
50.1k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
50.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
50.1k
     abfd, src->u.syment.n_sclass,
5027
50.1k
     dst->symbol.section->name, dst->symbol.name);
5028
50.1k
        ret = false;
5029
        /* Fall through.  */
5030
50.3k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
50.3k
        dst->symbol.flags = BSF_DEBUGGING;
5034
50.3k
        dst->symbol.value = (src->u.syment.n_value);
5035
50.3k
        break;
5036
107k
      }
5037
5038
107k
    dst->native = src;
5039
107k
    dst->symbol.udata.i = 0;
5040
107k
    dst->lineno = NULL;
5041
5042
107k
    this_index += (src->u.syment.n_numaux) + 1;
5043
107k
    dst++;
5044
107k
    number_of_symbols++;
5045
107k
  }
5046
566
    }
5047
5048
566
  obj_symbols (abfd) = cached_area;
5049
566
  obj_raw_syments (abfd) = native_symbols;
5050
5051
566
  abfd->symcount = number_of_symbols;
5052
566
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
566
  {
5055
566
    asection *p;
5056
5057
566
    p = abfd->sections;
5058
2.39k
    while (p)
5059
2.13k
      {
5060
2.13k
  if (! coff_slurp_line_table (abfd, p))
5061
311
    return false;
5062
1.82k
  p = p->next;
5063
1.82k
      }
5064
566
  }
5065
5066
255
  return ret;
5067
566
}
pei-arm-wince.c:coff_slurp_symbol_table
Line
Count
Source
4695
365
{
4696
365
  combined_entry_type *native_symbols;
4697
365
  coff_symbol_type *cached_area;
4698
365
  unsigned int *table_ptr;
4699
365
  unsigned int number_of_symbols = 0;
4700
365
  bool ret = true;
4701
365
  size_t amt;
4702
4703
365
  if (obj_symbols (abfd))
4704
46
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
319
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
28
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
291
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
291
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
291
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
291
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
291
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
291
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
291
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
291
  if (table_ptr == NULL)
4729
0
    return false;
4730
291
  else
4731
291
    {
4732
291
      coff_symbol_type *dst = cached_area;
4733
291
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
291
      unsigned int this_index = 0;
4735
4736
46.8k
      while (this_index < last_native_index)
4737
46.5k
  {
4738
46.5k
    combined_entry_type *src = native_symbols + this_index;
4739
46.5k
    table_ptr[this_index] = number_of_symbols;
4740
4741
46.5k
    dst->symbol.the_bfd = abfd;
4742
46.5k
    BFD_ASSERT (src->is_sym);
4743
46.5k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
46.5k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
46.5k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
46.5k
                 src->u.syment.n_scnum);
4748
46.5k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
46.5k
    dst->symbol.value = 0;
4751
46.5k
    dst->done_lineno = false;
4752
4753
46.5k
    switch (src->u.syment.n_sclass)
4754
46.5k
      {
4755
514
      case C_EXT:
4756
535
      case C_WEAKEXT:
4757
535
#if defined ARM
4758
554
      case C_THUMBEXT:
4759
557
      case C_THUMBEXTFUNC:
4760
557
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
557
#ifdef C_SYSTEM
4768
667
      case C_SYSTEM: /* System Wide variable.  */
4769
667
#endif
4770
667
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
682
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
1.20k
      case C_NT_WEAK:
4775
1.20k
#endif
4776
1.20k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.20k
    {
4778
1.04k
    case COFF_SYMBOL_GLOBAL:
4779
1.04k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.04k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.04k
      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.04k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
68
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.04k
      break;
4793
4794
89
    case COFF_SYMBOL_COMMON:
4795
89
      dst->symbol.section = bfd_com_section_ptr;
4796
89
      dst->symbol.value = src->u.syment.n_value;
4797
89
      break;
4798
4799
62
    case COFF_SYMBOL_UNDEFINED:
4800
62
      dst->symbol.section = bfd_und_section_ptr;
4801
62
      dst->symbol.value = 0;
4802
62
      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.20k
    }
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.20k
#ifdef COFF_WITH_PE
4831
1.20k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
518
    dst->symbol.flags |= BSF_WEAK;
4833
4834
1.20k
        if (src->u.syment.n_sclass == C_SECTION
4835
1.20k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
1.20k
#endif
4838
1.20k
        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.20k
      )
4843
21
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.20k
        break;
4846
4847
574
      case C_STAT:  /* Static.  */
4848
574
#if defined ARM
4849
586
      case C_THUMBSTAT:    /* Thumb static.  */
4850
595
      case C_THUMBLABEL:   /* Thumb label.  */
4851
620
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
620
#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
870
      case C_LABEL:  /* Label.  */
4858
870
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
870
        else
4861
870
    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
870
        if (dst->symbol.section)
4866
870
    {
4867
870
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
870
      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
870
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
870
        break;
4879
4880
332
      case C_FILE: /* File name.  */
4881
332
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
950
      case C_MOS:   /* Member of structure.  */
4884
1.09k
      case C_EOS:   /* End of structure.  */
4885
1.14k
      case C_REGPARM: /* Register parameter.  */
4886
1.30k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.42k
      case C_TPDEF: /* Type definition.  */
4889
1.64k
      case C_ARG:
4890
2.61k
      case C_AUTO: /* Automatic variable.  */
4891
2.64k
      case C_FIELD: /* Bit field.  */
4892
2.83k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.93k
      case C_MOE:   /* Member of enumeration.  */
4894
3.04k
      case C_MOU:   /* Member of union.  */
4895
3.10k
      case C_UNTAG: /* Union tag.  */
4896
3.27k
      case C_STRTAG: /* Structure tag.  */
4897
#ifdef RS6000COFF_C
4898
      case C_GSYM:
4899
      case C_LSYM:
4900
      case C_PSYM:
4901
      case C_RSYM:
4902
      case C_RPSYM:
4903
      case C_STSYM:
4904
      case C_TCSYM:
4905
      case C_BCOMM:
4906
      case C_ECOML:
4907
      case C_ECOMM:
4908
      case C_DECL:
4909
      case C_ENTRY:
4910
      case C_FUN:
4911
      case C_ESTAT:
4912
#endif
4913
3.27k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3.27k
        dst->symbol.value = (src->u.syment.n_value);
4915
3.27k
        break;
4916
4917
#ifdef RS6000COFF_C
4918
      case C_BINCL: /* Beginning of include file.  */
4919
      case C_EINCL: /* Ending of include file.  */
4920
        /* The value is actually a pointer into the line numbers
4921
     of the file.  We locate the line number entry, and
4922
     set the section to the section which contains it, and
4923
     the value to the index in that section.  */
4924
        {
4925
    asection *sec;
4926
4927
    dst->symbol.flags = BSF_DEBUGGING;
4928
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
4929
      if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
4930
          && ((file_ptr) (sec->line_filepos
4931
              + sec->lineno_count * bfd_coff_linesz (abfd))
4932
        > (file_ptr) src->u.syment.n_value))
4933
        break;
4934
    if (sec == NULL)
4935
      dst->symbol.value = 0;
4936
    else
4937
      {
4938
        dst->symbol.section = sec;
4939
        dst->symbol.value = ((src->u.syment.n_value
4940
            - sec->line_filepos)
4941
           / bfd_coff_linesz (abfd));
4942
        src->fix_line = 1;
4943
      }
4944
        }
4945
        break;
4946
4947
      case C_BSTAT:
4948
        dst->symbol.flags = BSF_DEBUGGING;
4949
4950
        if (src->u.syment.n_value >= obj_raw_syment_count (abfd))
4951
    dst->symbol.value = 0;
4952
        else
4953
    {
4954
      /* The value is actually a symbol index.  Save a pointer
4955
         to the symbol instead of the index.  FIXME: This
4956
         should use a union.  */
4957
      src->u.syment.n_value
4958
        = (uintptr_t) (native_symbols + src->u.syment.n_value);
4959
      dst->symbol.value = src->u.syment.n_value;
4960
      src->fix_value = 1;
4961
    }
4962
        break;
4963
#endif
4964
4965
110
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
839
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
958
      case C_EFCN: /* Physical end of function.  */
4968
958
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
958
        dst->symbol.value = src->u.syment.n_value;
4972
958
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
956
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
956
      dst->symbol.flags = BSF_DEBUGGING;
4977
956
    }
4978
2
        else
4979
2
    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
958
        break;
4988
4989
25
      case C_STATLAB: /* Static load time label.  */
4990
25
        dst->symbol.value = src->u.syment.n_value;
4991
25
        dst->symbol.flags = BSF_GLOBAL;
4992
25
        break;
4993
4994
32.7k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
32.7k
        if (src->u.syment.n_type == 0
4998
32.7k
      && src->u.syment.n_value == 0
4999
32.7k
      && src->u.syment.n_scnum == 0)
5000
16.3k
    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
16.4k
      case C_EXTDEF: /* External definition.  */
5008
16.4k
      case C_ULABEL: /* Undefined label.  */
5009
16.4k
      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
16.4k
      case C_EXTLAB: /* External load time label.  */
5022
23.7k
      default:
5023
23.7k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
23.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
23.7k
     abfd, src->u.syment.n_sclass,
5027
23.7k
     dst->symbol.section->name, dst->symbol.name);
5028
23.7k
        ret = false;
5029
        /* Fall through.  */
5030
23.8k
      case C_HIDDEN: /* Ext symbol in dmert public lib.  */
5031
        /* PR 20722: These symbols can also be generated by
5032
     building DLLs with --gc-sections enabled.  */
5033
23.8k
        dst->symbol.flags = BSF_DEBUGGING;
5034
23.8k
        dst->symbol.value = (src->u.syment.n_value);
5035
23.8k
        break;
5036
46.5k
      }
5037
5038
46.5k
    dst->native = src;
5039
46.5k
    dst->symbol.udata.i = 0;
5040
46.5k
    dst->lineno = NULL;
5041
5042
46.5k
    this_index += (src->u.syment.n_numaux) + 1;
5043
46.5k
    dst++;
5044
46.5k
    number_of_symbols++;
5045
46.5k
  }
5046
291
    }
5047
5048
291
  obj_symbols (abfd) = cached_area;
5049
291
  obj_raw_syments (abfd) = native_symbols;
5050
5051
291
  abfd->symcount = number_of_symbols;
5052
291
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
291
  {
5055
291
    asection *p;
5056
5057
291
    p = abfd->sections;
5058
4.49k
    while (p)
5059
4.43k
      {
5060
4.43k
  if (! coff_slurp_line_table (abfd, p))
5061
228
    return false;
5062
4.20k
  p = p->next;
5063
4.20k
      }
5064
291
  }
5065
5066
63
  return ret;
5067
291
}
pei-arm.c:coff_slurp_symbol_table
Line
Count
Source
4695
629
{
4696
629
  combined_entry_type *native_symbols;
4697
629
  coff_symbol_type *cached_area;
4698
629
  unsigned int *table_ptr;
4699
629
  unsigned int number_of_symbols = 0;
4700
629
  bool ret = true;
4701
629
  size_t amt;
4702
4703
629
  if (obj_symbols (abfd))
4704
120
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
509
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
106
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
403
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
403
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
403
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
403
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
403
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
403
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
403
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
403
  if (table_ptr == NULL)
4729
0
    return false;
4730
403
  else
4731
403
    {
4732
403
      coff_symbol_type *dst = cached_area;
4733
403
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
403
      unsigned int this_index = 0;
4735
4736
47.0k
      while (this_index < last_native_index)
4737
46.6k
  {
4738
46.6k
    combined_entry_type *src = native_symbols + this_index;
4739
46.6k
    table_ptr[this_index] = number_of_symbols;
4740
4741
46.6k
    dst->symbol.the_bfd = abfd;
4742
46.6k
    BFD_ASSERT (src->is_sym);
4743
46.6k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
46.6k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
46.6k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
46.6k
                 src->u.syment.n_scnum);
4748
46.6k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
46.6k
    dst->symbol.value = 0;
4751
46.6k
    dst->done_lineno = false;
4752
4753
46.6k
    switch (src->u.syment.n_sclass)
4754
46.6k
      {
4755
443
      case C_EXT:
4756
469
      case C_WEAKEXT:
4757
469
#if defined ARM
4758
496
      case C_THUMBEXT:
4759
548
      case C_THUMBEXTFUNC:
4760
548
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
548
#ifdef C_SYSTEM
4768
650
      case C_SYSTEM: /* System Wide variable.  */
4769
650
#endif
4770
650
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
678
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
1.31k
      case C_NT_WEAK:
4775
1.31k
#endif
4776
1.31k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
1.31k
    {
4778
1.14k
    case COFF_SYMBOL_GLOBAL:
4779
1.14k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
1.14k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
1.14k
      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.14k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
45
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
1.14k
      break;
4793
4794
99
    case COFF_SYMBOL_COMMON:
4795
99
      dst->symbol.section = bfd_com_section_ptr;
4796
99
      dst->symbol.value = src->u.syment.n_value;
4797
99
      break;
4798
4799
67
    case COFF_SYMBOL_UNDEFINED:
4800
67
      dst->symbol.section = bfd_und_section_ptr;
4801
67
      dst->symbol.value = 0;
4802
67
      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.31k
    }
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.31k
#ifdef COFF_WITH_PE
4831
1.31k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
633
    dst->symbol.flags |= BSF_WEAK;
4833
4834
1.31k
        if (src->u.syment.n_sclass == C_SECTION
4835
1.31k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
1.31k
#endif
4838
1.31k
        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.31k
      )
4843
26
    dst->symbol.flags |= BSF_WEAK;
4844
4845
1.31k
        break;
4846
4847
632
      case C_STAT:  /* Static.  */
4848
632
#if defined ARM
4849
664
      case C_THUMBSTAT:    /* Thumb static.  */
4850
674
      case C_THUMBLABEL:   /* Thumb label.  */
4851
723
      case C_THUMBSTATFUNC:/* Thumb static function.  */
4852
723
#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
780
      case C_LABEL:  /* Label.  */
4858
780
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
780
        else
4861
780
    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
780
        if (dst->symbol.section)
4866
780
    {
4867
780
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
780
      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
780
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
780
        break;
4879
4880
323
      case C_FILE: /* File name.  */
4881
323
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
482
      case C_MOS:   /* Member of structure.  */
4884
592
      case C_EOS:   /* End of structure.  */
4885
716
      case C_REGPARM: /* Register parameter.  */
4886
919
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
1.14k
      case C_TPDEF: /* Type definition.  */
4889
1.27k
      case C_ARG:
4890
2.54k
      case C_AUTO: /* Automatic variable.  */
4891
2.61k
      case C_FIELD: /* Bit field.  */
4892
2.67k
      case C_ENTAG: /* Enumeration tag.  */
4893
2.85k
      case C_MOE:   /* Member of enumeration.  */
4894
2.90k
      case C_MOU:   /* Member of union.  */
4895
3.01k
      case C_UNTAG: /* Union tag.  */
4896
3.28k
      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.28k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
3.28k
        dst->symbol.value = (src->u.syment.n_value);
4915
3.28k
        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
126
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
1.06k
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.18k
      case C_EFCN: /* Physical end of function.  */
4968
1.18k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.18k
        dst->symbol.value = src->u.syment.n_value;
4972
1.18k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.18k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.18k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.18k
    }
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.18k
        break;
4988
4989
127
      case C_STATLAB: /* Static load time label.  */
4990
127
        dst->symbol.value = src->u.syment.n_value;
4991
127
        dst->symbol.flags = BSF_GLOBAL;
4992
127
        break;
4993
4994
31.0k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
31.0k
        if (src->u.syment.n_type == 0
4998
31.0k
      && src->u.syment.n_value == 0
4999
31.0k
      && src->u.syment.n_scnum == 0)
5000
10.2k
    break;
5001
#ifdef RS6000COFF_C
5002
        /* XCOFF specific: deleted entry.  */
5003
        if (src->u.syment.n_value == C_NULL_VALUE)
5004
    break;
5005
#endif
5006
        /* Fall through.  */
5007
20.9k
      case C_EXTDEF: /* External definition.  */
5008
21.0k
      case C_ULABEL: /* Undefined label.  */
5009
21.0k
      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
21.0k
      case C_EXTLAB: /* External load time label.  */
5022
29.7k
      default:
5023
29.7k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
29.7k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
29.7k
     abfd, src->u.syment.n_sclass,
5027
29.7k
     dst->symbol.section->name, dst->symbol.name);
5028
29.7k
        ret = false;
5029
        /* Fall through.  */
5030
29.7k
      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
29.7k
        dst->symbol.flags = BSF_DEBUGGING;
5034
29.7k
        dst->symbol.value = (src->u.syment.n_value);
5035
29.7k
        break;
5036
46.6k
      }
5037
5038
46.6k
    dst->native = src;
5039
46.6k
    dst->symbol.udata.i = 0;
5040
46.6k
    dst->lineno = NULL;
5041
5042
46.6k
    this_index += (src->u.syment.n_numaux) + 1;
5043
46.6k
    dst++;
5044
46.6k
    number_of_symbols++;
5045
46.6k
  }
5046
403
    }
5047
5048
403
  obj_symbols (abfd) = cached_area;
5049
403
  obj_raw_syments (abfd) = native_symbols;
5050
5051
403
  abfd->symcount = number_of_symbols;
5052
403
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
403
  {
5055
403
    asection *p;
5056
5057
403
    p = abfd->sections;
5058
1.16k
    while (p)
5059
1.06k
      {
5060
1.06k
  if (! coff_slurp_line_table (abfd, p))
5061
300
    return false;
5062
761
  p = p->next;
5063
761
      }
5064
403
  }
5065
5066
103
  return ret;
5067
403
}
pei-mcore.c:coff_slurp_symbol_table
Line
Count
Source
4695
499
{
4696
499
  combined_entry_type *native_symbols;
4697
499
  coff_symbol_type *cached_area;
4698
499
  unsigned int *table_ptr;
4699
499
  unsigned int number_of_symbols = 0;
4700
499
  bool ret = true;
4701
499
  size_t amt;
4702
4703
499
  if (obj_symbols (abfd))
4704
61
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
438
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
91
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
347
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
347
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
347
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
347
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
347
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
347
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
347
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
347
  if (table_ptr == NULL)
4729
0
    return false;
4730
347
  else
4731
347
    {
4732
347
      coff_symbol_type *dst = cached_area;
4733
347
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
347
      unsigned int this_index = 0;
4735
4736
47.5k
      while (this_index < last_native_index)
4737
47.1k
  {
4738
47.1k
    combined_entry_type *src = native_symbols + this_index;
4739
47.1k
    table_ptr[this_index] = number_of_symbols;
4740
4741
47.1k
    dst->symbol.the_bfd = abfd;
4742
47.1k
    BFD_ASSERT (src->is_sym);
4743
47.1k
    dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
4744
    /* We use the native name field to point to the cached field.  */
4745
47.1k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
47.1k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
47.1k
                 src->u.syment.n_scnum);
4748
47.1k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
47.1k
    dst->symbol.value = 0;
4751
47.1k
    dst->done_lineno = false;
4752
4753
47.1k
    switch (src->u.syment.n_sclass)
4754
47.1k
      {
4755
3.62k
      case C_EXT:
4756
3.66k
      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.66k
#ifdef C_SYSTEM
4768
3.74k
      case C_SYSTEM: /* System Wide variable.  */
4769
3.74k
#endif
4770
3.74k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
3.77k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
4.10k
      case C_NT_WEAK:
4775
4.10k
#endif
4776
4.10k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
4.10k
    {
4778
3.95k
    case COFF_SYMBOL_GLOBAL:
4779
3.95k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
3.95k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
3.95k
      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
3.95k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
62
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
3.95k
      break;
4793
4794
58
    case COFF_SYMBOL_COMMON:
4795
58
      dst->symbol.section = bfd_com_section_ptr;
4796
58
      dst->symbol.value = src->u.syment.n_value;
4797
58
      break;
4798
4799
91
    case COFF_SYMBOL_UNDEFINED:
4800
91
      dst->symbol.section = bfd_und_section_ptr;
4801
91
      dst->symbol.value = 0;
4802
91
      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.10k
    }
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.10k
#ifdef COFF_WITH_PE
4831
4.10k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
334
    dst->symbol.flags |= BSF_WEAK;
4833
4834
4.10k
        if (src->u.syment.n_sclass == C_SECTION
4835
4.10k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
4.10k
#endif
4838
4.10k
        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.10k
      )
4843
42
    dst->symbol.flags |= BSF_WEAK;
4844
4845
4.10k
        break;
4846
4847
1.07k
      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.33k
      case C_LABEL:  /* Label.  */
4858
1.33k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
2
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.33k
        else
4861
1.33k
    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.33k
        if (dst->symbol.section)
4866
1.33k
    {
4867
1.33k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.33k
      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.33k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.33k
        break;
4879
4880
229
      case C_FILE: /* File name.  */
4881
229
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.01k
      case C_MOS:   /* Member of structure.  */
4884
1.24k
      case C_EOS:   /* End of structure.  */
4885
1.36k
      case C_REGPARM: /* Register parameter.  */
4886
2.48k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
2.75k
      case C_TPDEF: /* Type definition.  */
4889
2.91k
      case C_ARG:
4890
4.39k
      case C_AUTO: /* Automatic variable.  */
4891
5.63k
      case C_FIELD: /* Bit field.  */
4892
5.73k
      case C_ENTAG: /* Enumeration tag.  */
4893
6.10k
      case C_MOE:   /* Member of enumeration.  */
4894
6.45k
      case C_MOU:   /* Member of union.  */
4895
6.63k
      case C_UNTAG: /* Union tag.  */
4896
6.80k
      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.80k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
6.80k
        dst->symbol.value = (src->u.syment.n_value);
4915
6.80k
        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
111
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
522
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
788
      case C_EFCN: /* Physical end of function.  */
4968
788
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
788
        dst->symbol.value = src->u.syment.n_value;
4972
788
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
788
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
788
      dst->symbol.flags = BSF_DEBUGGING;
4977
788
    }
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
788
        break;
4988
4989
81
      case C_STATLAB: /* Static load time label.  */
4990
81
        dst->symbol.value = src->u.syment.n_value;
4991
81
        dst->symbol.flags = BSF_GLOBAL;
4992
81
        break;
4993
4994
27.0k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
27.0k
        if (src->u.syment.n_type == 0
4998
27.0k
      && src->u.syment.n_value == 0
4999
27.0k
      && src->u.syment.n_scnum == 0)
5000
11.7k
    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
15.3k
      case C_EXTDEF: /* External definition.  */
5008
15.3k
      case C_ULABEL: /* Undefined label.  */
5009
15.4k
      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
15.4k
      case C_EXTLAB: /* External load time label.  */
5022
22.1k
      default:
5023
22.1k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
22.1k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
22.1k
     abfd, src->u.syment.n_sclass,
5027
22.1k
     dst->symbol.section->name, dst->symbol.name);
5028
22.1k
        ret = false;
5029
        /* Fall through.  */
5030
22.2k
      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
22.2k
        dst->symbol.flags = BSF_DEBUGGING;
5034
22.2k
        dst->symbol.value = (src->u.syment.n_value);
5035
22.2k
        break;
5036
47.1k
      }
5037
5038
47.1k
    dst->native = src;
5039
47.1k
    dst->symbol.udata.i = 0;
5040
47.1k
    dst->lineno = NULL;
5041
5042
47.1k
    this_index += (src->u.syment.n_numaux) + 1;
5043
47.1k
    dst++;
5044
47.1k
    number_of_symbols++;
5045
47.1k
  }
5046
347
    }
5047
5048
347
  obj_symbols (abfd) = cached_area;
5049
347
  obj_raw_syments (abfd) = native_symbols;
5050
5051
347
  abfd->symcount = number_of_symbols;
5052
347
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
347
  {
5055
347
    asection *p;
5056
5057
347
    p = abfd->sections;
5058
917
    while (p)
5059
788
      {
5060
788
  if (! coff_slurp_line_table (abfd, p))
5061
218
    return false;
5062
570
  p = p->next;
5063
570
      }
5064
347
  }
5065
5066
129
  return ret;
5067
347
}
pei-sh.c:coff_slurp_symbol_table
Line
Count
Source
4695
1.25k
{
4696
1.25k
  combined_entry_type *native_symbols;
4697
1.25k
  coff_symbol_type *cached_area;
4698
1.25k
  unsigned int *table_ptr;
4699
1.25k
  unsigned int number_of_symbols = 0;
4700
1.25k
  bool ret = true;
4701
1.25k
  size_t amt;
4702
4703
1.25k
  if (obj_symbols (abfd))
4704
300
    return true;
4705
4706
  /* Read in the symbol table.  */
4707
958
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
4708
490
    return false;
4709
4710
  /* Allocate enough room for all the symbols in cached form.  */
4711
468
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4712
468
       sizeof (*cached_area), &amt))
4713
0
    {
4714
0
      bfd_set_error (bfd_error_file_too_big);
4715
0
      return false;
4716
0
    }
4717
468
  cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
4718
468
  if (cached_area == NULL)
4719
0
    return false;
4720
4721
468
  if (_bfd_mul_overflow (obj_raw_syment_count (abfd),
4722
468
       sizeof (*table_ptr), &amt))
4723
0
    {
4724
0
      bfd_set_error (bfd_error_file_too_big);
4725
0
      return false;
4726
0
    }
4727
468
  table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
4728
468
  if (table_ptr == NULL)
4729
0
    return false;
4730
468
  else
4731
468
    {
4732
468
      coff_symbol_type *dst = cached_area;
4733
468
      unsigned int last_native_index = obj_raw_syment_count (abfd);
4734
468
      unsigned int this_index = 0;
4735
4736
162k
      while (this_index < last_native_index)
4737
162k
  {
4738
162k
    combined_entry_type *src = native_symbols + this_index;
4739
162k
    table_ptr[this_index] = number_of_symbols;
4740
4741
162k
    dst->symbol.the_bfd = abfd;
4742
162k
    BFD_ASSERT (src->is_sym);
4743
162k
    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
162k
    src->u.syment._n._n_n._n_zeroes = (uintptr_t) dst;
4746
162k
    dst->symbol.section = coff_section_from_bfd_index (abfd,
4747
162k
                 src->u.syment.n_scnum);
4748
162k
    dst->symbol.flags = 0;
4749
    /* PR 17512: file: 079-7098-0.001:0.1.  */
4750
162k
    dst->symbol.value = 0;
4751
162k
    dst->done_lineno = false;
4752
4753
162k
    switch (src->u.syment.n_sclass)
4754
162k
      {
4755
2.55k
      case C_EXT:
4756
2.68k
      case C_WEAKEXT:
4757
#if defined ARM
4758
      case C_THUMBEXT:
4759
      case C_THUMBEXTFUNC:
4760
#endif
4761
#ifdef RS6000COFF_C
4762
      case C_HIDEXT:
4763
#ifndef AIX_WEAK_SUPPORT
4764
      case C_AIX_WEAKEXT:
4765
#endif
4766
#endif
4767
2.68k
#ifdef C_SYSTEM
4768
2.89k
      case C_SYSTEM: /* System Wide variable.  */
4769
2.89k
#endif
4770
2.89k
#ifdef COFF_WITH_PE
4771
      /* In PE, 0x68 (104) denotes a section symbol.  */
4772
2.91k
      case C_SECTION:
4773
      /* In PE, 0x69 (105) denotes a weak external symbol.  */
4774
3.40k
      case C_NT_WEAK:
4775
3.40k
#endif
4776
3.40k
        switch (coff_classify_symbol (abfd, &src->u.syment))
4777
3.40k
    {
4778
3.08k
    case COFF_SYMBOL_GLOBAL:
4779
3.08k
      dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
4780
3.08k
#if defined COFF_WITH_PE
4781
      /* PE sets the symbol to a value relative to the
4782
         start of the section.  */
4783
3.08k
      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
3.08k
      if (ISFCN ((src->u.syment.n_type)))
4789
        /* A function ext does not go at the end of a
4790
           file.  */
4791
77
        dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
4792
3.08k
      break;
4793
4794
215
    case COFF_SYMBOL_COMMON:
4795
215
      dst->symbol.section = bfd_com_section_ptr;
4796
215
      dst->symbol.value = src->u.syment.n_value;
4797
215
      break;
4798
4799
101
    case COFF_SYMBOL_UNDEFINED:
4800
101
      dst->symbol.section = bfd_und_section_ptr;
4801
101
      dst->symbol.value = 0;
4802
101
      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.40k
    }
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.40k
#ifdef COFF_WITH_PE
4831
3.40k
        if (src->u.syment.n_sclass == C_NT_WEAK)
4832
488
    dst->symbol.flags |= BSF_WEAK;
4833
4834
3.40k
        if (src->u.syment.n_sclass == C_SECTION
4835
3.40k
      && src->u.syment.n_scnum > 0)
4836
0
    dst->symbol.flags = BSF_LOCAL;
4837
3.40k
#endif
4838
3.40k
        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.40k
      )
4843
130
    dst->symbol.flags |= BSF_WEAK;
4844
4845
3.40k
        break;
4846
4847
1.37k
      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.86k
      case C_LABEL:  /* Label.  */
4858
1.86k
        if (src->u.syment.n_scnum == N_DEBUG)
4859
0
    dst->symbol.flags = BSF_DEBUGGING;
4860
1.86k
        else
4861
1.86k
    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.86k
        if (dst->symbol.section)
4866
1.86k
    {
4867
1.86k
#if defined COFF_WITH_PE
4868
      /* PE sets the symbol to a value relative to the
4869
         start of the section.  */
4870
1.86k
      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.86k
    }
4876
0
        else
4877
0
    dst->symbol.value = src->u.syment.n_value;
4878
1.86k
        break;
4879
4880
434
      case C_FILE: /* File name.  */
4881
434
        dst->symbol.flags = BSF_FILE;
4882
        /* Fall through.  */
4883
1.32k
      case C_MOS:   /* Member of structure.  */
4884
1.53k
      case C_EOS:   /* End of structure.  */
4885
2.35k
      case C_REGPARM: /* Register parameter.  */
4886
2.87k
      case C_REG:   /* register variable.  */
4887
        /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
4888
4.14k
      case C_TPDEF: /* Type definition.  */
4889
4.36k
      case C_ARG:
4890
9.59k
      case C_AUTO: /* Automatic variable.  */
4891
11.5k
      case C_FIELD: /* Bit field.  */
4892
11.7k
      case C_ENTAG: /* Enumeration tag.  */
4893
13.5k
      case C_MOE:   /* Member of enumeration.  */
4894
15.0k
      case C_MOU:   /* Member of union.  */
4895
15.4k
      case C_UNTAG: /* Union tag.  */
4896
21.4k
      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.4k
        dst->symbol.flags |= BSF_DEBUGGING;
4914
21.4k
        dst->symbol.value = (src->u.syment.n_value);
4915
21.4k
        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
156
      case C_BLOCK: /* ".bb" or ".eb".  */
4966
963
      case C_FCN:   /* ".bf" or ".ef" (or PE ".lf").  */
4967
1.57k
      case C_EFCN: /* Physical end of function.  */
4968
1.57k
#if defined COFF_WITH_PE
4969
        /* PE sets the symbol to a value relative to the start
4970
     of the section.  */
4971
1.57k
        dst->symbol.value = src->u.syment.n_value;
4972
1.57k
        if (strcmp (dst->symbol.name, ".bf") != 0)
4973
1.57k
    {
4974
      /* PE uses funny values for .ef and .lf; don't
4975
         relocate them.  */
4976
1.57k
      dst->symbol.flags = BSF_DEBUGGING;
4977
1.57k
    }
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.57k
        break;
4988
4989
302
      case C_STATLAB: /* Static load time label.  */
4990
302
        dst->symbol.value = src->u.syment.n_value;
4991
302
        dst->symbol.flags = BSF_GLOBAL;
4992
302
        break;
4993
4994
118k
      case C_NULL:
4995
        /* PE DLLs sometimes have zeroed out symbols for some
4996
     reason.  Just ignore them without a warning.  */
4997
118k
        if (src->u.syment.n_type == 0
4998
118k
      && src->u.syment.n_value == 0
4999
118k
      && src->u.syment.n_scnum == 0)
5000
76.0k
    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
42.4k
      case C_EXTDEF: /* External definition.  */
5008
42.6k
      case C_ULABEL: /* Undefined label.  */
5009
42.7k
      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
42.7k
      case C_EXTLAB: /* External load time label.  */
5022
57.5k
      default:
5023
57.5k
        _bfd_error_handler
5024
    /* xgettext:c-format */
5025
57.5k
    (_("%pB: unrecognized storage class %d for %s symbol `%s'"),
5026
57.5k
     abfd, src->u.syment.n_sclass,
5027
57.5k
     dst->symbol.section->name, dst->symbol.name);
5028
57.5k
        ret = false;
5029
        /* Fall through.  */
5030
57.6k
      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
57.6k
        dst->symbol.flags = BSF_DEBUGGING;
5034
57.6k
        dst->symbol.value = (src->u.syment.n_value);
5035
57.6k
        break;
5036
162k
      }
5037
5038
162k
    dst->native = src;
5039
162k
    dst->symbol.udata.i = 0;
5040
162k
    dst->lineno = NULL;
5041
5042
162k
    this_index += (src->u.syment.n_numaux) + 1;
5043
162k
    dst++;
5044
162k
    number_of_symbols++;
5045
162k
  }
5046
468
    }
5047
5048
468
  obj_symbols (abfd) = cached_area;
5049
468
  obj_raw_syments (abfd) = native_symbols;
5050
5051
468
  abfd->symcount = number_of_symbols;
5052
468
  obj_convert (abfd) = table_ptr;
5053
  /* Slurp the line tables for each section too.  */
5054
468
  {
5055
468
    asection *p;
5056
5057
468
    p = abfd->sections;
5058
1.80k
    while (p)
5059
1.61k
      {
5060
1.61k
  if (! coff_slurp_line_table (abfd, p))
5061
285
    return false;
5062
1.33k
  p = p->next;
5063
1.33k
      }
5064
468
  }
5065
5066
183
  return ret;
5067
468
}
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
85.1k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
85.1k
  switch (syment->n_sclass)
5080
85.1k
    {
5081
52.3k
    case C_EXT:
5082
56.2k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
1.05k
    case C_THUMBEXT:
5085
1.10k
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
11.4k
    case C_HIDEXT:
5089
11.4k
#ifndef AIX_WEAK_SUPPORT
5090
13.6k
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
13.6k
#ifdef C_SYSTEM
5094
63.5k
    case C_SYSTEM:
5095
63.5k
#endif
5096
#ifdef COFF_WITH_PE
5097
43.5k
    case C_NT_WEAK:
5098
#endif
5099
73.0k
      if (syment->n_scnum == 0)
5100
10.5k
  {
5101
10.5k
    if (syment->n_value == 0)
5102
2.61k
      return COFF_SYMBOL_UNDEFINED;
5103
7.94k
    else
5104
7.94k
      return COFF_SYMBOL_COMMON;
5105
10.5k
  }
5106
#ifdef RS6000COFF_C
5107
11.8k
      if (syment->n_sclass == C_HIDEXT)
5108
587
  return COFF_SYMBOL_LOCAL;
5109
11.2k
#endif
5110
61.8k
      return COFF_SYMBOL_GLOBAL;
5111
5112
12.1k
    default:
5113
12.1k
      break;
5114
85.1k
    }
5115
5116
#ifdef COFF_WITH_PE
5117
12.1k
  if (syment->n_sclass == C_STAT)
5118
418
    {
5119
418
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
131
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
287
      return COFF_SYMBOL_LOCAL;
5144
418
    }
5145
5146
11.7k
  if (syment->n_sclass == C_SECTION)
5147
474
    {
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
474
      syment->n_value = 0;
5152
474
      if (syment->n_scnum == 0)
5153
454
  return COFF_SYMBOL_UNDEFINED;
5154
20
      return COFF_SYMBOL_PE_SECTION;
5155
474
    }
5156
11.2k
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
11.2k
  if (syment->n_scnum == 0)
5160
11.1k
    {
5161
11.1k
      char buf[SYMNMLEN + 1];
5162
5163
11.1k
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
11.1k
  (_("warning: %pB: local symbol `%s' has no section"),
5166
11.1k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
11.1k
    }
5168
5169
11.2k
  return COFF_SYMBOL_LOCAL;
5170
11.7k
}
pei-i386.c:coff_classify_symbol
Line
Count
Source
5076
1.51k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.51k
  switch (syment->n_sclass)
5080
1.51k
    {
5081
966
    case C_EXT:
5082
1.11k
    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.11k
#ifdef C_SYSTEM
5094
1.17k
    case C_SYSTEM:
5095
1.17k
#endif
5096
1.17k
#ifdef COFF_WITH_PE
5097
1.48k
    case C_NT_WEAK:
5098
1.48k
#endif
5099
1.48k
      if (syment->n_scnum == 0)
5100
148
  {
5101
148
    if (syment->n_value == 0)
5102
47
      return COFF_SYMBOL_UNDEFINED;
5103
101
    else
5104
101
      return COFF_SYMBOL_COMMON;
5105
148
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.34k
      return COFF_SYMBOL_GLOBAL;
5111
5112
25
    default:
5113
25
      break;
5114
1.51k
    }
5115
5116
25
#ifdef COFF_WITH_PE
5117
25
  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
25
  if (syment->n_sclass == C_SECTION)
5147
25
    {
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
25
      syment->n_value = 0;
5152
25
      if (syment->n_scnum == 0)
5153
25
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
25
    }
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
25
}
pe-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
3.72k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3.72k
  switch (syment->n_sclass)
5080
3.72k
    {
5081
2.69k
    case C_EXT:
5082
2.97k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.97k
#ifdef C_SYSTEM
5094
3.25k
    case C_SYSTEM:
5095
3.25k
#endif
5096
3.25k
#ifdef COFF_WITH_PE
5097
3.58k
    case C_NT_WEAK:
5098
3.58k
#endif
5099
3.58k
      if (syment->n_scnum == 0)
5100
618
  {
5101
618
    if (syment->n_value == 0)
5102
161
      return COFF_SYMBOL_UNDEFINED;
5103
457
    else
5104
457
      return COFF_SYMBOL_COMMON;
5105
618
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.96k
      return COFF_SYMBOL_GLOBAL;
5111
5112
145
    default:
5113
145
      break;
5114
3.72k
    }
5115
5116
145
#ifdef COFF_WITH_PE
5117
145
  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
145
  if (syment->n_sclass == C_SECTION)
5147
145
    {
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
145
      syment->n_value = 0;
5152
145
      if (syment->n_scnum == 0)
5153
125
  return COFF_SYMBOL_UNDEFINED;
5154
20
      return COFF_SYMBOL_PE_SECTION;
5155
145
    }
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
145
}
pei-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
3.62k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3.62k
  switch (syment->n_sclass)
5080
3.62k
    {
5081
2.49k
    case C_EXT:
5082
2.57k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.57k
#ifdef C_SYSTEM
5094
2.67k
    case C_SYSTEM:
5095
2.67k
#endif
5096
2.67k
#ifdef COFF_WITH_PE
5097
3.25k
    case C_NT_WEAK:
5098
3.25k
#endif
5099
3.25k
      if (syment->n_scnum == 0)
5100
578
  {
5101
578
    if (syment->n_value == 0)
5102
421
      return COFF_SYMBOL_UNDEFINED;
5103
157
    else
5104
157
      return COFF_SYMBOL_COMMON;
5105
578
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.67k
      return COFF_SYMBOL_GLOBAL;
5111
5112
367
    default:
5113
367
      break;
5114
3.62k
    }
5115
5116
367
#ifdef COFF_WITH_PE
5117
367
  if (syment->n_sclass == C_STAT)
5118
290
    {
5119
290
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
3
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
287
      return COFF_SYMBOL_LOCAL;
5144
290
    }
5145
5146
77
  if (syment->n_sclass == C_SECTION)
5147
15
    {
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
15
      syment->n_value = 0;
5152
15
      if (syment->n_scnum == 0)
5153
15
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
15
    }
5156
62
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
62
  if (syment->n_scnum == 0)
5160
31
    {
5161
31
      char buf[SYMNMLEN + 1];
5162
5163
31
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
31
  (_("warning: %pB: local symbol `%s' has no section"),
5166
31
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
31
    }
5168
5169
62
  return COFF_SYMBOL_LOCAL;
5170
77
}
coff-x86_64.c:coff_classify_symbol
Line
Count
Source
5076
2.54k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.54k
  switch (syment->n_sclass)
5080
2.54k
    {
5081
1.90k
    case C_EXT:
5082
2.35k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.35k
#ifdef C_SYSTEM
5094
2.54k
    case C_SYSTEM:
5095
2.54k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
2.54k
      if (syment->n_scnum == 0)
5100
548
  {
5101
548
    if (syment->n_value == 0)
5102
101
      return COFF_SYMBOL_UNDEFINED;
5103
447
    else
5104
447
      return COFF_SYMBOL_COMMON;
5105
548
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.00k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
2.54k
    }
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
2.54k
}
coff64-rs6000.c:coff_classify_symbol
Line
Count
Source
5076
6.88k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
6.88k
  switch (syment->n_sclass)
5080
6.88k
    {
5081
4.78k
    case C_EXT:
5082
4.96k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
4.96k
#ifdef RS6000COFF_C
5088
5.20k
    case C_HIDEXT:
5089
5.20k
#ifndef AIX_WEAK_SUPPORT
5090
6.44k
    case C_AIX_WEAKEXT:
5091
6.44k
#endif
5092
6.44k
#endif
5093
6.44k
#ifdef C_SYSTEM
5094
6.88k
    case C_SYSTEM:
5095
6.88k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
6.88k
      if (syment->n_scnum == 0)
5100
1.47k
  {
5101
1.47k
    if (syment->n_value == 0)
5102
307
      return COFF_SYMBOL_UNDEFINED;
5103
1.17k
    else
5104
1.17k
      return COFF_SYMBOL_COMMON;
5105
1.47k
  }
5106
5.41k
#ifdef RS6000COFF_C
5107
5.41k
      if (syment->n_sclass == C_HIDEXT)
5108
212
  return COFF_SYMBOL_LOCAL;
5109
5.19k
#endif
5110
5.19k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
6.88k
    }
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.88k
}
pe-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
2.80k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.80k
  switch (syment->n_sclass)
5080
2.80k
    {
5081
1.14k
    case C_EXT:
5082
1.31k
    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.31k
#ifdef C_SYSTEM
5094
1.46k
    case C_SYSTEM:
5095
1.46k
#endif
5096
1.46k
#ifdef COFF_WITH_PE
5097
2.66k
    case C_NT_WEAK:
5098
2.66k
#endif
5099
2.66k
      if (syment->n_scnum == 0)
5100
313
  {
5101
313
    if (syment->n_value == 0)
5102
77
      return COFF_SYMBOL_UNDEFINED;
5103
236
    else
5104
236
      return COFF_SYMBOL_COMMON;
5105
313
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.34k
      return COFF_SYMBOL_GLOBAL;
5111
5112
140
    default:
5113
140
      break;
5114
2.80k
    }
5115
5116
140
#ifdef COFF_WITH_PE
5117
140
  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
140
  if (syment->n_sclass == C_SECTION)
5147
11
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
11
      syment->n_value = 0;
5152
11
      if (syment->n_scnum == 0)
5153
11
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
11
    }
5156
129
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
129
  if (syment->n_scnum == 0)
5160
129
    {
5161
129
      char buf[SYMNMLEN + 1];
5162
5163
129
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
129
  (_("warning: %pB: local symbol `%s' has no section"),
5166
129
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
129
    }
5168
5169
129
  return COFF_SYMBOL_LOCAL;
5170
140
}
pei-aarch64.c:coff_classify_symbol
Line
Count
Source
5076
2.53k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.53k
  switch (syment->n_sclass)
5080
2.53k
    {
5081
1.49k
    case C_EXT:
5082
1.59k
    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.59k
#ifdef C_SYSTEM
5094
1.82k
    case C_SYSTEM:
5095
1.82k
#endif
5096
1.82k
#ifdef COFF_WITH_PE
5097
2.50k
    case C_NT_WEAK:
5098
2.50k
#endif
5099
2.50k
      if (syment->n_scnum == 0)
5100
626
  {
5101
626
    if (syment->n_value == 0)
5102
65
      return COFF_SYMBOL_UNDEFINED;
5103
561
    else
5104
561
      return COFF_SYMBOL_COMMON;
5105
626
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.88k
      return COFF_SYMBOL_GLOBAL;
5111
5112
25
    default:
5113
25
      break;
5114
2.53k
    }
5115
5116
25
#ifdef COFF_WITH_PE
5117
25
  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
25
  if (syment->n_sclass == C_SECTION)
5147
25
    {
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
25
      syment->n_value = 0;
5152
25
      if (syment->n_scnum == 0)
5153
25
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
25
    }
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
25
}
pei-ia64.c:coff_classify_symbol
Line
Count
Source
5076
2.67k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.67k
  switch (syment->n_sclass)
5080
2.67k
    {
5081
1.56k
    case C_EXT:
5082
1.69k
    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.69k
#ifdef C_SYSTEM
5094
1.74k
    case C_SYSTEM:
5095
1.74k
#endif
5096
1.74k
#ifdef COFF_WITH_PE
5097
2.64k
    case C_NT_WEAK:
5098
2.64k
#endif
5099
2.64k
      if (syment->n_scnum == 0)
5100
332
  {
5101
332
    if (syment->n_value == 0)
5102
49
      return COFF_SYMBOL_UNDEFINED;
5103
283
    else
5104
283
      return COFF_SYMBOL_COMMON;
5105
332
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.31k
      return COFF_SYMBOL_GLOBAL;
5111
5112
31
    default:
5113
31
      break;
5114
2.67k
    }
5115
5116
31
#ifdef COFF_WITH_PE
5117
31
  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
31
  if (syment->n_sclass == C_SECTION)
5147
31
    {
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
31
      syment->n_value = 0;
5152
31
      if (syment->n_scnum == 0)
5153
31
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
31
    }
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
31
}
pei-loongarch64.c:coff_classify_symbol
Line
Count
Source
5076
2.29k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.29k
  switch (syment->n_sclass)
5080
2.29k
    {
5081
1.36k
    case C_EXT:
5082
1.53k
    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.53k
#ifdef C_SYSTEM
5094
1.75k
    case C_SYSTEM:
5095
1.75k
#endif
5096
1.75k
#ifdef COFF_WITH_PE
5097
2.28k
    case C_NT_WEAK:
5098
2.28k
#endif
5099
2.28k
      if (syment->n_scnum == 0)
5100
669
  {
5101
669
    if (syment->n_value == 0)
5102
208
      return COFF_SYMBOL_UNDEFINED;
5103
461
    else
5104
461
      return COFF_SYMBOL_COMMON;
5105
669
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.61k
      return COFF_SYMBOL_GLOBAL;
5111
5112
13
    default:
5113
13
      break;
5114
2.29k
    }
5115
5116
13
#ifdef COFF_WITH_PE
5117
13
  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
13
  if (syment->n_sclass == C_SECTION)
5147
13
    {
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
13
      syment->n_value = 0;
5152
13
      if (syment->n_scnum == 0)
5153
13
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
13
    }
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
13
}
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
7.50k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
7.50k
  switch (syment->n_sclass)
5080
7.50k
    {
5081
5.53k
    case C_EXT:
5082
5.84k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
5.84k
#ifdef RS6000COFF_C
5088
6.24k
    case C_HIDEXT:
5089
6.24k
#ifndef AIX_WEAK_SUPPORT
5090
7.19k
    case C_AIX_WEAKEXT:
5091
7.19k
#endif
5092
7.19k
#endif
5093
7.19k
#ifdef C_SYSTEM
5094
7.50k
    case C_SYSTEM:
5095
7.50k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
7.50k
      if (syment->n_scnum == 0)
5100
1.10k
  {
5101
1.10k
    if (syment->n_value == 0)
5102
102
      return COFF_SYMBOL_UNDEFINED;
5103
1.00k
    else
5104
1.00k
      return COFF_SYMBOL_COMMON;
5105
1.10k
  }
5106
6.39k
#ifdef RS6000COFF_C
5107
6.39k
      if (syment->n_sclass == C_HIDEXT)
5108
375
  return COFF_SYMBOL_LOCAL;
5109
6.02k
#endif
5110
6.02k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
7.50k
    }
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.50k
}
coff-sh.c:coff_classify_symbol
Line
Count
Source
5076
2.15k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.15k
  switch (syment->n_sclass)
5080
2.15k
    {
5081
1.77k
    case C_EXT:
5082
1.93k
    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.93k
#ifdef C_SYSTEM
5094
2.15k
    case C_SYSTEM:
5095
2.15k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
2.15k
      if (syment->n_scnum == 0)
5100
357
  {
5101
357
    if (syment->n_value == 0)
5102
115
      return COFF_SYMBOL_UNDEFINED;
5103
242
    else
5104
242
      return COFF_SYMBOL_COMMON;
5105
357
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.79k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
2.15k
    }
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
2.15k
}
Unexecuted instantiation: coff-stgo32.c:coff_classify_symbol
coff-tic30.c:coff_classify_symbol
Line
Count
Source
5076
1.42k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.42k
  switch (syment->n_sclass)
5080
1.42k
    {
5081
1.10k
    case C_EXT:
5082
1.30k
    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.30k
#ifdef C_SYSTEM
5094
1.42k
    case C_SYSTEM:
5095
1.42k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
1.42k
      if (syment->n_scnum == 0)
5100
236
  {
5101
236
    if (syment->n_value == 0)
5102
56
      return COFF_SYMBOL_UNDEFINED;
5103
180
    else
5104
180
      return COFF_SYMBOL_COMMON;
5105
236
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.19k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
1.42k
    }
5115
5116
#ifdef COFF_WITH_PE
5117
  if (syment->n_sclass == C_STAT)
5118
    {
5119
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
      return COFF_SYMBOL_LOCAL;
5144
    }
5145
5146
  if (syment->n_sclass == C_SECTION)
5147
    {
5148
      /* In some cases in a DLL generated by the Microsoft linker, the
5149
   n_value field will contain garbage.  FIXME: This should
5150
   probably be handled by the swapping function instead.  */
5151
      syment->n_value = 0;
5152
      if (syment->n_scnum == 0)
5153
  return COFF_SYMBOL_UNDEFINED;
5154
      return COFF_SYMBOL_PE_SECTION;
5155
    }
5156
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
0
  if (syment->n_scnum == 0)
5160
0
    {
5161
0
      char buf[SYMNMLEN + 1];
5162
5163
0
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
0
  (_("warning: %pB: local symbol `%s' has no section"),
5166
0
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
0
    }
5168
5169
0
  return COFF_SYMBOL_LOCAL;
5170
1.42k
}
Unexecuted instantiation: coff-tic4x.c:coff_classify_symbol
coff-tic54x.c:coff_classify_symbol
Line
Count
Source
5076
3.97k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3.97k
  switch (syment->n_sclass)
5080
3.97k
    {
5081
3.26k
    case C_EXT:
5082
3.62k
    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.62k
#ifdef C_SYSTEM
5094
3.97k
    case C_SYSTEM:
5095
3.97k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
3.97k
      if (syment->n_scnum == 0)
5100
724
  {
5101
724
    if (syment->n_value == 0)
5102
184
      return COFF_SYMBOL_UNDEFINED;
5103
540
    else
5104
540
      return COFF_SYMBOL_COMMON;
5105
724
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
3.24k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
3.97k
    }
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.97k
}
coff-z80.c:coff_classify_symbol
Line
Count
Source
5076
2.51k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.51k
  switch (syment->n_sclass)
5080
2.51k
    {
5081
2.22k
    case C_EXT:
5082
2.39k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.39k
#ifdef C_SYSTEM
5094
2.51k
    case C_SYSTEM:
5095
2.51k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
2.51k
      if (syment->n_scnum == 0)
5100
315
  {
5101
315
    if (syment->n_value == 0)
5102
114
      return COFF_SYMBOL_UNDEFINED;
5103
201
    else
5104
201
      return COFF_SYMBOL_COMMON;
5105
315
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
2.20k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
2.51k
    }
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
2.51k
}
coff-z8k.c:coff_classify_symbol
Line
Count
Source
5076
2.45k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
2.45k
  switch (syment->n_sclass)
5080
2.45k
    {
5081
2.11k
    case C_EXT:
5082
2.30k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.30k
#ifdef C_SYSTEM
5094
2.45k
    case C_SYSTEM:
5095
2.45k
#endif
5096
#ifdef COFF_WITH_PE
5097
    case C_NT_WEAK:
5098
#endif
5099
2.45k
      if (syment->n_scnum == 0)
5100
548
  {
5101
548
    if (syment->n_value == 0)
5102
71
      return COFF_SYMBOL_UNDEFINED;
5103
477
    else
5104
477
      return COFF_SYMBOL_COMMON;
5105
548
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.90k
      return COFF_SYMBOL_GLOBAL;
5111
5112
0
    default:
5113
0
      break;
5114
2.45k
    }
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
2.45k
}
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.97k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4.97k
  switch (syment->n_sclass)
5080
4.97k
    {
5081
3.13k
    case C_EXT:
5082
3.30k
    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.30k
#ifdef C_SYSTEM
5094
3.52k
    case C_SYSTEM:
5095
3.52k
#endif
5096
3.52k
#ifdef COFF_WITH_PE
5097
4.76k
    case C_NT_WEAK:
5098
4.76k
#endif
5099
4.76k
      if (syment->n_scnum == 0)
5100
526
  {
5101
526
    if (syment->n_value == 0)
5102
115
      return COFF_SYMBOL_UNDEFINED;
5103
411
    else
5104
411
      return COFF_SYMBOL_COMMON;
5105
526
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
4.23k
      return COFF_SYMBOL_GLOBAL;
5111
5112
210
    default:
5113
210
      break;
5114
4.97k
    }
5115
5116
210
#ifdef COFF_WITH_PE
5117
210
  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
210
  if (syment->n_sclass == C_SECTION)
5147
51
    {
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
51
      syment->n_value = 0;
5152
51
      if (syment->n_scnum == 0)
5153
51
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
51
    }
5156
159
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
159
  if (syment->n_scnum == 0)
5160
158
    {
5161
158
      char buf[SYMNMLEN + 1];
5162
5163
158
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
158
  (_("warning: %pB: local symbol `%s' has no section"),
5166
158
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
158
    }
5168
5169
159
  return COFF_SYMBOL_LOCAL;
5170
210
}
pe-mcore.c:coff_classify_symbol
Line
Count
Source
5076
16.4k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
16.4k
  switch (syment->n_sclass)
5080
16.4k
    {
5081
3.38k
    case C_EXT:
5082
3.62k
    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.62k
#ifdef C_SYSTEM
5094
4.10k
    case C_SYSTEM:
5095
4.10k
#endif
5096
4.10k
#ifdef COFF_WITH_PE
5097
5.39k
    case C_NT_WEAK:
5098
5.39k
#endif
5099
5.39k
      if (syment->n_scnum == 0)
5100
377
  {
5101
377
    if (syment->n_value == 0)
5102
82
      return COFF_SYMBOL_UNDEFINED;
5103
295
    else
5104
295
      return COFF_SYMBOL_COMMON;
5105
377
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
5.01k
      return COFF_SYMBOL_GLOBAL;
5111
5112
11.0k
    default:
5113
11.0k
      break;
5114
16.4k
    }
5115
5116
11.0k
#ifdef COFF_WITH_PE
5117
11.0k
  if (syment->n_sclass == C_STAT)
5118
128
    {
5119
128
      if (syment->n_scnum == 0)
5120
  /* The Microsoft compiler sometimes generates these if a
5121
     small static function is inlined every time it is used.
5122
     The function is discarded, but the symbol table entry
5123
     remains.  */
5124
128
  return COFF_SYMBOL_LOCAL;
5125
5126
#ifdef STRICT_PE_FORMAT
5127
      /* This is correct for Microsoft generated objects, but it
5128
   breaks gas generated objects.  */
5129
      if (syment->n_value == 0)
5130
  {
5131
    const asection *sec;
5132
    const char *name;
5133
    char buf[SYMNMLEN + 1];
5134
5135
    name = _bfd_coff_internal_syment_name (abfd, syment, buf);
5136
    sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
5137
    if (sec != NULL && name != NULL
5138
        && (strcmp (bfd_section_name (sec), name) == 0))
5139
      return COFF_SYMBOL_PE_SECTION;
5140
  }
5141
#endif
5142
5143
0
      return COFF_SYMBOL_LOCAL;
5144
128
    }
5145
5146
10.9k
  if (syment->n_sclass == C_SECTION)
5147
46
    {
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
46
      syment->n_value = 0;
5152
46
      if (syment->n_scnum == 0)
5153
46
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
46
    }
5156
10.8k
#endif /* COFF_WITH_PE */
5157
5158
  /* If it is not a global symbol, we presume it is a local symbol.  */
5159
10.8k
  if (syment->n_scnum == 0)
5160
10.8k
    {
5161
10.8k
      char buf[SYMNMLEN + 1];
5162
5163
10.8k
      _bfd_error_handler
5164
  /* xgettext:c-format */
5165
10.8k
  (_("warning: %pB: local symbol `%s' has no section"),
5166
10.8k
   abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
5167
10.8k
    }
5168
5169
10.8k
  return COFF_SYMBOL_LOCAL;
5170
10.9k
}
pe-sh.c:coff_classify_symbol
Line
Count
Source
5076
5.08k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
5.08k
  switch (syment->n_sclass)
5080
5.08k
    {
5081
4.31k
    case C_EXT:
5082
4.45k
    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.45k
#ifdef C_SYSTEM
5094
4.62k
    case C_SYSTEM:
5095
4.62k
#endif
5096
4.62k
#ifdef COFF_WITH_PE
5097
5.06k
    case C_NT_WEAK:
5098
5.06k
#endif
5099
5.06k
      if (syment->n_scnum == 0)
5100
370
  {
5101
370
    if (syment->n_value == 0)
5102
111
      return COFF_SYMBOL_UNDEFINED;
5103
259
    else
5104
259
      return COFF_SYMBOL_COMMON;
5105
370
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
4.69k
      return COFF_SYMBOL_GLOBAL;
5111
5112
18
    default:
5113
18
      break;
5114
5.08k
    }
5115
5116
18
#ifdef COFF_WITH_PE
5117
18
  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
18
  if (syment->n_sclass == C_SECTION)
5147
18
    {
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
18
      syment->n_value = 0;
5152
18
      if (syment->n_scnum == 0)
5153
18
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
18
    }
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
18
}
pei-arm-wince.c:coff_classify_symbol
Line
Count
Source
5076
1.20k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.20k
  switch (syment->n_sclass)
5080
1.20k
    {
5081
514
    case C_EXT:
5082
535
    case C_WEAKEXT:
5083
535
#ifdef ARM
5084
554
    case C_THUMBEXT:
5085
557
    case C_THUMBEXTFUNC:
5086
557
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
557
#ifdef C_SYSTEM
5094
667
    case C_SYSTEM:
5095
667
#endif
5096
667
#ifdef COFF_WITH_PE
5097
1.18k
    case C_NT_WEAK:
5098
1.18k
#endif
5099
1.18k
      if (syment->n_scnum == 0)
5100
136
  {
5101
136
    if (syment->n_value == 0)
5102
47
      return COFF_SYMBOL_UNDEFINED;
5103
89
    else
5104
89
      return COFF_SYMBOL_COMMON;
5105
136
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.04k
      return COFF_SYMBOL_GLOBAL;
5111
5112
15
    default:
5113
15
      break;
5114
1.20k
    }
5115
5116
15
#ifdef COFF_WITH_PE
5117
15
  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
15
  if (syment->n_sclass == C_SECTION)
5147
15
    {
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
15
      syment->n_value = 0;
5152
15
      if (syment->n_scnum == 0)
5153
15
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
15
    }
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
15
}
pei-arm.c:coff_classify_symbol
Line
Count
Source
5076
1.31k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
1.31k
  switch (syment->n_sclass)
5080
1.31k
    {
5081
443
    case C_EXT:
5082
469
    case C_WEAKEXT:
5083
469
#ifdef ARM
5084
496
    case C_THUMBEXT:
5085
548
    case C_THUMBEXTFUNC:
5086
548
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
548
#ifdef C_SYSTEM
5094
650
    case C_SYSTEM:
5095
650
#endif
5096
650
#ifdef COFF_WITH_PE
5097
1.28k
    case C_NT_WEAK:
5098
1.28k
#endif
5099
1.28k
      if (syment->n_scnum == 0)
5100
138
  {
5101
138
    if (syment->n_value == 0)
5102
39
      return COFF_SYMBOL_UNDEFINED;
5103
99
    else
5104
99
      return COFF_SYMBOL_COMMON;
5105
138
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
1.14k
      return COFF_SYMBOL_GLOBAL;
5111
5112
28
    default:
5113
28
      break;
5114
1.31k
    }
5115
5116
28
#ifdef COFF_WITH_PE
5117
28
  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
28
  if (syment->n_sclass == C_SECTION)
5147
28
    {
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
28
      syment->n_value = 0;
5152
28
      if (syment->n_scnum == 0)
5153
28
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
28
    }
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
28
}
pei-mcore.c:coff_classify_symbol
Line
Count
Source
5076
4.10k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
4.10k
  switch (syment->n_sclass)
5080
4.10k
    {
5081
3.62k
    case C_EXT:
5082
3.66k
    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.66k
#ifdef C_SYSTEM
5094
3.74k
    case C_SYSTEM:
5095
3.74k
#endif
5096
3.74k
#ifdef COFF_WITH_PE
5097
4.07k
    case C_NT_WEAK:
5098
4.07k
#endif
5099
4.07k
      if (syment->n_scnum == 0)
5100
122
  {
5101
122
    if (syment->n_value == 0)
5102
64
      return COFF_SYMBOL_UNDEFINED;
5103
58
    else
5104
58
      return COFF_SYMBOL_COMMON;
5105
122
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
3.95k
      return COFF_SYMBOL_GLOBAL;
5111
5112
27
    default:
5113
27
      break;
5114
4.10k
    }
5115
5116
27
#ifdef COFF_WITH_PE
5117
27
  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
27
  if (syment->n_sclass == C_SECTION)
5147
27
    {
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
27
      syment->n_value = 0;
5152
27
      if (syment->n_scnum == 0)
5153
27
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
27
    }
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
27
}
pei-sh.c:coff_classify_symbol
Line
Count
Source
5076
3.40k
{
5077
  /* FIXME: This partially duplicates the switch in
5078
     coff_slurp_symbol_table.  */
5079
3.40k
  switch (syment->n_sclass)
5080
3.40k
    {
5081
2.55k
    case C_EXT:
5082
2.68k
    case C_WEAKEXT:
5083
#ifdef ARM
5084
    case C_THUMBEXT:
5085
    case C_THUMBEXTFUNC:
5086
#endif
5087
#ifdef RS6000COFF_C
5088
    case C_HIDEXT:
5089
#ifndef AIX_WEAK_SUPPORT
5090
    case C_AIX_WEAKEXT:
5091
#endif
5092
#endif
5093
2.68k
#ifdef C_SYSTEM
5094
2.89k
    case C_SYSTEM:
5095
2.89k
#endif
5096
2.89k
#ifdef COFF_WITH_PE
5097
3.38k
    case C_NT_WEAK:
5098
3.38k
#endif
5099
3.38k
      if (syment->n_scnum == 0)
5100
292
  {
5101
292
    if (syment->n_value == 0)
5102
77
      return COFF_SYMBOL_UNDEFINED;
5103
215
    else
5104
215
      return COFF_SYMBOL_COMMON;
5105
292
  }
5106
#ifdef RS6000COFF_C
5107
      if (syment->n_sclass == C_HIDEXT)
5108
  return COFF_SYMBOL_LOCAL;
5109
#endif
5110
3.08k
      return COFF_SYMBOL_GLOBAL;
5111
5112
24
    default:
5113
24
      break;
5114
3.40k
    }
5115
5116
24
#ifdef COFF_WITH_PE
5117
24
  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
24
  if (syment->n_sclass == C_SECTION)
5147
24
    {
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
24
      syment->n_value = 0;
5152
24
      if (syment->n_scnum == 0)
5153
24
  return COFF_SYMBOL_UNDEFINED;
5154
0
      return COFF_SYMBOL_PE_SECTION;
5155
24
    }
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
24
}
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
6.11k
#define COFF_PE_ADDEND_BIAS(ptr) 0 /* Symbol value not stored in raw data.  */
5208
#else
5209
234
#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
1.34k
  {               \
5215
1.34k
    coff_symbol_type *coffsym = NULL;       \
5216
1.34k
                \
5217
1.34k
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
5218
1.34k
      coffsym = (obj_symbols (abfd)       \
5219
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
5220
1.34k
    else if (ptr)           \
5221
1.34k
      coffsym = coff_symbol_from (ptr);       \
5222
1.34k
    if (coffsym != NULL            \
5223
1.34k
  && coffsym->native->is_sym        \
5224
1.34k
  && coffsym->native->u.syment.n_scnum == 0)   \
5225
1.34k
      cache_ptr->addend = 0;         \
5226
1.34k
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
5227
856
       && ptr->section != NULL)       \
5228
856
      cache_ptr->addend = - (ptr->section->vma      \
5229
511
           + COFF_PE_ADDEND_BIAS (ptr)); \
5230
856
    else              \
5231
856
      cache_ptr->addend = 0;         \
5232
1.34k
  }
5233
#endif
5234
5235
static bool
5236
coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
5237
18.5k
{
5238
18.5k
  bfd_byte *native_relocs;
5239
18.5k
  arelent *reloc_cache;
5240
18.5k
  arelent *cache_ptr;
5241
18.5k
  unsigned int idx;
5242
18.5k
  size_t amt;
5243
5244
18.5k
  if (asect->relocation)
5245
263
    return true;
5246
18.2k
  if (asect->reloc_count == 0)
5247
2.03k
    return true;
5248
16.2k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
16.2k
  if (!coff_slurp_symbol_table (abfd))
5251
2.87k
    return false;
5252
5253
13.3k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
13.3k
               asect->reloc_count,
5255
13.3k
               bfd_coff_relsz (abfd));
5256
13.3k
  if (native_relocs == NULL)
5257
7.43k
    return false;
5258
5259
5.94k
  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.94k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
5.94k
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
143k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
142k
    {
5273
142k
      struct internal_reloc dst;
5274
142k
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
142k
      cache_ptr = reloc_cache + idx;
5280
142k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
142k
      dst.r_offset = 0;
5283
142k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
12.1k
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
      cache_ptr->address = dst.r_vaddr;
5289
5290
130k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
128k
  {
5292
128k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
3.34k
      {
5294
3.34k
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
3.34k
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
3.34k
     abfd, dst.r_symndx);
5298
3.34k
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
3.34k
        ptr = NULL;
5300
3.34k
      }
5301
124k
    else
5302
124k
      {
5303
124k
        cache_ptr->sym_ptr_ptr = (symbols
5304
124k
          + obj_convert (abfd)[dst.r_symndx]);
5305
124k
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
124k
      }
5307
128k
  }
5308
2.54k
      else
5309
2.54k
  {
5310
2.54k
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
2.54k
    ptr = NULL;
5312
2.54k
  }
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
130k
      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
130k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
#endif  /* RELOC_PROCESSING */
5331
5332
142k
      if (cache_ptr->howto == NULL)
5333
5.19k
  {
5334
5.19k
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
5.19k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
5.19k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
5.19k
    bfd_set_error (bfd_error_bad_value);
5339
5.19k
    free (native_relocs);
5340
5.19k
    return false;
5341
5.19k
  }
5342
142k
    }
5343
5344
752
  free (native_relocs);
5345
752
  asect->relocation = reloc_cache;
5346
752
  return true;
5347
5.94k
}
pei-i386.c:coff_slurp_reloc_table
Line
Count
Source
5237
38
{
5238
38
  bfd_byte *native_relocs;
5239
38
  arelent *reloc_cache;
5240
38
  arelent *cache_ptr;
5241
38
  unsigned int idx;
5242
38
  size_t amt;
5243
5244
38
  if (asect->relocation)
5245
25
    return true;
5246
13
  if (asect->reloc_count == 0)
5247
13
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pe-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
229
{
5238
229
  bfd_byte *native_relocs;
5239
229
  arelent *reloc_cache;
5240
229
  arelent *cache_ptr;
5241
229
  unsigned int idx;
5242
229
  size_t amt;
5243
5244
229
  if (asect->relocation)
5245
7
    return true;
5246
222
  if (asect->reloc_count == 0)
5247
17
    return true;
5248
205
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
205
  if (!coff_slurp_symbol_table (abfd))
5251
27
    return false;
5252
5253
178
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
178
               asect->reloc_count,
5255
178
               bfd_coff_relsz (abfd));
5256
178
  if (native_relocs == NULL)
5257
26
    return false;
5258
5259
152
  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
152
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
152
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
1.50k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
1.45k
    {
5273
1.45k
      struct internal_reloc dst;
5274
1.45k
      void *src;
5275
1.45k
#ifndef RELOC_PROCESSING
5276
1.45k
      asymbol *ptr;
5277
1.45k
#endif
5278
5279
1.45k
      cache_ptr = reloc_cache + idx;
5280
1.45k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
1.45k
      dst.r_offset = 0;
5283
1.45k
      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.45k
      cache_ptr->address = dst.r_vaddr;
5289
5290
1.45k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
1.41k
  {
5292
1.41k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
658
      {
5294
658
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
658
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
658
     abfd, dst.r_symndx);
5298
658
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
658
        ptr = NULL;
5300
658
      }
5301
752
    else
5302
752
      {
5303
752
        cache_ptr->sym_ptr_ptr = (symbols
5304
752
          + obj_convert (abfd)[dst.r_symndx]);
5305
752
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
752
      }
5307
1.41k
  }
5308
40
      else
5309
40
  {
5310
40
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
40
    ptr = NULL;
5312
40
  }
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.45k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
1.45k
      (void) ptr;
5324
5325
1.45k
      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.45k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
1.45k
#endif  /* RELOC_PROCESSING */
5331
5332
1.45k
      if (cache_ptr->howto == NULL)
5333
93
  {
5334
93
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
93
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
93
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
93
    bfd_set_error (bfd_error_bad_value);
5339
93
    free (native_relocs);
5340
93
    return false;
5341
93
  }
5342
1.45k
    }
5343
5344
59
  free (native_relocs);
5345
59
  asect->relocation = reloc_cache;
5346
59
  return true;
5347
152
}
pei-x86_64.c:coff_slurp_reloc_table
Line
Count
Source
5237
87
{
5238
87
  bfd_byte *native_relocs;
5239
87
  arelent *reloc_cache;
5240
87
  arelent *cache_ptr;
5241
87
  unsigned int idx;
5242
87
  size_t amt;
5243
5244
87
  if (asect->relocation)
5245
15
    return true;
5246
72
  if (asect->reloc_count == 0)
5247
72
    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
1.80k
{
5238
1.80k
  bfd_byte *native_relocs;
5239
1.80k
  arelent *reloc_cache;
5240
1.80k
  arelent *cache_ptr;
5241
1.80k
  unsigned int idx;
5242
1.80k
  size_t amt;
5243
5244
1.80k
  if (asect->relocation)
5245
12
    return true;
5246
1.79k
  if (asect->reloc_count == 0)
5247
900
    return true;
5248
896
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
896
  if (!coff_slurp_symbol_table (abfd))
5251
384
    return false;
5252
5253
512
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
512
               asect->reloc_count,
5255
512
               bfd_coff_relsz (abfd));
5256
512
  if (native_relocs == NULL)
5257
261
    return false;
5258
5259
251
  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
251
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
251
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
2.18k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
2.07k
    {
5273
2.07k
      struct internal_reloc dst;
5274
2.07k
      void *src;
5275
2.07k
#ifndef RELOC_PROCESSING
5276
2.07k
      asymbol *ptr;
5277
2.07k
#endif
5278
5279
2.07k
      cache_ptr = reloc_cache + idx;
5280
2.07k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
2.07k
      dst.r_offset = 0;
5283
2.07k
      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
2.07k
      cache_ptr->address = dst.r_vaddr;
5289
5290
2.07k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
1.76k
  {
5292
1.76k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
409
      {
5294
409
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
409
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
409
     abfd, dst.r_symndx);
5298
409
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
409
        ptr = NULL;
5300
409
      }
5301
1.35k
    else
5302
1.35k
      {
5303
1.35k
        cache_ptr->sym_ptr_ptr = (symbols
5304
1.35k
          + obj_convert (abfd)[dst.r_symndx]);
5305
1.35k
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
1.35k
      }
5307
1.76k
  }
5308
313
      else
5309
313
  {
5310
313
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
313
    ptr = NULL;
5312
313
  }
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.07k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
2.07k
      (void) ptr;
5324
5325
2.07k
      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.07k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
2.07k
#endif  /* RELOC_PROCESSING */
5331
5332
2.07k
      if (cache_ptr->howto == NULL)
5333
144
  {
5334
144
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
144
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
144
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
144
    bfd_set_error (bfd_error_bad_value);
5339
144
    free (native_relocs);
5340
144
    return false;
5341
144
  }
5342
2.07k
    }
5343
5344
107
  free (native_relocs);
5345
107
  asect->relocation = reloc_cache;
5346
107
  return true;
5347
251
}
coff64-rs6000.c:coff_slurp_reloc_table
Line
Count
Source
5237
110
{
5238
110
  bfd_byte *native_relocs;
5239
110
  arelent *reloc_cache;
5240
110
  arelent *cache_ptr;
5241
110
  unsigned int idx;
5242
110
  size_t amt;
5243
5244
110
  if (asect->relocation)
5245
0
    return true;
5246
110
  if (asect->reloc_count == 0)
5247
3
    return true;
5248
107
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
107
  if (!coff_slurp_symbol_table (abfd))
5251
47
    return false;
5252
5253
60
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
60
               asect->reloc_count,
5255
60
               bfd_coff_relsz (abfd));
5256
60
  if (native_relocs == NULL)
5257
51
    return false;
5258
5259
9
  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
9
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
9
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
51
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
42
    {
5273
42
      struct internal_reloc dst;
5274
42
      void *src;
5275
42
#ifndef RELOC_PROCESSING
5276
42
      asymbol *ptr;
5277
42
#endif
5278
5279
42
      cache_ptr = reloc_cache + idx;
5280
42
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
42
      dst.r_offset = 0;
5283
42
      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
42
      cache_ptr->address = dst.r_vaddr;
5289
5290
42
      if (dst.r_symndx != -1 && symbols != NULL)
5291
42
  {
5292
42
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
36
      {
5294
36
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
36
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
36
     abfd, dst.r_symndx);
5298
36
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
36
        ptr = NULL;
5300
36
      }
5301
6
    else
5302
6
      {
5303
6
        cache_ptr->sym_ptr_ptr = (symbols
5304
6
          + obj_convert (abfd)[dst.r_symndx]);
5305
6
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
6
      }
5307
42
  }
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
42
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
42
      (void) ptr;
5324
5325
42
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
42
      RTYPE2HOWTO (cache_ptr, &dst);
5330
42
#endif  /* RELOC_PROCESSING */
5331
5332
42
      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
42
    }
5343
5344
9
  free (native_relocs);
5345
9
  asect->relocation = reloc_cache;
5346
9
  return true;
5347
9
}
pe-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
663
{
5238
663
  bfd_byte *native_relocs;
5239
663
  arelent *reloc_cache;
5240
663
  arelent *cache_ptr;
5241
663
  unsigned int idx;
5242
663
  size_t amt;
5243
5244
663
  if (asect->relocation)
5245
3
    return true;
5246
660
  if (asect->reloc_count == 0)
5247
8
    return true;
5248
652
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
652
  if (!coff_slurp_symbol_table (abfd))
5251
45
    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
131
    return false;
5258
5259
476
  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
476
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
476
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
9.88k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
9.64k
    {
5273
9.64k
      struct internal_reloc dst;
5274
9.64k
      void *src;
5275
9.64k
#ifndef RELOC_PROCESSING
5276
9.64k
      asymbol *ptr;
5277
9.64k
#endif
5278
5279
9.64k
      cache_ptr = reloc_cache + idx;
5280
9.64k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
9.64k
      dst.r_offset = 0;
5283
9.64k
      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
9.64k
      cache_ptr->address = dst.r_vaddr;
5289
5290
9.64k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
9.59k
  {
5292
9.59k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
588
      {
5294
588
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
588
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
588
     abfd, dst.r_symndx);
5298
588
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
588
        ptr = NULL;
5300
588
      }
5301
9.00k
    else
5302
9.00k
      {
5303
9.00k
        cache_ptr->sym_ptr_ptr = (symbols
5304
9.00k
          + obj_convert (abfd)[dst.r_symndx]);
5305
9.00k
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
9.00k
      }
5307
9.59k
  }
5308
46
      else
5309
46
  {
5310
46
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
46
    ptr = NULL;
5312
46
  }
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
9.64k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
9.64k
      (void) ptr;
5324
5325
9.64k
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
9.64k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
9.64k
#endif  /* RELOC_PROCESSING */
5331
5332
9.64k
      if (cache_ptr->howto == NULL)
5333
227
  {
5334
227
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
227
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
227
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
227
    bfd_set_error (bfd_error_bad_value);
5339
227
    free (native_relocs);
5340
227
    return false;
5341
227
  }
5342
9.64k
    }
5343
5344
249
  free (native_relocs);
5345
249
  asect->relocation = reloc_cache;
5346
249
  return true;
5347
476
}
pei-aarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
13
{
5238
13
  bfd_byte *native_relocs;
5239
13
  arelent *reloc_cache;
5240
13
  arelent *cache_ptr;
5241
13
  unsigned int idx;
5242
13
  size_t amt;
5243
5244
13
  if (asect->relocation)
5245
9
    return true;
5246
4
  if (asect->reloc_count == 0)
5247
4
    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
}
pei-ia64.c:coff_slurp_reloc_table
Line
Count
Source
5237
1
{
5238
1
  bfd_byte *native_relocs;
5239
1
  arelent *reloc_cache;
5240
1
  arelent *cache_ptr;
5241
1
  unsigned int idx;
5242
1
  size_t amt;
5243
5244
1
  if (asect->relocation)
5245
0
    return true;
5246
1
  if (asect->reloc_count == 0)
5247
1
    return true;
5248
0
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
0
  if (!coff_slurp_symbol_table (abfd))
5251
0
    return false;
5252
5253
0
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
0
               asect->reloc_count,
5255
0
               bfd_coff_relsz (abfd));
5256
0
  if (native_relocs == NULL)
5257
0
    return false;
5258
5259
0
  if (_bfd_mul_overflow (asect->reloc_count, sizeof (arelent), &amt))
5260
0
    {
5261
0
      bfd_set_error (bfd_error_file_too_big);
5262
0
      return false;
5263
0
    }
5264
0
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
0
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
0
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
0
    {
5273
0
      struct internal_reloc dst;
5274
0
      void *src;
5275
0
#ifndef RELOC_PROCESSING
5276
0
      asymbol *ptr;
5277
0
#endif
5278
5279
0
      cache_ptr = reloc_cache + idx;
5280
0
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
0
      dst.r_offset = 0;
5283
0
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
#ifdef RELOC_PROCESSING
5286
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
5287
#else
5288
0
      cache_ptr->address = dst.r_vaddr;
5289
5290
0
      if (dst.r_symndx != -1 && symbols != NULL)
5291
0
  {
5292
0
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
0
      {
5294
0
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
0
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
0
     abfd, dst.r_symndx);
5298
0
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
0
        ptr = NULL;
5300
0
      }
5301
0
    else
5302
0
      {
5303
0
        cache_ptr->sym_ptr_ptr = (symbols
5304
0
          + obj_convert (abfd)[dst.r_symndx]);
5305
0
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
0
      }
5307
0
  }
5308
0
      else
5309
0
  {
5310
0
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
0
    ptr = NULL;
5312
0
  }
5313
5314
      /* The symbols definitions that we have read in have been
5315
   relocated as if their sections started at 0. But the offsets
5316
   refering to the symbols in the raw data have not been
5317
   modified, so we have to have a negative addend to compensate.
5318
5319
   Note that symbols which used to be common must be left alone.  */
5320
5321
      /* Calculate any reloc addend by looking at the symbol.  */
5322
0
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
0
      (void) ptr;
5324
5325
0
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
0
      RTYPE2HOWTO (cache_ptr, &dst);
5330
0
#endif  /* RELOC_PROCESSING */
5331
5332
0
      if (cache_ptr->howto == NULL)
5333
0
  {
5334
0
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
0
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
0
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
0
    bfd_set_error (bfd_error_bad_value);
5339
0
    free (native_relocs);
5340
0
    return false;
5341
0
  }
5342
0
    }
5343
5344
0
  free (native_relocs);
5345
0
  asect->relocation = reloc_cache;
5346
0
  return true;
5347
0
}
pei-loongarch64.c:coff_slurp_reloc_table
Line
Count
Source
5237
21
{
5238
21
  bfd_byte *native_relocs;
5239
21
  arelent *reloc_cache;
5240
21
  arelent *cache_ptr;
5241
21
  unsigned int idx;
5242
21
  size_t amt;
5243
5244
21
  if (asect->relocation)
5245
21
    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
213
{
5238
213
  bfd_byte *native_relocs;
5239
213
  arelent *reloc_cache;
5240
213
  arelent *cache_ptr;
5241
213
  unsigned int idx;
5242
213
  size_t amt;
5243
5244
213
  if (asect->relocation)
5245
0
    return true;
5246
213
  if (asect->reloc_count == 0)
5247
128
    return true;
5248
85
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
85
  if (!coff_slurp_symbol_table (abfd))
5251
34
    return false;
5252
5253
51
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
51
               asect->reloc_count,
5255
51
               bfd_coff_relsz (abfd));
5256
51
  if (native_relocs == NULL)
5257
46
    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
12
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
7
    {
5273
7
      struct internal_reloc dst;
5274
7
      void *src;
5275
7
#ifndef RELOC_PROCESSING
5276
7
      asymbol *ptr;
5277
7
#endif
5278
5279
7
      cache_ptr = reloc_cache + idx;
5280
7
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
7
      dst.r_offset = 0;
5283
7
      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
7
      cache_ptr->address = dst.r_vaddr;
5289
5290
7
      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
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
7
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
7
      (void) ptr;
5324
5325
7
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
7
      RTYPE2HOWTO (cache_ptr, &dst);
5330
7
#endif  /* RELOC_PROCESSING */
5331
5332
7
      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
7
    }
5343
5344
5
  free (native_relocs);
5345
5
  asect->relocation = reloc_cache;
5346
5
  return true;
5347
5
}
coff-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
1.16k
{
5238
1.16k
  bfd_byte *native_relocs;
5239
1.16k
  arelent *reloc_cache;
5240
1.16k
  arelent *cache_ptr;
5241
1.16k
  unsigned int idx;
5242
1.16k
  size_t amt;
5243
5244
1.16k
  if (asect->relocation)
5245
2
    return true;
5246
1.16k
  if (asect->reloc_count == 0)
5247
112
    return true;
5248
1.05k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
1.05k
  if (!coff_slurp_symbol_table (abfd))
5251
319
    return false;
5252
5253
736
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
736
               asect->reloc_count,
5255
736
               bfd_coff_relsz (abfd));
5256
736
  if (native_relocs == NULL)
5257
462
    return false;
5258
5259
274
  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
274
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
274
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
3.20k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
3.11k
    {
5273
3.11k
      struct internal_reloc dst;
5274
3.11k
      void *src;
5275
3.11k
#ifndef RELOC_PROCESSING
5276
3.11k
      asymbol *ptr;
5277
3.11k
#endif
5278
5279
3.11k
      cache_ptr = reloc_cache + idx;
5280
3.11k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
3.11k
      dst.r_offset = 0;
5283
3.11k
      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.11k
      cache_ptr->address = dst.r_vaddr;
5289
5290
3.11k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
1.16k
  {
5292
1.16k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
640
      {
5294
640
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
640
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
640
     abfd, dst.r_symndx);
5298
640
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
640
        ptr = NULL;
5300
640
      }
5301
525
    else
5302
525
      {
5303
525
        cache_ptr->sym_ptr_ptr = (symbols
5304
525
          + obj_convert (abfd)[dst.r_symndx]);
5305
525
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
525
      }
5307
1.16k
  }
5308
1.95k
      else
5309
1.95k
  {
5310
1.95k
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
1.95k
    ptr = NULL;
5312
1.95k
  }
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.11k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
3.11k
      (void) ptr;
5324
5325
3.11k
      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.11k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
3.11k
#endif  /* RELOC_PROCESSING */
5331
5332
3.11k
      if (cache_ptr->howto == NULL)
5333
180
  {
5334
180
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
180
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
180
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
180
    bfd_set_error (bfd_error_bad_value);
5339
180
    free (native_relocs);
5340
180
    return false;
5341
180
  }
5342
3.11k
    }
5343
5344
94
  free (native_relocs);
5345
94
  asect->relocation = reloc_cache;
5346
94
  return true;
5347
274
}
Unexecuted instantiation: coff-stgo32.c:coff_slurp_reloc_table
coff-tic30.c:coff_slurp_reloc_table
Line
Count
Source
5237
11.2k
{
5238
11.2k
  bfd_byte *native_relocs;
5239
11.2k
  arelent *reloc_cache;
5240
11.2k
  arelent *cache_ptr;
5241
11.2k
  unsigned int idx;
5242
11.2k
  size_t amt;
5243
5244
11.2k
  if (asect->relocation)
5245
0
    return true;
5246
11.2k
  if (asect->reloc_count == 0)
5247
572
    return true;
5248
10.7k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
10.7k
  if (!coff_slurp_symbol_table (abfd))
5251
874
    return false;
5252
5253
9.84k
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
9.84k
               asect->reloc_count,
5255
9.84k
               bfd_coff_relsz (abfd));
5256
9.84k
  if (native_relocs == NULL)
5257
5.89k
    return false;
5258
5259
3.95k
  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.95k
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
3.95k
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
10.3k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
10.3k
    {
5273
10.3k
      struct internal_reloc dst;
5274
10.3k
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
10.3k
      cache_ptr = reloc_cache + idx;
5280
10.3k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
10.3k
      dst.r_offset = 0;
5283
10.3k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
10.3k
#ifdef RELOC_PROCESSING
5286
10.3k
      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
10.3k
      if (cache_ptr->howto == NULL)
5333
3.93k
  {
5334
3.93k
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
3.93k
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
3.93k
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
3.93k
    bfd_set_error (bfd_error_bad_value);
5339
3.93k
    free (native_relocs);
5340
3.93k
    return false;
5341
3.93k
  }
5342
10.3k
    }
5343
5344
24
  free (native_relocs);
5345
24
  asect->relocation = reloc_cache;
5346
24
  return true;
5347
3.95k
}
Unexecuted instantiation: coff-tic4x.c:coff_slurp_reloc_table
coff-tic54x.c:coff_slurp_reloc_table
Line
Count
Source
5237
1.42k
{
5238
1.42k
  bfd_byte *native_relocs;
5239
1.42k
  arelent *reloc_cache;
5240
1.42k
  arelent *cache_ptr;
5241
1.42k
  unsigned int idx;
5242
1.42k
  size_t amt;
5243
5244
1.42k
  if (asect->relocation)
5245
0
    return true;
5246
1.42k
  if (asect->reloc_count == 0)
5247
134
    return true;
5248
1.29k
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
1.29k
  if (!coff_slurp_symbol_table (abfd))
5251
783
    return false;
5252
5253
512
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
512
               asect->reloc_count,
5255
512
               bfd_coff_relsz (abfd));
5256
512
  if (native_relocs == NULL)
5257
223
    return false;
5258
5259
289
  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
289
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
289
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
372
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
343
    {
5273
343
      struct internal_reloc dst;
5274
343
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
343
      cache_ptr = reloc_cache + idx;
5280
343
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
343
      dst.r_offset = 0;
5283
343
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
343
#ifdef RELOC_PROCESSING
5286
343
      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
343
      if (cache_ptr->howto == NULL)
5333
260
  {
5334
260
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
260
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
260
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
260
    bfd_set_error (bfd_error_bad_value);
5339
260
    free (native_relocs);
5340
260
    return false;
5341
260
  }
5342
343
    }
5343
5344
29
  free (native_relocs);
5345
29
  asect->relocation = reloc_cache;
5346
29
  return true;
5347
289
}
coff-z80.c:coff_slurp_reloc_table
Line
Count
Source
5237
356
{
5238
356
  bfd_byte *native_relocs;
5239
356
  arelent *reloc_cache;
5240
356
  arelent *cache_ptr;
5241
356
  unsigned int idx;
5242
356
  size_t amt;
5243
5244
356
  if (asect->relocation)
5245
4
    return true;
5246
352
  if (asect->reloc_count == 0)
5247
12
    return true;
5248
340
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
340
  if (!coff_slurp_symbol_table (abfd))
5251
141
    return false;
5252
5253
199
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
199
               asect->reloc_count,
5255
199
               bfd_coff_relsz (abfd));
5256
199
  if (native_relocs == NULL)
5257
65
    return false;
5258
5259
134
  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
134
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
134
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
1.40k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
1.33k
    {
5273
1.33k
      struct internal_reloc dst;
5274
1.33k
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
1.33k
      cache_ptr = reloc_cache + idx;
5280
1.33k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
1.33k
      dst.r_offset = 0;
5283
1.33k
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
1.33k
#ifdef RELOC_PROCESSING
5286
1.33k
      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
1.33k
      if (cache_ptr->howto == NULL)
5333
64
  {
5334
64
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
64
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
64
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
64
    bfd_set_error (bfd_error_bad_value);
5339
64
    free (native_relocs);
5340
64
    return false;
5341
64
  }
5342
1.33k
    }
5343
5344
70
  free (native_relocs);
5345
70
  asect->relocation = reloc_cache;
5346
70
  return true;
5347
134
}
coff-z8k.c:coff_slurp_reloc_table
Line
Count
Source
5237
403
{
5238
403
  bfd_byte *native_relocs;
5239
403
  arelent *reloc_cache;
5240
403
  arelent *cache_ptr;
5241
403
  unsigned int idx;
5242
403
  size_t amt;
5243
5244
403
  if (asect->relocation)
5245
0
    return true;
5246
403
  if (asect->reloc_count == 0)
5247
34
    return true;
5248
369
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
369
  if (!coff_slurp_symbol_table (abfd))
5251
150
    return false;
5252
5253
219
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
219
               asect->reloc_count,
5255
219
               bfd_coff_relsz (abfd));
5256
219
  if (native_relocs == NULL)
5257
141
    return false;
5258
5259
78
  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
78
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
78
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
113
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
105
    {
5273
105
      struct internal_reloc dst;
5274
105
      void *src;
5275
#ifndef RELOC_PROCESSING
5276
      asymbol *ptr;
5277
#endif
5278
5279
105
      cache_ptr = reloc_cache + idx;
5280
105
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
105
      dst.r_offset = 0;
5283
105
      bfd_coff_swap_reloc_in (abfd, src, &dst);
5284
5285
105
#ifdef RELOC_PROCESSING
5286
105
      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
105
      if (cache_ptr->howto == NULL)
5333
70
  {
5334
70
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
70
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
70
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
70
    bfd_set_error (bfd_error_bad_value);
5339
70
    free (native_relocs);
5340
70
    return false;
5341
70
  }
5342
105
    }
5343
5344
8
  free (native_relocs);
5345
8
  asect->relocation = reloc_cache;
5346
8
  return true;
5347
78
}
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
132
{
5238
132
  bfd_byte *native_relocs;
5239
132
  arelent *reloc_cache;
5240
132
  arelent *cache_ptr;
5241
132
  unsigned int idx;
5242
132
  size_t amt;
5243
5244
132
  if (asect->relocation)
5245
0
    return true;
5246
132
  if (asect->reloc_count == 0)
5247
2
    return true;
5248
130
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
130
  if (!coff_slurp_symbol_table (abfd))
5251
5
    return false;
5252
5253
125
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
125
               asect->reloc_count,
5255
125
               bfd_coff_relsz (abfd));
5256
125
  if (native_relocs == NULL)
5257
22
    return false;
5258
5259
103
  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
103
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
103
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
97.8k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
97.8k
    {
5273
97.8k
      struct internal_reloc dst;
5274
97.8k
      void *src;
5275
97.8k
#ifndef RELOC_PROCESSING
5276
97.8k
      asymbol *ptr;
5277
97.8k
#endif
5278
5279
97.8k
      cache_ptr = reloc_cache + idx;
5280
97.8k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
97.8k
      dst.r_offset = 0;
5283
97.8k
      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
97.8k
      cache_ptr->address = dst.r_vaddr;
5289
5290
97.8k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
97.7k
  {
5292
97.7k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
351
      {
5294
351
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
351
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
351
     abfd, dst.r_symndx);
5298
351
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
351
        ptr = NULL;
5300
351
      }
5301
97.4k
    else
5302
97.4k
      {
5303
97.4k
        cache_ptr->sym_ptr_ptr = (symbols
5304
97.4k
          + obj_convert (abfd)[dst.r_symndx]);
5305
97.4k
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
97.4k
      }
5307
97.7k
  }
5308
55
      else
5309
55
  {
5310
55
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
55
    ptr = NULL;
5312
55
  }
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
97.8k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
97.8k
      (void) ptr;
5324
5325
97.8k
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
97.8k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
97.8k
#endif  /* RELOC_PROCESSING */
5331
5332
97.8k
      if (cache_ptr->howto == NULL)
5333
86
  {
5334
86
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
86
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
86
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
86
    bfd_set_error (bfd_error_bad_value);
5339
86
    free (native_relocs);
5340
86
    return false;
5341
86
  }
5342
97.8k
    }
5343
5344
17
  free (native_relocs);
5345
17
  asect->relocation = reloc_cache;
5346
17
  return true;
5347
103
}
pe-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5237
291
{
5238
291
  bfd_byte *native_relocs;
5239
291
  arelent *reloc_cache;
5240
291
  arelent *cache_ptr;
5241
291
  unsigned int idx;
5242
291
  size_t amt;
5243
5244
291
  if (asect->relocation)
5245
0
    return true;
5246
291
  if (asect->reloc_count == 0)
5247
11
    return true;
5248
280
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
280
  if (!coff_slurp_symbol_table (abfd))
5251
59
    return false;
5252
5253
221
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
221
               asect->reloc_count,
5255
221
               bfd_coff_relsz (abfd));
5256
221
  if (native_relocs == NULL)
5257
102
    return false;
5258
5259
119
  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
119
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
119
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
1.00k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
951
    {
5273
951
      struct internal_reloc dst;
5274
951
      void *src;
5275
951
#ifndef RELOC_PROCESSING
5276
951
      asymbol *ptr;
5277
951
#endif
5278
5279
951
      cache_ptr = reloc_cache + idx;
5280
951
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
951
      dst.r_offset = 0;
5283
951
      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
951
      cache_ptr->address = dst.r_vaddr;
5289
5290
951
      if (dst.r_symndx != -1 && symbols != NULL)
5291
909
  {
5292
909
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
208
      {
5294
208
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
208
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
208
     abfd, dst.r_symndx);
5298
208
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
208
        ptr = NULL;
5300
208
      }
5301
701
    else
5302
701
      {
5303
701
        cache_ptr->sym_ptr_ptr = (symbols
5304
701
          + obj_convert (abfd)[dst.r_symndx]);
5305
701
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
701
      }
5307
909
  }
5308
42
      else
5309
42
  {
5310
42
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
42
    ptr = NULL;
5312
42
  }
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
951
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
951
      (void) ptr;
5324
5325
951
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
951
      RTYPE2HOWTO (cache_ptr, &dst);
5330
951
#endif  /* RELOC_PROCESSING */
5331
5332
951
      if (cache_ptr->howto == NULL)
5333
66
  {
5334
66
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
66
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
66
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
66
    bfd_set_error (bfd_error_bad_value);
5339
66
    free (native_relocs);
5340
66
    return false;
5341
66
  }
5342
951
    }
5343
5344
53
  free (native_relocs);
5345
53
  asect->relocation = reloc_cache;
5346
53
  return true;
5347
119
}
pe-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
125
{
5238
125
  bfd_byte *native_relocs;
5239
125
  arelent *reloc_cache;
5240
125
  arelent *cache_ptr;
5241
125
  unsigned int idx;
5242
125
  size_t amt;
5243
5244
125
  if (asect->relocation)
5245
0
    return true;
5246
125
  if (asect->reloc_count == 0)
5247
8
    return true;
5248
117
  if (asect->flags & SEC_CONSTRUCTOR)
5249
0
    return true;
5250
117
  if (!coff_slurp_symbol_table (abfd))
5251
5
    return false;
5252
5253
112
  native_relocs = (bfd_byte *) buy_and_read (abfd, asect->rel_filepos,
5254
112
               asect->reloc_count,
5255
112
               bfd_coff_relsz (abfd));
5256
112
  if (native_relocs == NULL)
5257
14
    return false;
5258
5259
98
  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
98
  reloc_cache = (arelent *) bfd_alloc (abfd, amt);
5265
98
  if (reloc_cache == NULL)
5266
0
    {
5267
0
      free (native_relocs);
5268
0
      return false;
5269
0
    }
5270
5271
15.7k
  for (idx = 0; idx < asect->reloc_count; idx++)
5272
15.7k
    {
5273
15.7k
      struct internal_reloc dst;
5274
15.7k
      void *src;
5275
15.7k
#ifndef RELOC_PROCESSING
5276
15.7k
      asymbol *ptr;
5277
15.7k
#endif
5278
5279
15.7k
      cache_ptr = reloc_cache + idx;
5280
15.7k
      src = native_relocs + idx * (size_t) bfd_coff_relsz (abfd);
5281
5282
15.7k
      dst.r_offset = 0;
5283
15.7k
      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
15.7k
      cache_ptr->address = dst.r_vaddr;
5289
5290
15.7k
      if (dst.r_symndx != -1 && symbols != NULL)
5291
15.6k
  {
5292
15.6k
    if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
5293
455
      {
5294
455
        _bfd_error_handler
5295
    /* xgettext:c-format */
5296
455
    (_("%pB: warning: illegal symbol index %ld in relocs"),
5297
455
     abfd, dst.r_symndx);
5298
455
        cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5299
455
        ptr = NULL;
5300
455
      }
5301
15.1k
    else
5302
15.1k
      {
5303
15.1k
        cache_ptr->sym_ptr_ptr = (symbols
5304
15.1k
          + obj_convert (abfd)[dst.r_symndx]);
5305
15.1k
        ptr = *(cache_ptr->sym_ptr_ptr);
5306
15.1k
      }
5307
15.6k
  }
5308
94
      else
5309
94
  {
5310
94
    cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
5311
94
    ptr = NULL;
5312
94
  }
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
15.7k
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);
5323
15.7k
      (void) ptr;
5324
5325
15.7k
      cache_ptr->address -= asect->vma;
5326
      /* !! cache_ptr->section = NULL;*/
5327
5328
      /* Fill in the cache_ptr->howto field from dst.r_type.  */
5329
15.7k
      RTYPE2HOWTO (cache_ptr, &dst);
5330
15.7k
#endif  /* RELOC_PROCESSING */
5331
5332
15.7k
      if (cache_ptr->howto == NULL)
5333
70
  {
5334
70
    _bfd_error_handler
5335
      /* xgettext:c-format */
5336
70
      (_("%pB: illegal relocation type %d at address %#" PRIx64),
5337
70
       abfd, dst.r_type, (uint64_t) dst.r_vaddr);
5338
70
    bfd_set_error (bfd_error_bad_value);
5339
70
    free (native_relocs);
5340
70
    return false;
5341
70
  }
5342
15.7k
    }
5343
5344
28
  free (native_relocs);
5345
28
  asect->relocation = reloc_cache;
5346
28
  return true;
5347
98
}
Unexecuted instantiation: pei-arm-wince.c:coff_slurp_reloc_table
pei-arm.c:coff_slurp_reloc_table
Line
Count
Source
5237
19
{
5238
19
  bfd_byte *native_relocs;
5239
19
  arelent *reloc_cache;
5240
19
  arelent *cache_ptr;
5241
19
  unsigned int idx;
5242
19
  size_t amt;
5243
5244
19
  if (asect->relocation)
5245
19
    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
}
pei-mcore.c:coff_slurp_reloc_table
Line
Count
Source
5237
3
{
5238
3
  bfd_byte *native_relocs;
5239
3
  arelent *reloc_cache;
5240
3
  arelent *cache_ptr;
5241
3
  unsigned int idx;
5242
3
  size_t amt;
5243
5244
3
  if (asect->relocation)
5245
0
    return true;
5246
3
  if (asect->reloc_count == 0)
5247
3
    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
}
pei-sh.c:coff_slurp_reloc_table
Line
Count
Source
5237
149
{
5238
149
  bfd_byte *native_relocs;
5239
149
  arelent *reloc_cache;
5240
149
  arelent *cache_ptr;
5241
149
  unsigned int idx;
5242
149
  size_t amt;
5243
5244
149
  if (asect->relocation)
5245
146
    return true;
5246
3
  if (asect->reloc_count == 0)
5247
3
    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
18.5k
{
5388
18.5k
  arelent *tblptr = section->relocation;
5389
18.5k
  unsigned int count = 0;
5390
5391
18.5k
  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
18.5k
  else
5405
18.5k
    {
5406
18.5k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
15.5k
  return -1;
5408
5409
3.05k
      tblptr = section->relocation;
5410
5411
30.9k
      for (; count++ < section->reloc_count;)
5412
27.8k
  *relptr++ = tblptr++;
5413
3.05k
    }
5414
3.05k
  *relptr = 0;
5415
3.05k
  return section->reloc_count;
5416
18.5k
}
pei-i386.c:coff_canonicalize_reloc
Line
Count
Source
5387
38
{
5388
38
  arelent *tblptr = section->relocation;
5389
38
  unsigned int count = 0;
5390
5391
38
  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
38
  else
5405
38
    {
5406
38
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
38
      tblptr = section->relocation;
5410
5411
63
      for (; count++ < section->reloc_count;)
5412
25
  *relptr++ = tblptr++;
5413
38
    }
5414
38
  *relptr = 0;
5415
38
  return section->reloc_count;
5416
38
}
pe-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
229
{
5388
229
  arelent *tblptr = section->relocation;
5389
229
  unsigned int count = 0;
5390
5391
229
  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
229
  else
5405
229
    {
5406
229
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
146
  return -1;
5408
5409
83
      tblptr = section->relocation;
5410
5411
1.36k
      for (; count++ < section->reloc_count;)
5412
1.28k
  *relptr++ = tblptr++;
5413
83
    }
5414
83
  *relptr = 0;
5415
83
  return section->reloc_count;
5416
229
}
pei-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
87
{
5388
87
  arelent *tblptr = section->relocation;
5389
87
  unsigned int count = 0;
5390
5391
87
  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
87
  else
5405
87
    {
5406
87
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
87
      tblptr = section->relocation;
5410
5411
102
      for (; count++ < section->reloc_count;)
5412
15
  *relptr++ = tblptr++;
5413
87
    }
5414
87
  *relptr = 0;
5415
87
  return section->reloc_count;
5416
87
}
coff-x86_64.c:coff_canonicalize_reloc
Line
Count
Source
5387
1.80k
{
5388
1.80k
  arelent *tblptr = section->relocation;
5389
1.80k
  unsigned int count = 0;
5390
5391
1.80k
  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.80k
  else
5405
1.80k
    {
5406
1.80k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
789
  return -1;
5408
5409
1.01k
      tblptr = section->relocation;
5410
5411
2.55k
      for (; count++ < section->reloc_count;)
5412
1.53k
  *relptr++ = tblptr++;
5413
1.01k
    }
5414
1.01k
  *relptr = 0;
5415
1.01k
  return section->reloc_count;
5416
1.80k
}
coff64-rs6000.c:coff_canonicalize_reloc
Line
Count
Source
5387
110
{
5388
110
  arelent *tblptr = section->relocation;
5389
110
  unsigned int count = 0;
5390
5391
110
  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
110
  else
5405
110
    {
5406
110
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
98
  return -1;
5408
5409
12
      tblptr = section->relocation;
5410
5411
54
      for (; count++ < section->reloc_count;)
5412
42
  *relptr++ = tblptr++;
5413
12
    }
5414
12
  *relptr = 0;
5415
12
  return section->reloc_count;
5416
110
}
pe-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
663
{
5388
663
  arelent *tblptr = section->relocation;
5389
663
  unsigned int count = 0;
5390
5391
663
  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
663
  else
5405
663
    {
5406
663
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
403
  return -1;
5408
5409
260
      tblptr = section->relocation;
5410
5411
8.54k
      for (; count++ < section->reloc_count;)
5412
8.28k
  *relptr++ = tblptr++;
5413
260
    }
5414
260
  *relptr = 0;
5415
260
  return section->reloc_count;
5416
663
}
pei-aarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
13
{
5388
13
  arelent *tblptr = section->relocation;
5389
13
  unsigned int count = 0;
5390
5391
13
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
13
  else
5405
13
    {
5406
13
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
13
      tblptr = section->relocation;
5410
5411
22
      for (; count++ < section->reloc_count;)
5412
9
  *relptr++ = tblptr++;
5413
13
    }
5414
13
  *relptr = 0;
5415
13
  return section->reloc_count;
5416
13
}
pei-ia64.c:coff_canonicalize_reloc
Line
Count
Source
5387
1
{
5388
1
  arelent *tblptr = section->relocation;
5389
1
  unsigned int count = 0;
5390
5391
1
  if (section->flags & SEC_CONSTRUCTOR)
5392
0
    {
5393
      /* This section has relocs made up by us, they are not in the
5394
   file, so take them out of their chain and place them into
5395
   the data area provided.  */
5396
0
      arelent_chain *chain = section->constructor_chain;
5397
5398
0
      for (count = 0; count < section->reloc_count; count++)
5399
0
  {
5400
0
    *relptr++ = &chain->relent;
5401
0
    chain = chain->next;
5402
0
  }
5403
0
    }
5404
1
  else
5405
1
    {
5406
1
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
1
      tblptr = section->relocation;
5410
5411
1
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
1
    }
5414
1
  *relptr = 0;
5415
1
  return section->reloc_count;
5416
1
}
pei-loongarch64.c:coff_canonicalize_reloc
Line
Count
Source
5387
21
{
5388
21
  arelent *tblptr = section->relocation;
5389
21
  unsigned int count = 0;
5390
5391
21
  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
21
  else
5405
21
    {
5406
21
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
21
      tblptr = section->relocation;
5410
5411
42
      for (; count++ < section->reloc_count;)
5412
21
  *relptr++ = tblptr++;
5413
21
    }
5414
21
  *relptr = 0;
5415
21
  return section->reloc_count;
5416
21
}
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
213
{
5388
213
  arelent *tblptr = section->relocation;
5389
213
  unsigned int count = 0;
5390
5391
213
  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
213
  else
5405
213
    {
5406
213
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
80
  return -1;
5408
5409
133
      tblptr = section->relocation;
5410
5411
140
      for (; count++ < section->reloc_count;)
5412
7
  *relptr++ = tblptr++;
5413
133
    }
5414
133
  *relptr = 0;
5415
133
  return section->reloc_count;
5416
213
}
coff-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
1.16k
{
5388
1.16k
  arelent *tblptr = section->relocation;
5389
1.16k
  unsigned int count = 0;
5390
5391
1.16k
  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.16k
  else
5405
1.16k
    {
5406
1.16k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
961
  return -1;
5408
5409
208
      tblptr = section->relocation;
5410
5411
818
      for (; count++ < section->reloc_count;)
5412
610
  *relptr++ = tblptr++;
5413
208
    }
5414
208
  *relptr = 0;
5415
208
  return section->reloc_count;
5416
1.16k
}
Unexecuted instantiation: coff-stgo32.c:coff_canonicalize_reloc
coff-tic30.c:coff_canonicalize_reloc
Line
Count
Source
5387
11.2k
{
5388
11.2k
  arelent *tblptr = section->relocation;
5389
11.2k
  unsigned int count = 0;
5390
5391
11.2k
  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.2k
  else
5405
11.2k
    {
5406
11.2k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
10.6k
  return -1;
5408
5409
596
      tblptr = section->relocation;
5410
5411
4.77k
      for (; count++ < section->reloc_count;)
5412
4.17k
  *relptr++ = tblptr++;
5413
596
    }
5414
596
  *relptr = 0;
5415
596
  return section->reloc_count;
5416
11.2k
}
Unexecuted instantiation: coff-tic4x.c:coff_canonicalize_reloc
coff-tic54x.c:coff_canonicalize_reloc
Line
Count
Source
5387
1.42k
{
5388
1.42k
  arelent *tblptr = section->relocation;
5389
1.42k
  unsigned int count = 0;
5390
5391
1.42k
  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.42k
  else
5405
1.42k
    {
5406
1.42k
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
1.26k
  return -1;
5408
5409
163
      tblptr = section->relocation;
5410
5411
201
      for (; count++ < section->reloc_count;)
5412
38
  *relptr++ = tblptr++;
5413
163
    }
5414
163
  *relptr = 0;
5415
163
  return section->reloc_count;
5416
1.42k
}
coff-z80.c:coff_canonicalize_reloc
Line
Count
Source
5387
356
{
5388
356
  arelent *tblptr = section->relocation;
5389
356
  unsigned int count = 0;
5390
5391
356
  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
356
  else
5405
356
    {
5406
356
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
270
  return -1;
5408
5409
86
      tblptr = section->relocation;
5410
5411
976
      for (; count++ < section->reloc_count;)
5412
890
  *relptr++ = tblptr++;
5413
86
    }
5414
86
  *relptr = 0;
5415
86
  return section->reloc_count;
5416
356
}
coff-z8k.c:coff_canonicalize_reloc
Line
Count
Source
5387
403
{
5388
403
  arelent *tblptr = section->relocation;
5389
403
  unsigned int count = 0;
5390
5391
403
  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
403
  else
5405
403
    {
5406
403
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
361
  return -1;
5408
5409
42
      tblptr = section->relocation;
5410
5411
50
      for (; count++ < section->reloc_count;)
5412
8
  *relptr++ = tblptr++;
5413
42
    }
5414
42
  *relptr = 0;
5415
42
  return section->reloc_count;
5416
403
}
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
132
{
5388
132
  arelent *tblptr = section->relocation;
5389
132
  unsigned int count = 0;
5390
5391
132
  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
132
  else
5405
132
    {
5406
132
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
113
  return -1;
5408
5409
19
      tblptr = section->relocation;
5410
5411
542
      for (; count++ < section->reloc_count;)
5412
523
  *relptr++ = tblptr++;
5413
19
    }
5414
19
  *relptr = 0;
5415
19
  return section->reloc_count;
5416
132
}
pe-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5387
291
{
5388
291
  arelent *tblptr = section->relocation;
5389
291
  unsigned int count = 0;
5390
5391
291
  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
291
  else
5405
291
    {
5406
291
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
227
  return -1;
5408
5409
64
      tblptr = section->relocation;
5410
5411
695
      for (; count++ < section->reloc_count;)
5412
631
  *relptr++ = tblptr++;
5413
64
    }
5414
64
  *relptr = 0;
5415
64
  return section->reloc_count;
5416
291
}
pe-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
125
{
5388
125
  arelent *tblptr = section->relocation;
5389
125
  unsigned int count = 0;
5390
5391
125
  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
125
  else
5405
125
    {
5406
125
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
89
  return -1;
5408
5409
36
      tblptr = section->relocation;
5410
5411
9.63k
      for (; count++ < section->reloc_count;)
5412
9.60k
  *relptr++ = tblptr++;
5413
36
    }
5414
36
  *relptr = 0;
5415
36
  return section->reloc_count;
5416
125
}
Unexecuted instantiation: pei-arm-wince.c:coff_canonicalize_reloc
pei-arm.c:coff_canonicalize_reloc
Line
Count
Source
5387
19
{
5388
19
  arelent *tblptr = section->relocation;
5389
19
  unsigned int count = 0;
5390
5391
19
  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
19
  else
5405
19
    {
5406
19
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
19
      tblptr = section->relocation;
5410
5411
38
      for (; count++ < section->reloc_count;)
5412
19
  *relptr++ = tblptr++;
5413
19
    }
5414
19
  *relptr = 0;
5415
19
  return section->reloc_count;
5416
19
}
pei-mcore.c:coff_canonicalize_reloc
Line
Count
Source
5387
3
{
5388
3
  arelent *tblptr = section->relocation;
5389
3
  unsigned int count = 0;
5390
5391
3
  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
3
  else
5405
3
    {
5406
3
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
3
      tblptr = section->relocation;
5410
5411
3
      for (; count++ < section->reloc_count;)
5412
0
  *relptr++ = tblptr++;
5413
3
    }
5414
3
  *relptr = 0;
5415
3
  return section->reloc_count;
5416
3
}
pei-sh.c:coff_canonicalize_reloc
Line
Count
Source
5387
149
{
5388
149
  arelent *tblptr = section->relocation;
5389
149
  unsigned int count = 0;
5390
5391
149
  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
149
  else
5405
149
    {
5406
149
      if (! coff_slurp_reloc_table (abfd, section, symbols))
5407
0
  return -1;
5408
5409
149
      tblptr = section->relocation;
5410
5411
295
      for (; count++ < section->reloc_count;)
5412
146
  *relptr++ = tblptr++;
5413
149
    }
5414
149
  *relptr = 0;
5415
149
  return section->reloc_count;
5416
149
}
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
3.06M
{
5706
3.06M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
3.06M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
3.06M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
3.06M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
3.06M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
3.06M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
3.06M
  filehdr_dst->f_symptr =
5714
3.06M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
3.06M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
3.06M
  filehdr_dst->f_opthdr = 0;
5717
3.06M
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
3.06M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
3.06M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
3.06M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
3.06M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
3.06M
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
3.06M
}
pe-x86_64.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
1.53M
{
5706
1.53M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
1.53M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
1.53M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
1.53M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
1.53M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
1.53M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
1.53M
  filehdr_dst->f_symptr =
5714
1.53M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
1.53M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
1.53M
  filehdr_dst->f_opthdr = 0;
5717
1.53M
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
1.53M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
1.53M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
1.53M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
1.53M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
1.53M
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
1.53M
}
pe-i386.c:coff_bigobj_swap_filehdr_in
Line
Count
Source
5705
1.53M
{
5706
1.53M
  struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
5707
1.53M
    (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
5708
1.53M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
5709
5710
1.53M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->Machine);
5711
1.53M
  filehdr_dst->f_nscns  = H_GET_32 (abfd, filehdr_src->NumberOfSections);
5712
1.53M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
5713
1.53M
  filehdr_dst->f_symptr =
5714
1.53M
    GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
5715
1.53M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
5716
1.53M
  filehdr_dst->f_opthdr = 0;
5717
1.53M
  filehdr_dst->f_flags  = 0;
5718
5719
  /* Check other magic numbers.  */
5720
1.53M
  if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
5721
1.53M
      || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
5722
1.53M
      || H_GET_16 (abfd, filehdr_src->Version) != 2
5723
1.53M
      || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
5724
1.53M
    filehdr_dst->f_opthdr = 0xffff;
5725
5726
  /* Note that CLR metadata are ignored.  */
5727
1.53M
}
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
57.1k
{
5755
57.1k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5756
57.1k
  struct internal_syment *in = (struct internal_syment *) in1;
5757
5758
57.1k
  if (ext->e.e_name[0] == 0)
5759
45.3k
    {
5760
45.3k
      in->_n._n_n._n_zeroes = 0;
5761
45.3k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5762
45.3k
    }
5763
11.7k
  else
5764
11.7k
    {
5765
#if SYMNMLEN != E_SYMNMLEN
5766
#error we need to cope with truncating or extending SYMNMLEN
5767
#else
5768
11.7k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5769
11.7k
#endif
5770
11.7k
    }
5771
5772
57.1k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5773
57.1k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5774
57.1k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5775
57.1k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5776
57.1k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5777
57.1k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5778
57.1k
}
pe-x86_64.c:coff_bigobj_swap_sym_in
Line
Count
Source
5754
56.3k
{
5755
56.3k
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5756
56.3k
  struct internal_syment *in = (struct internal_syment *) in1;
5757
5758
56.3k
  if (ext->e.e_name[0] == 0)
5759
44.7k
    {
5760
44.7k
      in->_n._n_n._n_zeroes = 0;
5761
44.7k
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5762
44.7k
    }
5763
11.5k
  else
5764
11.5k
    {
5765
#if SYMNMLEN != E_SYMNMLEN
5766
#error we need to cope with truncating or extending SYMNMLEN
5767
#else
5768
11.5k
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5769
11.5k
#endif
5770
11.5k
    }
5771
5772
56.3k
  in->n_value = H_GET_32 (abfd, ext->e_value);
5773
56.3k
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5774
56.3k
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5775
56.3k
  in->n_type = H_GET_16 (abfd, ext->e_type);
5776
56.3k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5777
56.3k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5778
56.3k
}
pe-i386.c:coff_bigobj_swap_sym_in
Line
Count
Source
5754
795
{
5755
795
  SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
5756
795
  struct internal_syment *in = (struct internal_syment *) in1;
5757
5758
795
  if (ext->e.e_name[0] == 0)
5759
628
    {
5760
628
      in->_n._n_n._n_zeroes = 0;
5761
628
      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
5762
628
    }
5763
167
  else
5764
167
    {
5765
#if SYMNMLEN != E_SYMNMLEN
5766
#error we need to cope with truncating or extending SYMNMLEN
5767
#else
5768
167
      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
5769
167
#endif
5770
167
    }
5771
5772
795
  in->n_value = H_GET_32 (abfd, ext->e_value);
5773
795
  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
5774
795
  in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
5775
795
  in->n_type = H_GET_16 (abfd, ext->e_type);
5776
795
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
5777
795
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
5778
795
}
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
328k
{
5819
328k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5820
328k
  union internal_auxent *in = (union internal_auxent *) in1;
5821
5822
  /* Make sure that all fields in the aux structure are
5823
     initialised.  */
5824
328k
  memset (in, 0, sizeof * in);
5825
328k
  switch (in_class)
5826
328k
    {
5827
19.7k
    case C_FILE:
5828
19.7k
      if (numaux > 1)
5829
19.7k
  {
5830
19.7k
    if (indx == 0)
5831
197
      memcpy (in->x_file.x_n.x_fname, ext->File.Name,
5832
197
        numaux * sizeof (AUXENT_BIGOBJ));
5833
19.7k
  }
5834
9
      else
5835
9
  memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5836
19.7k
      break;
5837
5838
5.29k
    case C_STAT:
5839
5.88k
    case C_LEAFSTAT:
5840
6.38k
    case C_HIDDEN:
5841
6.38k
      if (type == T_NULL)
5842
670
  {
5843
670
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5844
670
    in->x_scn.x_nreloc =
5845
670
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5846
670
    in->x_scn.x_nlinno =
5847
670
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5848
670
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5849
670
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5850
670
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5851
670
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5852
670
    return;
5853
670
  }
5854
5.71k
      break;
5855
5856
302k
    default:
5857
302k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5858
      /* Characteristics is ignored.  */
5859
302k
      break;
5860
328k
    }
5861
328k
}
pe-x86_64.c:coff_bigobj_swap_aux_in
Line
Count
Source
5818
328k
{
5819
328k
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5820
328k
  union internal_auxent *in = (union internal_auxent *) in1;
5821
5822
  /* Make sure that all fields in the aux structure are
5823
     initialised.  */
5824
328k
  memset (in, 0, sizeof * in);
5825
328k
  switch (in_class)
5826
328k
    {
5827
19.7k
    case C_FILE:
5828
19.7k
      if (numaux > 1)
5829
19.7k
  {
5830
19.7k
    if (indx == 0)
5831
197
      memcpy (in->x_file.x_n.x_fname, ext->File.Name,
5832
197
        numaux * sizeof (AUXENT_BIGOBJ));
5833
19.7k
  }
5834
9
      else
5835
9
  memcpy (in->x_file.x_n.x_fname, ext->File.Name, sizeof (ext->File.Name));
5836
19.7k
      break;
5837
5838
5.29k
    case C_STAT:
5839
5.88k
    case C_LEAFSTAT:
5840
6.37k
    case C_HIDDEN:
5841
6.37k
      if (type == T_NULL)
5842
670
  {
5843
670
    in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
5844
670
    in->x_scn.x_nreloc =
5845
670
      H_GET_16 (abfd, ext->Section.NumberOfRelocations);
5846
670
    in->x_scn.x_nlinno =
5847
670
      H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
5848
670
    in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
5849
670
    in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
5850
670
      | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
5851
670
    in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
5852
670
    return;
5853
670
  }
5854
5.70k
      break;
5855
5856
302k
    default:
5857
302k
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5858
      /* Characteristics is ignored.  */
5859
302k
      break;
5860
328k
    }
5861
328k
}
pe-i386.c:coff_bigobj_swap_aux_in
Line
Count
Source
5818
38
{
5819
38
  AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
5820
38
  union internal_auxent *in = (union internal_auxent *) in1;
5821
5822
  /* Make sure that all fields in the aux structure are
5823
     initialised.  */
5824
38
  memset (in, 0, sizeof * in);
5825
38
  switch (in_class)
5826
38
    {
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
1
    case C_STAT:
5839
2
    case C_LEAFSTAT:
5840
3
    case C_HIDDEN:
5841
3
      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
3
      break;
5855
5856
35
    default:
5857
35
      in->x_sym.x_tagndx.u32 = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
5858
      /* Characteristics is ignored.  */
5859
35
      break;
5860
38
    }
5861
38
}
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
};