Coverage Report

Created: 2026-10-02 09:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/peicode.h
Line
Count
Source
1
/* Support for the generic parts of PE/PEI, for BFD.
2
   Copyright (C) 1995-2026 Free Software Foundation, Inc.
3
   Written by Cygnus Solutions.
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
23
/* Most of this hacked by  Steve Chamberlain,
24
      sac@cygnus.com
25
26
   PE/PEI rearrangement (and code added): Donn Terry
27
               Softway Systems, Inc.  */
28
29
/* Hey look, some documentation [and in a place you expect to find it]!
30
31
   The main reference for the pei format is "Microsoft Portable Executable
32
   and Common Object File Format Specification 4.1".  Get it if you need to
33
   do some serious hacking on this code.
34
35
   Another reference:
36
   "Peering Inside the PE: A Tour of the Win32 Portable Executable
37
   File Format", MSJ 1994, Volume 9.
38
39
   The *sole* difference between the pe format and the pei format is that the
40
   latter has an MSDOS 2.0 .exe header on the front that prints the message
41
   "This app must be run under Windows." (or some such).
42
   (FIXME: Whether that statement is *really* true or not is unknown.
43
   Are there more subtle differences between pe and pei formats?
44
   For now assume there aren't.  If you find one, then for God sakes
45
   document it here!)
46
47
   The Microsoft docs use the word "image" instead of "executable" because
48
   the former can also refer to a DLL (shared library).  Confusion can arise
49
   because the `i' in `pei' also refers to "image".  The `pe' format can
50
   also create images (i.e. executables), it's just that to run on a win32
51
   system you need to use the pei format.
52
53
   FIXME: Please add more docs here so the next poor fool that has to hack
54
   on this code has a chance of getting something accomplished without
55
   wasting too much time.  */
56
57
#include "libpei.h"
58
59
static bool (*pe_saved_coff_bfd_print_private_bfd_data) (bfd *, void *) =
60
#ifndef coff_bfd_print_private_bfd_data
61
     NULL;
62
#else
63
     coff_bfd_print_private_bfd_data;
64
#undef coff_bfd_print_private_bfd_data
65
#endif
66
67
static bool pe_print_private_bfd_data (bfd *, void *);
68
#define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
69
70
static bool (*pe_saved_coff_bfd_copy_private_bfd_data) (bfd *, bfd *) =
71
#ifndef coff_bfd_copy_private_bfd_data
72
     NULL;
73
#else
74
     coff_bfd_copy_private_bfd_data;
75
#undef coff_bfd_copy_private_bfd_data
76
#endif
77
78
static bool pe_bfd_copy_private_bfd_data (bfd *, bfd *);
79
#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
80
81
#define coff_mkobject    pe_mkobject
82
#define coff_mkobject_hook pe_mkobject_hook
83
84
#ifdef COFF_IMAGE_WITH_PE
85
86
/* For the case of linking ELF objects into a PE binary.  */
87
#undef TARGET_MERGE_SECTIONS
88
#define TARGET_MERGE_SECTIONS true
89
90
/* This structure contains static variables used by the ILF code.  */
91
typedef asection * asection_ptr;
92
93
typedef struct
94
{
95
  bfd *     abfd;
96
  bfd_byte *    data;
97
  struct bfd_in_memory * bim;
98
  unsigned short  magic;
99
100
  arelent *   reltab;
101
  unsigned int    relcount;
102
103
  coff_symbol_type *  sym_cache;
104
  coff_symbol_type *  sym_ptr;
105
  unsigned int    sym_index;
106
107
  unsigned int *  sym_table;
108
  unsigned int *  table_ptr;
109
110
  combined_entry_type * native_syms;
111
  combined_entry_type * native_ptr;
112
113
  coff_symbol_type ** sym_ptr_table;
114
  coff_symbol_type ** sym_ptr_ptr;
115
116
  unsigned int    sec_index;
117
118
  char *    string_table;
119
  char *    string_ptr;
120
  char *    end_string_ptr;
121
122
  SYMENT *    esym_table;
123
  SYMENT *    esym_ptr;
124
125
  struct internal_reloc * int_reltab;
126
}
127
pe_ILF_vars;
128
#endif /* COFF_IMAGE_WITH_PE */
129
130
bfd_cleanup coff_real_object_p
131
  (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *);
132

133
#ifndef NO_COFF_RELOCS
134
static void
135
coff_swap_reloc_in (bfd *abfd, void *src, void *dst)
136
70.3k
{
137
70.3k
  RELOC *reloc_src = src;
138
70.3k
  struct internal_reloc *reloc_dst = dst;
139
140
70.3k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
70.3k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
70.3k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
70.3k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
28.2k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
70.3k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.30k
{
137
4.30k
  RELOC *reloc_src = src;
138
4.30k
  struct internal_reloc *reloc_dst = dst;
139
140
4.30k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.30k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.30k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.30k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
4.30k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.75k
{
137
3.75k
  RELOC *reloc_src = src;
138
3.75k
  struct internal_reloc *reloc_dst = dst;
139
140
3.75k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.75k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.75k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.75k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.75k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
5.19k
{
137
5.19k
  RELOC *reloc_src = src;
138
5.19k
  struct internal_reloc *reloc_dst = dst;
139
140
5.19k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
5.19k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
5.19k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
5.19k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
5.19k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
9.20k
{
137
9.20k
  RELOC *reloc_src = src;
138
9.20k
  struct internal_reloc *reloc_dst = dst;
139
140
9.20k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
9.20k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
9.20k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
9.20k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
9.20k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
4.23k
{
137
4.23k
  RELOC *reloc_src = src;
138
4.23k
  struct internal_reloc *reloc_dst = dst;
139
140
4.23k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.23k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.23k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.23k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
4.23k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
3.98k
{
137
3.98k
  RELOC *reloc_src = src;
138
3.98k
  struct internal_reloc *reloc_dst = dst;
139
140
3.98k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.98k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.98k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.98k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.98k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.84k
{
137
3.84k
  RELOC *reloc_src = src;
138
3.84k
  struct internal_reloc *reloc_dst = dst;
139
140
3.84k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.84k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.84k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.84k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.84k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.84k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.84k
#endif
147
3.84k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.25k
{
137
3.25k
  RELOC *reloc_src = src;
138
3.25k
  struct internal_reloc *reloc_dst = dst;
139
140
3.25k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.25k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.25k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.25k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.25k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.25k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.25k
#endif
147
3.25k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.90k
{
137
1.90k
  RELOC *reloc_src = src;
138
1.90k
  struct internal_reloc *reloc_dst = dst;
139
140
1.90k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
1.90k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
1.90k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
1.90k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
1.90k
#ifdef SWAP_IN_RELOC_OFFSET
145
1.90k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
1.90k
#endif
147
1.90k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.90k
{
137
1.90k
  RELOC *reloc_src = src;
138
1.90k
  struct internal_reloc *reloc_dst = dst;
139
140
1.90k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
1.90k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
1.90k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
1.90k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
1.90k
#ifdef SWAP_IN_RELOC_OFFSET
145
1.90k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
1.90k
#endif
147
1.90k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
5.33k
{
137
5.33k
  RELOC *reloc_src = src;
138
5.33k
  struct internal_reloc *reloc_dst = dst;
139
140
5.33k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
5.33k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
5.33k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
5.33k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
5.33k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
4.69k
{
137
4.69k
  RELOC *reloc_src = src;
138
4.69k
  struct internal_reloc *reloc_dst = dst;
139
140
4.69k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.69k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.69k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.69k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.69k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.69k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.69k
#endif
147
4.69k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
3.34k
{
137
3.34k
  RELOC *reloc_src = src;
138
3.34k
  struct internal_reloc *reloc_dst = dst;
139
140
3.34k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.34k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.34k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.34k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.34k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
4.44k
{
137
4.44k
  RELOC *reloc_src = src;
138
4.44k
  struct internal_reloc *reloc_dst = dst;
139
140
4.44k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.44k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.44k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.44k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.44k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.44k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.44k
#endif
147
4.44k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
4.67k
{
137
4.67k
  RELOC *reloc_src = src;
138
4.67k
  struct internal_reloc *reloc_dst = dst;
139
140
4.67k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.67k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.67k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.67k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.67k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.67k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.67k
#endif
147
4.67k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
3.54k
{
137
3.54k
  RELOC *reloc_src = src;
138
3.54k
  struct internal_reloc *reloc_dst = dst;
139
140
3.54k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.54k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.54k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.54k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.54k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.54k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.54k
#endif
147
3.54k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.68k
{
137
2.68k
  RELOC *reloc_src = src;
138
2.68k
  struct internal_reloc *reloc_dst = dst;
139
140
2.68k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
2.68k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
2.68k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
2.68k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
2.68k
}
148
149
static unsigned int
150
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
151
16
{
152
16
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
16
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
16
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
16
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
16
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
0
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
16
  return RELSZ;
166
16
}
Unexecuted instantiation: pei-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-x86_64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-x86_64.c:coff_swap_reloc_out
pe-aarch64.c:coff_swap_reloc_out
Line
Count
Source
151
16
{
152
16
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
16
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
16
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
16
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
16
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
16
  return RELSZ;
166
16
}
Unexecuted instantiation: pei-aarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-loongarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-riscv64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pei-sh.c:coff_swap_reloc_out
167
#endif /* not NO_COFF_RELOCS */
168
169
#ifdef COFF_IMAGE_WITH_PE
170
#undef FILHDR
171
491k
#define FILHDR struct external_PEI_IMAGE_hdr
172
#endif
173
174
static void
175
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
176
2.40M
{
177
2.40M
  FILHDR *filehdr_src = (FILHDR *) src;
178
2.40M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
2.40M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
2.40M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
2.40M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
2.40M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
2.40M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
2.40M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
2.40M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
248k
    {
191
248k
      filehdr_dst->f_nsyms = 0;
192
248k
      filehdr_dst->f_flags |= F_LSYMS;
193
248k
    }
194
195
2.40M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
2.40M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
176
55.3k
{
177
55.3k
  FILHDR *filehdr_src = (FILHDR *) src;
178
55.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
55.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
55.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
55.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
55.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
55.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
55.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
55.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.42k
    {
191
5.42k
      filehdr_dst->f_nsyms = 0;
192
5.42k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.42k
    }
194
195
55.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
55.3k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
176
206k
{
177
206k
  FILHDR *filehdr_src = (FILHDR *) src;
178
206k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
206k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
206k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
206k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
206k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
206k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
206k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
206k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.8k
    {
191
22.8k
      filehdr_dst->f_nsyms = 0;
192
22.8k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.8k
    }
194
195
206k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
206k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
176
54.3k
{
177
54.3k
  FILHDR *filehdr_src = (FILHDR *) src;
178
54.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
54.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
54.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
54.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
54.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
54.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
54.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
54.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.30k
    {
191
5.30k
      filehdr_dst->f_nsyms = 0;
192
5.30k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.30k
    }
194
195
54.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
54.3k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
204k
{
177
204k
  FILHDR *filehdr_src = (FILHDR *) src;
178
204k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
204k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
204k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
204k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
204k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
204k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
204k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
204k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.7k
    {
191
22.7k
      filehdr_dst->f_nsyms = 0;
192
22.7k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.7k
    }
194
195
204k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
204k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
52.8k
{
177
52.8k
  FILHDR *filehdr_src = (FILHDR *) src;
178
52.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
52.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
52.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
52.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
52.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
52.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
52.8k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
52.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.17k
    {
191
5.17k
      filehdr_dst->f_nsyms = 0;
192
5.17k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.17k
    }
194
195
52.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
52.8k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
176
16.9k
{
177
16.9k
  FILHDR *filehdr_src = (FILHDR *) src;
178
16.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
16.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
16.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
16.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
16.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
16.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
16.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
16.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
481
    {
191
481
      filehdr_dst->f_nsyms = 0;
192
481
      filehdr_dst->f_flags |= F_LSYMS;
193
481
    }
194
195
16.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
16.9k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
52.5k
{
177
52.5k
  FILHDR *filehdr_src = (FILHDR *) src;
178
52.5k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
52.5k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
52.5k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
52.5k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
52.5k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
52.5k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
52.5k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
52.5k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.15k
    {
191
5.15k
      filehdr_dst->f_nsyms = 0;
192
5.15k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.15k
    }
194
195
52.5k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
52.5k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
176
52.2k
{
177
52.2k
  FILHDR *filehdr_src = (FILHDR *) src;
178
52.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
52.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
52.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
52.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
52.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
52.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
52.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
52.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.03k
    {
191
5.03k
      filehdr_dst->f_nsyms = 0;
192
5.03k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.03k
    }
194
195
52.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
52.2k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
176
369k
{
177
369k
  FILHDR *filehdr_src = (FILHDR *) src;
178
369k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
369k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
369k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
369k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
369k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
369k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
369k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
369k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
37.9k
    {
191
37.9k
      filehdr_dst->f_nsyms = 0;
192
37.9k
      filehdr_dst->f_flags |= F_LSYMS;
193
37.9k
    }
194
195
369k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
369k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
176
369k
{
177
369k
  FILHDR *filehdr_src = (FILHDR *) src;
178
369k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
369k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
369k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
369k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
369k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
369k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
369k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
369k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
37.9k
    {
191
37.9k
      filehdr_dst->f_nsyms = 0;
192
37.9k
      filehdr_dst->f_flags |= F_LSYMS;
193
37.9k
    }
194
195
369k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
369k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
176
204k
{
177
204k
  FILHDR *filehdr_src = (FILHDR *) src;
178
204k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
204k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
204k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
204k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
204k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
204k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
204k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
204k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.8k
    {
191
22.8k
      filehdr_dst->f_nsyms = 0;
192
22.8k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.8k
    }
194
195
204k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
204k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
176
369k
{
177
369k
  FILHDR *filehdr_src = (FILHDR *) src;
178
369k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
369k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
369k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
369k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
369k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
369k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
369k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
369k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
38.1k
    {
191
38.1k
      filehdr_dst->f_nsyms = 0;
192
38.1k
      filehdr_dst->f_flags |= F_LSYMS;
193
38.1k
    }
194
195
369k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
369k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
176
186k
{
177
186k
  FILHDR *filehdr_src = (FILHDR *) src;
178
186k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
186k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
186k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
186k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
186k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
186k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
186k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
186k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
19.2k
    {
191
19.2k
      filehdr_dst->f_nsyms = 0;
192
19.2k
      filehdr_dst->f_flags |= F_LSYMS;
193
19.2k
    }
194
195
186k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
186k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
176
51.6k
{
177
51.6k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.08k
    {
191
5.08k
      filehdr_dst->f_nsyms = 0;
192
5.08k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.08k
    }
194
195
51.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.6k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
176
51.8k
{
177
51.8k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.8k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.08k
    {
191
5.08k
      filehdr_dst->f_nsyms = 0;
192
5.08k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.08k
    }
194
195
51.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.8k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
176
51.5k
{
177
51.5k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.5k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.5k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.5k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.5k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.5k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.5k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.5k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.5k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.02k
    {
191
5.02k
      filehdr_dst->f_nsyms = 0;
192
5.02k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.02k
    }
194
195
51.5k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.5k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
176
51.7k
{
177
51.7k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.02k
    {
191
5.02k
      filehdr_dst->f_nsyms = 0;
192
5.02k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.02k
    }
194
195
51.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.7k
}
197
198
#ifdef COFF_IMAGE_WITH_PE
199
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
200
#elif defined COFF_WITH_peAArch64
201
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
202
#elif defined COFF_WITH_pex64
203
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
204
#elif defined COFF_WITH_pep
205
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
206
#else
207
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
208
#endif
209
210
static void
211
coff_swap_scnhdr_in (bfd *abfd, void *ext, void *in)
212
891k
{
213
891k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
891k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
891k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
891k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
891k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
891k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
891k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
891k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
891k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
891k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
600k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
600k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
291k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
291k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
891k
  if (scnhdr_int->s_vaddr != 0)
239
582k
    {
240
582k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
582k
    }
247
248
891k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
891k
  if (scnhdr_int->s_paddr > 0
254
644k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
147k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
587k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
180k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
891k
#endif
263
891k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
212
59.4k
{
213
59.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
59.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
59.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
59.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
59.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
59.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
59.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
59.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
59.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
59.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
59.4k
#ifdef COFF_IMAGE_WITH_PE
230
59.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
59.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
59.4k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
59.4k
  if (scnhdr_int->s_vaddr != 0)
239
38.8k
    {
240
38.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
38.8k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
38.8k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
38.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
38.8k
#endif
246
38.8k
    }
247
248
59.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
59.4k
  if (scnhdr_int->s_paddr > 0
254
43.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
9.79k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
42.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
15.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
59.4k
#endif
263
59.4k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
212
61.7k
{
213
61.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
61.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
61.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
61.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
61.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
61.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
61.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
61.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
61.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
61.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
61.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
61.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
61.7k
#endif
237
238
61.7k
  if (scnhdr_int->s_vaddr != 0)
239
32.5k
    {
240
32.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
32.5k
    }
247
248
61.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
61.7k
  if (scnhdr_int->s_paddr > 0
254
34.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
7.30k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
27.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
7.30k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
61.7k
#endif
263
61.7k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
212
68.9k
{
213
68.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
68.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
68.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
68.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
68.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
68.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
68.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
68.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
68.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
68.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
68.9k
#ifdef COFF_IMAGE_WITH_PE
230
68.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
68.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
68.9k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
68.9k
  if (scnhdr_int->s_vaddr != 0)
239
44.9k
    {
240
44.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
44.9k
    }
247
248
68.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
68.9k
  if (scnhdr_int->s_paddr > 0
254
47.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
11.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
46.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
15.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
68.9k
#endif
263
68.9k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
48.3k
{
213
48.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
48.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
48.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
48.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
48.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
48.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
48.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
48.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
48.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
48.3k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
48.3k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
48.3k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
48.3k
#endif
237
238
48.3k
  if (scnhdr_int->s_vaddr != 0)
239
31.6k
    {
240
31.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
31.6k
    }
247
248
48.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
48.3k
  if (scnhdr_int->s_paddr > 0
254
33.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
5.21k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
28.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
5.21k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
48.3k
#endif
263
48.3k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
73.0k
{
213
73.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
73.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
73.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
73.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
73.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
73.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
73.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
73.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
73.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
73.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
73.0k
#ifdef COFF_IMAGE_WITH_PE
230
73.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
73.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
73.0k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
73.0k
  if (scnhdr_int->s_vaddr != 0)
239
52.7k
    {
240
52.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
52.7k
    }
247
248
73.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
73.0k
  if (scnhdr_int->s_paddr > 0
254
54.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
11.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
52.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
19.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
73.0k
#endif
263
73.0k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
212
60.8k
{
213
60.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
60.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
60.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
60.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
60.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
60.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
60.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
60.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
60.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
60.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
60.8k
#ifdef COFF_IMAGE_WITH_PE
230
60.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
60.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
60.8k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
60.8k
  if (scnhdr_int->s_vaddr != 0)
239
40.9k
    {
240
40.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
40.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
40.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
40.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
40.9k
#endif
246
40.9k
    }
247
248
60.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
60.8k
  if (scnhdr_int->s_paddr > 0
254
45.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
10.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
43.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
14.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
60.8k
#endif
263
60.8k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
57.0k
{
213
57.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
57.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
57.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
57.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
57.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
57.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
57.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
57.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
57.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
57.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
57.0k
#ifdef COFF_IMAGE_WITH_PE
230
57.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
57.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
57.0k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
57.0k
  if (scnhdr_int->s_vaddr != 0)
239
36.7k
    {
240
36.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
36.7k
    }
247
248
57.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
57.0k
  if (scnhdr_int->s_paddr > 0
254
41.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
7.61k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
39.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
13.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
57.0k
#endif
263
57.0k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
212
61.5k
{
213
61.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
61.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
61.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
61.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
61.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
61.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
61.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
61.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
61.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
61.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
61.5k
#ifdef COFF_IMAGE_WITH_PE
230
61.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
61.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
61.5k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
61.5k
  if (scnhdr_int->s_vaddr != 0)
239
40.7k
    {
240
40.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
40.7k
    }
247
248
61.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
61.5k
  if (scnhdr_int->s_paddr > 0
254
46.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
13.5k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
44.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
12.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
61.5k
#endif
263
61.5k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
212
25.2k
{
213
25.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
25.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
25.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
25.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
25.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
25.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
25.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
25.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
25.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
25.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
25.2k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
25.2k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
25.2k
#endif
237
238
25.2k
  if (scnhdr_int->s_vaddr != 0)
239
16.2k
    {
240
16.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
16.2k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
16.2k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
16.2k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
16.2k
#endif
246
16.2k
    }
247
248
25.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
25.2k
  if (scnhdr_int->s_paddr > 0
254
18.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
3.96k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
14.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
3.96k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
25.2k
#endif
263
25.2k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
212
25.2k
{
213
25.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
25.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
25.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
25.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
25.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
25.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
25.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
25.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
25.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
25.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
25.2k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
25.2k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
25.2k
#endif
237
238
25.2k
  if (scnhdr_int->s_vaddr != 0)
239
16.2k
    {
240
16.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
16.2k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
16.2k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
16.2k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
16.2k
#endif
246
16.2k
    }
247
248
25.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
25.2k
  if (scnhdr_int->s_paddr > 0
254
18.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
3.96k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
14.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
3.96k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
25.2k
#endif
263
25.2k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
212
55.5k
{
213
55.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
55.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
55.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
55.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
55.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
55.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
55.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
55.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
55.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
55.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
55.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
55.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
55.5k
#endif
237
238
55.5k
  if (scnhdr_int->s_vaddr != 0)
239
36.7k
    {
240
36.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
36.7k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
36.7k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
36.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
36.7k
#endif
246
36.7k
    }
247
248
55.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
55.5k
  if (scnhdr_int->s_paddr > 0
254
41.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
8.79k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
32.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
8.79k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
55.5k
#endif
263
55.5k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
212
28.1k
{
213
28.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
28.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
28.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
28.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
28.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
28.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
28.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
28.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
28.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
28.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
28.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
28.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
28.1k
#endif
237
238
28.1k
  if (scnhdr_int->s_vaddr != 0)
239
18.0k
    {
240
18.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
18.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
18.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
18.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
18.0k
#endif
246
18.0k
    }
247
248
28.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
28.1k
  if (scnhdr_int->s_paddr > 0
254
20.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
4.19k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
15.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
4.19k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
28.1k
#endif
263
28.1k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
212
46.9k
{
213
46.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
46.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
46.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
46.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
46.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
46.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
46.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
46.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
46.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
46.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
46.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
46.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
46.9k
#endif
237
238
46.9k
  if (scnhdr_int->s_vaddr != 0)
239
30.6k
    {
240
30.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
30.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
30.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
30.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
30.6k
#endif
246
30.6k
    }
247
248
46.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
46.9k
  if (scnhdr_int->s_paddr > 0
254
33.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
7.12k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
26.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
7.12k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
46.9k
#endif
263
46.9k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
212
47.4k
{
213
47.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
47.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
47.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
47.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
47.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
47.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
47.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
47.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
47.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
47.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
47.4k
#ifdef COFF_IMAGE_WITH_PE
230
47.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
47.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
47.4k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
47.4k
  if (scnhdr_int->s_vaddr != 0)
239
30.5k
    {
240
30.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
30.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
30.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
30.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
30.5k
#endif
246
30.5k
    }
247
248
47.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
47.4k
  if (scnhdr_int->s_paddr > 0
254
36.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
9.59k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
34.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
11.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
47.4k
#endif
263
47.4k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
212
63.5k
{
213
63.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
63.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
63.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
63.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
63.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
63.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
63.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
63.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
63.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
63.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
63.5k
#ifdef COFF_IMAGE_WITH_PE
230
63.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
63.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
63.5k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
63.5k
  if (scnhdr_int->s_vaddr != 0)
239
41.0k
    {
240
41.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
41.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
41.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
41.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
41.0k
#endif
246
41.0k
    }
247
248
63.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
63.5k
  if (scnhdr_int->s_paddr > 0
254
47.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
12.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
45.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
14.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
63.5k
#endif
263
63.5k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
212
56.9k
{
213
56.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
56.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
56.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
56.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
56.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
56.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
56.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
56.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
56.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
56.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
56.9k
#ifdef COFF_IMAGE_WITH_PE
230
56.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
56.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
56.9k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
56.9k
  if (scnhdr_int->s_vaddr != 0)
239
39.0k
    {
240
39.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
39.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
39.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
39.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
39.0k
#endif
246
39.0k
    }
247
248
56.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
56.9k
  if (scnhdr_int->s_paddr > 0
254
42.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
9.78k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
40.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
12.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
56.9k
#endif
263
56.9k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
212
51.7k
{
213
51.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
51.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
51.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
51.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
51.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
51.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
51.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
51.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
51.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
51.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
51.7k
#ifdef COFF_IMAGE_WITH_PE
230
51.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
51.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
51.7k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
51.7k
  if (scnhdr_int->s_vaddr != 0)
239
34.8k
    {
240
34.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
34.8k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
34.8k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
34.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
34.8k
#endif
246
34.8k
    }
247
248
51.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
51.7k
  if (scnhdr_int->s_paddr > 0
254
39.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
11.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
37.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
11.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
51.7k
#endif
263
51.7k
}
264
265
static bool
266
pe_mkobject (bfd *abfd)
267
110k
{
268
  /* Some x86 code followed by an ascii string.  */
269
110k
  static const char default_dos_message[64] = {
270
110k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
110k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
110k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
110k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
110k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
110k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
110k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
110k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
110k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
110k
  abfd->tdata.pe_obj_data = pe;
281
110k
  if (pe == NULL)
282
0
    return false;
283
284
110k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
110k
  pe->in_reloc_p = in_reloc_p;
288
289
110k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
110k
  bfd_coff_long_section_names (abfd)
292
110k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
110k
  return true;
295
110k
}
pei-i386.c:pe_mkobject
Line
Count
Source
267
10.1k
{
268
  /* Some x86 code followed by an ascii string.  */
269
10.1k
  static const char default_dos_message[64] = {
270
10.1k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
10.1k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
10.1k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
10.1k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
10.1k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
10.1k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
10.1k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
10.1k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
10.1k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
10.1k
  abfd->tdata.pe_obj_data = pe;
281
10.1k
  if (pe == NULL)
282
0
    return false;
283
284
10.1k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
10.1k
  pe->in_reloc_p = in_reloc_p;
288
289
10.1k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
10.1k
  bfd_coff_long_section_names (abfd)
292
10.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
10.1k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
267
8.64k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.64k
  static const char default_dos_message[64] = {
270
8.64k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.64k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.64k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.64k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.64k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.64k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.64k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.64k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.64k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.64k
  abfd->tdata.pe_obj_data = pe;
281
8.64k
  if (pe == NULL)
282
0
    return false;
283
284
8.64k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.64k
  pe->in_reloc_p = in_reloc_p;
288
289
8.64k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.64k
  bfd_coff_long_section_names (abfd)
292
8.64k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.64k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
267
8.22k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.22k
  static const char default_dos_message[64] = {
270
8.22k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.22k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.22k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.22k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.22k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.22k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.22k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.22k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.22k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.22k
  abfd->tdata.pe_obj_data = pe;
281
8.22k
  if (pe == NULL)
282
0
    return false;
283
284
8.22k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.22k
  pe->in_reloc_p = in_reloc_p;
288
289
8.22k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.22k
  bfd_coff_long_section_names (abfd)
292
8.22k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.22k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
267
8.81k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.81k
  static const char default_dos_message[64] = {
270
8.81k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.81k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.81k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.81k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.81k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.81k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.81k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.81k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.81k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.81k
  abfd->tdata.pe_obj_data = pe;
281
8.81k
  if (pe == NULL)
282
0
    return false;
283
284
8.81k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.81k
  pe->in_reloc_p = in_reloc_p;
288
289
8.81k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.81k
  bfd_coff_long_section_names (abfd)
292
8.81k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.81k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
267
8.93k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.93k
  static const char default_dos_message[64] = {
270
8.93k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.93k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.93k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.93k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.93k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.93k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.93k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.93k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.93k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.93k
  abfd->tdata.pe_obj_data = pe;
281
8.93k
  if (pe == NULL)
282
0
    return false;
283
284
8.93k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.93k
  pe->in_reloc_p = in_reloc_p;
288
289
8.93k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.93k
  bfd_coff_long_section_names (abfd)
292
8.93k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.93k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
267
7.28k
{
268
  /* Some x86 code followed by an ascii string.  */
269
7.28k
  static const char default_dos_message[64] = {
270
7.28k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
7.28k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
7.28k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
7.28k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
7.28k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
7.28k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
7.28k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
7.28k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
7.28k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
7.28k
  abfd->tdata.pe_obj_data = pe;
281
7.28k
  if (pe == NULL)
282
0
    return false;
283
284
7.28k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
7.28k
  pe->in_reloc_p = in_reloc_p;
288
289
7.28k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
7.28k
  bfd_coff_long_section_names (abfd)
292
7.28k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
7.28k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
267
6.85k
{
268
  /* Some x86 code followed by an ascii string.  */
269
6.85k
  static const char default_dos_message[64] = {
270
6.85k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
6.85k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
6.85k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
6.85k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
6.85k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
6.85k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
6.85k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
6.85k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
6.85k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
6.85k
  abfd->tdata.pe_obj_data = pe;
281
6.85k
  if (pe == NULL)
282
0
    return false;
283
284
6.85k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
6.85k
  pe->in_reloc_p = in_reloc_p;
288
289
6.85k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
6.85k
  bfd_coff_long_section_names (abfd)
292
6.85k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
6.85k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
267
6.19k
{
268
  /* Some x86 code followed by an ascii string.  */
269
6.19k
  static const char default_dos_message[64] = {
270
6.19k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
6.19k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
6.19k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
6.19k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
6.19k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
6.19k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
6.19k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
6.19k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
6.19k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
6.19k
  abfd->tdata.pe_obj_data = pe;
281
6.19k
  if (pe == NULL)
282
0
    return false;
283
284
6.19k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
6.19k
  pe->in_reloc_p = in_reloc_p;
288
289
6.19k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
6.19k
  bfd_coff_long_section_names (abfd)
292
6.19k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
6.19k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
267
2.71k
{
268
  /* Some x86 code followed by an ascii string.  */
269
2.71k
  static const char default_dos_message[64] = {
270
2.71k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
2.71k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
2.71k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
2.71k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
2.71k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
2.71k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
2.71k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
2.71k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
2.71k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
2.71k
  abfd->tdata.pe_obj_data = pe;
281
2.71k
  if (pe == NULL)
282
0
    return false;
283
284
2.71k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
2.71k
  pe->in_reloc_p = in_reloc_p;
288
289
2.71k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
2.71k
  bfd_coff_long_section_names (abfd)
292
2.71k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
2.71k
}
pe-arm.c:pe_mkobject
Line
Count
Source
267
2.71k
{
268
  /* Some x86 code followed by an ascii string.  */
269
2.71k
  static const char default_dos_message[64] = {
270
2.71k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
2.71k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
2.71k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
2.71k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
2.71k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
2.71k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
2.71k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
2.71k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
2.71k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
2.71k
  abfd->tdata.pe_obj_data = pe;
281
2.71k
  if (pe == NULL)
282
0
    return false;
283
284
2.71k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
2.71k
  pe->in_reloc_p = in_reloc_p;
288
289
2.71k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
2.71k
  bfd_coff_long_section_names (abfd)
292
2.71k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
2.71k
}
pe-i386.c:pe_mkobject
Line
Count
Source
267
8.46k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.46k
  static const char default_dos_message[64] = {
270
8.46k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.46k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.46k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.46k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.46k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.46k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.46k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.46k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.46k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.46k
  abfd->tdata.pe_obj_data = pe;
281
8.46k
  if (pe == NULL)
282
0
    return false;
283
284
8.46k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.46k
  pe->in_reloc_p = in_reloc_p;
288
289
8.46k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.46k
  bfd_coff_long_section_names (abfd)
292
8.46k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.46k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
267
3.58k
{
268
  /* Some x86 code followed by an ascii string.  */
269
3.58k
  static const char default_dos_message[64] = {
270
3.58k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
3.58k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
3.58k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
3.58k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
3.58k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
3.58k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
3.58k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
3.58k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
3.58k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
3.58k
  abfd->tdata.pe_obj_data = pe;
281
3.58k
  if (pe == NULL)
282
0
    return false;
283
284
3.58k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
3.58k
  pe->in_reloc_p = in_reloc_p;
288
289
3.58k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
3.58k
  bfd_coff_long_section_names (abfd)
292
3.58k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
3.58k
}
pe-sh.c:pe_mkobject
Line
Count
Source
267
4.84k
{
268
  /* Some x86 code followed by an ascii string.  */
269
4.84k
  static const char default_dos_message[64] = {
270
4.84k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
4.84k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
4.84k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
4.84k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
4.84k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
4.84k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
4.84k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
4.84k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
4.84k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
4.84k
  abfd->tdata.pe_obj_data = pe;
281
4.84k
  if (pe == NULL)
282
0
    return false;
283
284
4.84k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
4.84k
  pe->in_reloc_p = in_reloc_p;
288
289
4.84k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
4.84k
  bfd_coff_long_section_names (abfd)
292
4.84k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
4.84k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
267
5.64k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.64k
  static const char default_dos_message[64] = {
270
5.64k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.64k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.64k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.64k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.64k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.64k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.64k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.64k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.64k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.64k
  abfd->tdata.pe_obj_data = pe;
281
5.64k
  if (pe == NULL)
282
0
    return false;
283
284
5.64k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.64k
  pe->in_reloc_p = in_reloc_p;
288
289
5.64k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.64k
  bfd_coff_long_section_names (abfd)
292
5.64k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.64k
}
pei-arm.c:pe_mkobject
Line
Count
Source
267
7.08k
{
268
  /* Some x86 code followed by an ascii string.  */
269
7.08k
  static const char default_dos_message[64] = {
270
7.08k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
7.08k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
7.08k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
7.08k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
7.08k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
7.08k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
7.08k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
7.08k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
7.08k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
7.08k
  abfd->tdata.pe_obj_data = pe;
281
7.08k
  if (pe == NULL)
282
0
    return false;
283
284
7.08k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
7.08k
  pe->in_reloc_p = in_reloc_p;
288
289
7.08k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
7.08k
  bfd_coff_long_section_names (abfd)
292
7.08k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
7.08k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
267
5.14k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.14k
  static const char default_dos_message[64] = {
270
5.14k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.14k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.14k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.14k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.14k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.14k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.14k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.14k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.14k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.14k
  abfd->tdata.pe_obj_data = pe;
281
5.14k
  if (pe == NULL)
282
0
    return false;
283
284
5.14k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.14k
  pe->in_reloc_p = in_reloc_p;
288
289
5.14k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.14k
  bfd_coff_long_section_names (abfd)
292
5.14k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.14k
}
pei-sh.c:pe_mkobject
Line
Count
Source
267
5.70k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.70k
  static const char default_dos_message[64] = {
270
5.70k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.70k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.70k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.70k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.70k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.70k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.70k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.70k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.70k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.70k
  abfd->tdata.pe_obj_data = pe;
281
5.70k
  if (pe == NULL)
282
0
    return false;
283
284
5.70k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.70k
  pe->in_reloc_p = in_reloc_p;
288
289
5.70k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.70k
  bfd_coff_long_section_names (abfd)
292
5.70k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.70k
}
296
297
/* Create the COFF backend specific information.  */
298
299
static void *
300
pe_mkobject_hook (bfd *abfd,
301
      void *filehdr,
302
      void *aouthdr ATTRIBUTE_UNUSED)
303
108k
{
304
108k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
108k
  pe_data_type *pe;
306
307
108k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
108k
  pe = pe_data (abfd);
311
108k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
108k
  pe->coff.local_n_btmask = N_BTMASK;
316
108k
  pe->coff.local_n_btshft = N_BTSHFT;
317
108k
  pe->coff.local_n_tmask = N_TMASK;
318
108k
  pe->coff.local_n_tshift = N_TSHIFT;
319
108k
  pe->coff.local_symesz = SYMESZ;
320
108k
  pe->coff.local_auxesz = AUXESZ;
321
108k
  pe->coff.local_linesz = LINESZ;
322
323
108k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
108k
  obj_raw_syment_count (abfd) =
326
108k
    obj_conv_table_size (abfd) =
327
108k
      internal_f->f_nsyms;
328
329
108k
  pe->real_flags = internal_f->f_flags;
330
331
108k
  if ((internal_f->f_flags & F_DLL) != 0)
332
33.3k
    pe->dll = 1;
333
334
108k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
74.3k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
69.5k
  if (aouthdr)
339
39.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
17.8k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
108k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
108k
    sizeof (pe->dos_message));
349
350
108k
  return (void *) pe;
351
108k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
303
9.98k
{
304
9.98k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
9.98k
  pe_data_type *pe;
306
307
9.98k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
9.98k
  pe = pe_data (abfd);
311
9.98k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
9.98k
  pe->coff.local_n_btmask = N_BTMASK;
316
9.98k
  pe->coff.local_n_btshft = N_BTSHFT;
317
9.98k
  pe->coff.local_n_tmask = N_TMASK;
318
9.98k
  pe->coff.local_n_tshift = N_TSHIFT;
319
9.98k
  pe->coff.local_symesz = SYMESZ;
320
9.98k
  pe->coff.local_auxesz = AUXESZ;
321
9.98k
  pe->coff.local_linesz = LINESZ;
322
323
9.98k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
9.98k
  obj_raw_syment_count (abfd) =
326
9.98k
    obj_conv_table_size (abfd) =
327
9.98k
      internal_f->f_nsyms;
328
329
9.98k
  pe->real_flags = internal_f->f_flags;
330
331
9.98k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.73k
    pe->dll = 1;
333
334
9.98k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
7.68k
    abfd->flags |= HAS_DEBUG;
336
337
9.98k
#ifdef COFF_IMAGE_WITH_PE
338
9.98k
  if (aouthdr)
339
4.84k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
9.98k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
9.98k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
9.98k
    sizeof (pe->dos_message));
349
350
9.98k
  return (void *) pe;
351
9.98k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
303
8.45k
{
304
8.45k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.45k
  pe_data_type *pe;
306
307
8.45k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.45k
  pe = pe_data (abfd);
311
8.45k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.45k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.45k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.45k
  pe->coff.local_n_tmask = N_TMASK;
318
8.45k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.45k
  pe->coff.local_symesz = SYMESZ;
320
8.45k
  pe->coff.local_auxesz = AUXESZ;
321
8.45k
  pe->coff.local_linesz = LINESZ;
322
323
8.45k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.45k
  obj_raw_syment_count (abfd) =
326
8.45k
    obj_conv_table_size (abfd) =
327
8.45k
      internal_f->f_nsyms;
328
329
8.45k
  pe->real_flags = internal_f->f_flags;
330
331
8.45k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.17k
    pe->dll = 1;
333
334
8.45k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
6.28k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.45k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.45k
    sizeof (pe->dos_message));
349
350
8.45k
  return (void *) pe;
351
8.45k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
303
8.06k
{
304
8.06k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.06k
  pe_data_type *pe;
306
307
8.06k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.06k
  pe = pe_data (abfd);
311
8.06k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.06k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.06k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.06k
  pe->coff.local_n_tmask = N_TMASK;
318
8.06k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.06k
  pe->coff.local_symesz = SYMESZ;
320
8.06k
  pe->coff.local_auxesz = AUXESZ;
321
8.06k
  pe->coff.local_linesz = LINESZ;
322
323
8.06k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.06k
  obj_raw_syment_count (abfd) =
326
8.06k
    obj_conv_table_size (abfd) =
327
8.06k
      internal_f->f_nsyms;
328
329
8.06k
  pe->real_flags = internal_f->f_flags;
330
331
8.06k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.83k
    pe->dll = 1;
333
334
8.06k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
5.56k
    abfd->flags |= HAS_DEBUG;
336
337
8.06k
#ifdef COFF_IMAGE_WITH_PE
338
8.06k
  if (aouthdr)
339
4.98k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
8.06k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.06k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.06k
    sizeof (pe->dos_message));
349
350
8.06k
  return (void *) pe;
351
8.06k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
303
8.66k
{
304
8.66k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.66k
  pe_data_type *pe;
306
307
8.66k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.66k
  pe = pe_data (abfd);
311
8.66k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.66k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.66k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.66k
  pe->coff.local_n_tmask = N_TMASK;
318
8.66k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.66k
  pe->coff.local_symesz = SYMESZ;
320
8.66k
  pe->coff.local_auxesz = AUXESZ;
321
8.66k
  pe->coff.local_linesz = LINESZ;
322
323
8.66k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.66k
  obj_raw_syment_count (abfd) =
326
8.66k
    obj_conv_table_size (abfd) =
327
8.66k
      internal_f->f_nsyms;
328
329
8.66k
  pe->real_flags = internal_f->f_flags;
330
331
8.66k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.88k
    pe->dll = 1;
333
334
8.66k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.69k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.66k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.66k
    sizeof (pe->dos_message));
349
350
8.66k
  return (void *) pe;
351
8.66k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
303
8.79k
{
304
8.79k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.79k
  pe_data_type *pe;
306
307
8.79k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.79k
  pe = pe_data (abfd);
311
8.79k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.79k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.79k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.79k
  pe->coff.local_n_tmask = N_TMASK;
318
8.79k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.79k
  pe->coff.local_symesz = SYMESZ;
320
8.79k
  pe->coff.local_auxesz = AUXESZ;
321
8.79k
  pe->coff.local_linesz = LINESZ;
322
323
8.79k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.79k
  obj_raw_syment_count (abfd) =
326
8.79k
    obj_conv_table_size (abfd) =
327
8.79k
      internal_f->f_nsyms;
328
329
8.79k
  pe->real_flags = internal_f->f_flags;
330
331
8.79k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.06k
    pe->dll = 1;
333
334
8.79k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
6.91k
    abfd->flags |= HAS_DEBUG;
336
337
8.79k
#ifdef COFF_IMAGE_WITH_PE
338
8.79k
  if (aouthdr)
339
6.41k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
8.79k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.79k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.79k
    sizeof (pe->dos_message));
349
350
8.79k
  return (void *) pe;
351
8.79k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
303
7.05k
{
304
7.05k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
7.05k
  pe_data_type *pe;
306
307
7.05k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
7.05k
  pe = pe_data (abfd);
311
7.05k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
7.05k
  pe->coff.local_n_btmask = N_BTMASK;
316
7.05k
  pe->coff.local_n_btshft = N_BTSHFT;
317
7.05k
  pe->coff.local_n_tmask = N_TMASK;
318
7.05k
  pe->coff.local_n_tshift = N_TSHIFT;
319
7.05k
  pe->coff.local_symesz = SYMESZ;
320
7.05k
  pe->coff.local_auxesz = AUXESZ;
321
7.05k
  pe->coff.local_linesz = LINESZ;
322
323
7.05k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
7.05k
  obj_raw_syment_count (abfd) =
326
7.05k
    obj_conv_table_size (abfd) =
327
7.05k
      internal_f->f_nsyms;
328
329
7.05k
  pe->real_flags = internal_f->f_flags;
330
331
7.05k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.16k
    pe->dll = 1;
333
334
7.05k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.76k
    abfd->flags |= HAS_DEBUG;
336
337
7.05k
#ifdef COFF_IMAGE_WITH_PE
338
7.05k
  if (aouthdr)
339
3.37k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
7.05k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
7.05k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
7.05k
    sizeof (pe->dos_message));
349
350
7.05k
  return (void *) pe;
351
7.05k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
303
6.64k
{
304
6.64k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.64k
  pe_data_type *pe;
306
307
6.64k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.64k
  pe = pe_data (abfd);
311
6.64k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.64k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.64k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.64k
  pe->coff.local_n_tmask = N_TMASK;
318
6.64k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.64k
  pe->coff.local_symesz = SYMESZ;
320
6.64k
  pe->coff.local_auxesz = AUXESZ;
321
6.64k
  pe->coff.local_linesz = LINESZ;
322
323
6.64k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.64k
  obj_raw_syment_count (abfd) =
326
6.64k
    obj_conv_table_size (abfd) =
327
6.64k
      internal_f->f_nsyms;
328
329
6.64k
  pe->real_flags = internal_f->f_flags;
330
331
6.64k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.95k
    pe->dll = 1;
333
334
6.64k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.79k
    abfd->flags |= HAS_DEBUG;
336
337
6.64k
#ifdef COFF_IMAGE_WITH_PE
338
6.64k
  if (aouthdr)
339
4.31k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.64k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
6.64k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.64k
    sizeof (pe->dos_message));
349
350
6.64k
  return (void *) pe;
351
6.64k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
303
6.00k
{
304
6.00k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.00k
  pe_data_type *pe;
306
307
6.00k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.00k
  pe = pe_data (abfd);
311
6.00k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.00k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.00k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.00k
  pe->coff.local_n_tmask = N_TMASK;
318
6.00k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.00k
  pe->coff.local_symesz = SYMESZ;
320
6.00k
  pe->coff.local_auxesz = AUXESZ;
321
6.00k
  pe->coff.local_linesz = LINESZ;
322
323
6.00k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.00k
  obj_raw_syment_count (abfd) =
326
6.00k
    obj_conv_table_size (abfd) =
327
6.00k
      internal_f->f_nsyms;
328
329
6.00k
  pe->real_flags = internal_f->f_flags;
330
331
6.00k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.94k
    pe->dll = 1;
333
334
6.00k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.15k
    abfd->flags |= HAS_DEBUG;
336
337
6.00k
#ifdef COFF_IMAGE_WITH_PE
338
6.00k
  if (aouthdr)
339
3.91k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.00k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
6.00k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.00k
    sizeof (pe->dos_message));
349
350
6.00k
  return (void *) pe;
351
6.00k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
303
2.71k
{
304
2.71k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
2.71k
  pe_data_type *pe;
306
307
2.71k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
2.71k
  pe = pe_data (abfd);
311
2.71k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
2.71k
  pe->coff.local_n_btmask = N_BTMASK;
316
2.71k
  pe->coff.local_n_btshft = N_BTSHFT;
317
2.71k
  pe->coff.local_n_tmask = N_TMASK;
318
2.71k
  pe->coff.local_n_tshift = N_TSHIFT;
319
2.71k
  pe->coff.local_symesz = SYMESZ;
320
2.71k
  pe->coff.local_auxesz = AUXESZ;
321
2.71k
  pe->coff.local_linesz = LINESZ;
322
323
2.71k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
2.71k
  obj_raw_syment_count (abfd) =
326
2.71k
    obj_conv_table_size (abfd) =
327
2.71k
      internal_f->f_nsyms;
328
329
2.71k
  pe->real_flags = internal_f->f_flags;
330
331
2.71k
  if ((internal_f->f_flags & F_DLL) != 0)
332
911
    pe->dll = 1;
333
334
2.71k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.04k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
2.71k
#ifdef ARM
343
2.71k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
2.71k
#endif
346
347
2.71k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
2.71k
    sizeof (pe->dos_message));
349
350
2.71k
  return (void *) pe;
351
2.71k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
303
2.71k
{
304
2.71k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
2.71k
  pe_data_type *pe;
306
307
2.71k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
2.71k
  pe = pe_data (abfd);
311
2.71k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
2.71k
  pe->coff.local_n_btmask = N_BTMASK;
316
2.71k
  pe->coff.local_n_btshft = N_BTSHFT;
317
2.71k
  pe->coff.local_n_tmask = N_TMASK;
318
2.71k
  pe->coff.local_n_tshift = N_TSHIFT;
319
2.71k
  pe->coff.local_symesz = SYMESZ;
320
2.71k
  pe->coff.local_auxesz = AUXESZ;
321
2.71k
  pe->coff.local_linesz = LINESZ;
322
323
2.71k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
2.71k
  obj_raw_syment_count (abfd) =
326
2.71k
    obj_conv_table_size (abfd) =
327
2.71k
      internal_f->f_nsyms;
328
329
2.71k
  pe->real_flags = internal_f->f_flags;
330
331
2.71k
  if ((internal_f->f_flags & F_DLL) != 0)
332
911
    pe->dll = 1;
333
334
2.71k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.04k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
2.71k
#ifdef ARM
343
2.71k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
2.71k
#endif
346
347
2.71k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
2.71k
    sizeof (pe->dos_message));
349
350
2.71k
  return (void *) pe;
351
2.71k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
303
8.38k
{
304
8.38k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.38k
  pe_data_type *pe;
306
307
8.38k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.38k
  pe = pe_data (abfd);
311
8.38k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.38k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.38k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.38k
  pe->coff.local_n_tmask = N_TMASK;
318
8.38k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.38k
  pe->coff.local_symesz = SYMESZ;
320
8.38k
  pe->coff.local_auxesz = AUXESZ;
321
8.38k
  pe->coff.local_linesz = LINESZ;
322
323
8.38k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.38k
  obj_raw_syment_count (abfd) =
326
8.38k
    obj_conv_table_size (abfd) =
327
8.38k
      internal_f->f_nsyms;
328
329
8.38k
  pe->real_flags = internal_f->f_flags;
330
331
8.38k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.41k
    pe->dll = 1;
333
334
8.38k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
5.83k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.38k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.38k
    sizeof (pe->dos_message));
349
350
8.38k
  return (void *) pe;
351
8.38k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
303
3.48k
{
304
3.48k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
3.48k
  pe_data_type *pe;
306
307
3.48k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
3.48k
  pe = pe_data (abfd);
311
3.48k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
3.48k
  pe->coff.local_n_btmask = N_BTMASK;
316
3.48k
  pe->coff.local_n_btshft = N_BTSHFT;
317
3.48k
  pe->coff.local_n_tmask = N_TMASK;
318
3.48k
  pe->coff.local_n_tshift = N_TSHIFT;
319
3.48k
  pe->coff.local_symesz = SYMESZ;
320
3.48k
  pe->coff.local_auxesz = AUXESZ;
321
3.48k
  pe->coff.local_linesz = LINESZ;
322
323
3.48k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
3.48k
  obj_raw_syment_count (abfd) =
326
3.48k
    obj_conv_table_size (abfd) =
327
3.48k
      internal_f->f_nsyms;
328
329
3.48k
  pe->real_flags = internal_f->f_flags;
330
331
3.48k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.21k
    pe->dll = 1;
333
334
3.48k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.72k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
3.48k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
3.48k
    sizeof (pe->dos_message));
349
350
3.48k
  return (void *) pe;
351
3.48k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
303
4.75k
{
304
4.75k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
4.75k
  pe_data_type *pe;
306
307
4.75k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
4.75k
  pe = pe_data (abfd);
311
4.75k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
4.75k
  pe->coff.local_n_btmask = N_BTMASK;
316
4.75k
  pe->coff.local_n_btshft = N_BTSHFT;
317
4.75k
  pe->coff.local_n_tmask = N_TMASK;
318
4.75k
  pe->coff.local_n_tshift = N_TSHIFT;
319
4.75k
  pe->coff.local_symesz = SYMESZ;
320
4.75k
  pe->coff.local_auxesz = AUXESZ;
321
4.75k
  pe->coff.local_linesz = LINESZ;
322
323
4.75k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
4.75k
  obj_raw_syment_count (abfd) =
326
4.75k
    obj_conv_table_size (abfd) =
327
4.75k
      internal_f->f_nsyms;
328
329
4.75k
  pe->real_flags = internal_f->f_flags;
330
331
4.75k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.41k
    pe->dll = 1;
333
334
4.75k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.63k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
4.75k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
4.75k
    sizeof (pe->dos_message));
349
350
4.75k
  return (void *) pe;
351
4.75k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
303
5.51k
{
304
5.51k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.51k
  pe_data_type *pe;
306
307
5.51k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.51k
  pe = pe_data (abfd);
311
5.51k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.51k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.51k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.51k
  pe->coff.local_n_tmask = N_TMASK;
318
5.51k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.51k
  pe->coff.local_symesz = SYMESZ;
320
5.51k
  pe->coff.local_auxesz = AUXESZ;
321
5.51k
  pe->coff.local_linesz = LINESZ;
322
323
5.51k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.51k
  obj_raw_syment_count (abfd) =
326
5.51k
    obj_conv_table_size (abfd) =
327
5.51k
      internal_f->f_nsyms;
328
329
5.51k
  pe->real_flags = internal_f->f_flags;
330
331
5.51k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.10k
    pe->dll = 1;
333
334
5.51k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.35k
    abfd->flags |= HAS_DEBUG;
336
337
5.51k
#ifdef COFF_IMAGE_WITH_PE
338
5.51k
  if (aouthdr)
339
2.13k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.51k
#endif
341
342
5.51k
#ifdef ARM
343
5.51k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
5.51k
#endif
346
347
5.51k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.51k
    sizeof (pe->dos_message));
349
350
5.51k
  return (void *) pe;
351
5.51k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
303
6.90k
{
304
6.90k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.90k
  pe_data_type *pe;
306
307
6.90k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.90k
  pe = pe_data (abfd);
311
6.90k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.90k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.90k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.90k
  pe->coff.local_n_tmask = N_TMASK;
318
6.90k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.90k
  pe->coff.local_symesz = SYMESZ;
320
6.90k
  pe->coff.local_auxesz = AUXESZ;
321
6.90k
  pe->coff.local_linesz = LINESZ;
322
323
6.90k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.90k
  obj_raw_syment_count (abfd) =
326
6.90k
    obj_conv_table_size (abfd) =
327
6.90k
      internal_f->f_nsyms;
328
329
6.90k
  pe->real_flags = internal_f->f_flags;
330
331
6.90k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.51k
    pe->dll = 1;
333
334
6.90k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.41k
    abfd->flags |= HAS_DEBUG;
336
337
6.90k
#ifdef COFF_IMAGE_WITH_PE
338
6.90k
  if (aouthdr)
339
3.52k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.90k
#endif
341
342
6.90k
#ifdef ARM
343
6.90k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
6.90k
#endif
346
347
6.90k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.90k
    sizeof (pe->dos_message));
349
350
6.90k
  return (void *) pe;
351
6.90k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
303
5.01k
{
304
5.01k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.01k
  pe_data_type *pe;
306
307
5.01k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.01k
  pe = pe_data (abfd);
311
5.01k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.01k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.01k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.01k
  pe->coff.local_n_tmask = N_TMASK;
318
5.01k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.01k
  pe->coff.local_symesz = SYMESZ;
320
5.01k
  pe->coff.local_auxesz = AUXESZ;
321
5.01k
  pe->coff.local_linesz = LINESZ;
322
323
5.01k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.01k
  obj_raw_syment_count (abfd) =
326
5.01k
    obj_conv_table_size (abfd) =
327
5.01k
      internal_f->f_nsyms;
328
329
5.01k
  pe->real_flags = internal_f->f_flags;
330
331
5.01k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.91k
    pe->dll = 1;
333
334
5.01k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.10k
    abfd->flags |= HAS_DEBUG;
336
337
5.01k
#ifdef COFF_IMAGE_WITH_PE
338
5.01k
  if (aouthdr)
339
2.88k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.01k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
5.01k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.01k
    sizeof (pe->dos_message));
349
350
5.01k
  return (void *) pe;
351
5.01k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
303
5.56k
{
304
5.56k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.56k
  pe_data_type *pe;
306
307
5.56k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.56k
  pe = pe_data (abfd);
311
5.56k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.56k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.56k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.56k
  pe->coff.local_n_tmask = N_TMASK;
318
5.56k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.56k
  pe->coff.local_symesz = SYMESZ;
320
5.56k
  pe->coff.local_auxesz = AUXESZ;
321
5.56k
  pe->coff.local_linesz = LINESZ;
322
323
5.56k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.56k
  obj_raw_syment_count (abfd) =
326
5.56k
    obj_conv_table_size (abfd) =
327
5.56k
      internal_f->f_nsyms;
328
329
5.56k
  pe->real_flags = internal_f->f_flags;
330
331
5.56k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.20k
    pe->dll = 1;
333
334
5.56k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.38k
    abfd->flags |= HAS_DEBUG;
336
337
5.56k
#ifdef COFF_IMAGE_WITH_PE
338
5.56k
  if (aouthdr)
339
3.10k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.56k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
5.56k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.56k
    sizeof (pe->dos_message));
349
350
5.56k
  return (void *) pe;
351
5.56k
}
352
353
static bool
354
pe_print_private_bfd_data (bfd *abfd, void *vfile)
355
9.95k
{
356
9.95k
  FILE *file = (FILE *) vfile;
357
358
9.95k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
9.95k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
9.71k
    return true;
363
364
236
  fputc ('\n', file);
365
366
236
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
9.95k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
355
202
{
356
202
  FILE *file = (FILE *) vfile;
357
358
202
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
202
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
202
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
202
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
355
196
{
356
196
  FILE *file = (FILE *) vfile;
357
358
196
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
196
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
196
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
196
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
355
179
{
356
179
  FILE *file = (FILE *) vfile;
357
358
179
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
179
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
179
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
179
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
4.84k
{
356
4.84k
  FILE *file = (FILE *) vfile;
357
358
4.84k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
4.84k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
4.84k
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
4.84k
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
2.99k
{
356
2.99k
  FILE *file = (FILE *) vfile;
357
358
2.99k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
2.99k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
2.99k
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
2.99k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
355
362
{
356
362
  FILE *file = (FILE *) vfile;
357
358
362
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
362
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
362
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
362
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
214
{
356
214
  FILE *file = (FILE *) vfile;
357
358
214
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
214
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
214
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
214
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
355
250
{
356
250
  FILE *file = (FILE *) vfile;
357
358
250
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
250
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
250
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
250
}
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
pe-i386.c:pe_print_private_bfd_data
Line
Count
Source
355
61
{
356
61
  FILE *file = (FILE *) vfile;
357
358
61
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
61
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
61
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
61
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
355
105
{
356
105
  FILE *file = (FILE *) vfile;
357
358
105
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
105
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
105
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
105
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
355
71
{
356
71
  FILE *file = (FILE *) vfile;
357
358
71
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
71
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
71
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
71
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
355
13
{
356
13
  FILE *file = (FILE *) vfile;
357
358
13
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
13
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
0
    return true;
363
364
13
  fputc ('\n', file);
365
366
13
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
13
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
355
223
{
356
223
  FILE *file = (FILE *) vfile;
357
358
223
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
223
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
0
    return true;
363
364
223
  fputc ('\n', file);
365
366
223
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
223
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
355
124
{
356
124
  FILE *file = (FILE *) vfile;
357
358
124
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
124
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
124
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
124
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
355
117
{
356
117
  FILE *file = (FILE *) vfile;
357
358
117
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
117
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
117
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
117
}
368
369
/* Copy any private info we understand from the input bfd
370
   to the output bfd.  */
371
372
static bool
373
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
374
246
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
246
  if (pe_data (obfd) != NULL
379
246
      && pe_data (ibfd) != NULL
380
246
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
95
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
246
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
1
    return false;
385
386
245
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
42
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
203
  return true;
390
245
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
9
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
9
  if (pe_data (obfd) != NULL
379
9
      && pe_data (ibfd) != NULL
380
9
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
3
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
9
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
9
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
9
  return true;
390
9
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
15
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
15
  if (pe_data (obfd) != NULL
379
15
      && pe_data (ibfd) != NULL
380
15
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
15
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
15
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
15
  return true;
390
15
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
29
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
29
  if (pe_data (obfd) != NULL
379
29
      && pe_data (ibfd) != NULL
380
29
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
17
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
29
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
29
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
29
  return true;
390
29
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
18
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
18
  if (pe_data (obfd) != NULL
379
18
      && pe_data (ibfd) != NULL
380
18
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
3
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
18
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
18
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
18
  return true;
390
18
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
16
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
16
  if (pe_data (obfd) != NULL
379
16
      && pe_data (ibfd) != NULL
380
16
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
8
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
16
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
1
    return false;
385
386
15
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
15
  return true;
390
15
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
15
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
15
  if (pe_data (obfd) != NULL
379
15
      && pe_data (ibfd) != NULL
380
15
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
4
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
15
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
15
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
15
  return true;
390
15
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
28
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
28
  if (pe_data (obfd) != NULL
379
28
      && pe_data (ibfd) != NULL
380
28
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
12
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
28
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
28
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
28
  return true;
390
28
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
20
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
20
  if (pe_data (obfd) != NULL
379
20
      && pe_data (ibfd) != NULL
380
20
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
18
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
20
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
20
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
20
  return true;
390
20
}
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
pe-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
12
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
12
  if (pe_data (obfd) != NULL
379
12
      && pe_data (ibfd) != NULL
380
12
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
12
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
12
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
12
  return true;
390
12
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
8
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
8
  if (pe_data (obfd) != NULL
379
8
      && pe_data (ibfd) != NULL
380
8
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
4
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
8
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
8
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
8
  return true;
390
8
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
15
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
15
  if (pe_data (obfd) != NULL
379
15
      && pe_data (ibfd) != NULL
380
15
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
15
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
15
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
15
  return true;
390
15
}
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
18
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
18
  if (pe_data (obfd) != NULL
379
18
      && pe_data (ibfd) != NULL
380
18
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
5
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
18
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
18
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
18
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
0
  return true;
390
18
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
24
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
24
  if (pe_data (obfd) != NULL
379
24
      && pe_data (ibfd) != NULL
380
24
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
17
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
24
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
24
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
24
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
0
  return true;
390
24
}
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
7
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
7
  if (pe_data (obfd) != NULL
379
7
      && pe_data (ibfd) != NULL
380
7
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
7
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
7
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
7
  return true;
390
7
}
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
12
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
12
  if (pe_data (obfd) != NULL
379
12
      && pe_data (ibfd) != NULL
380
12
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
2
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
12
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
12
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
12
  return true;
390
12
}
391
392
#define coff_bfd_copy_private_section_data \
393
  _bfd_XX_bfd_copy_private_section_data
394
395
#define coff_get_symbol_info _bfd_XX_get_symbol_info
396
397
#ifdef COFF_IMAGE_WITH_PE
398

399
/* Code to handle Microsoft's Import Library Format.
400
   Also known as LINK6 format.
401
   Documentation about this format can be found at:
402
403
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
404
405
/* The following constants specify the sizes of the various data
406
   structures that we have to create in order to build a bfd describing
407
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
408
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
409
   need a padding byte in order to ensure 16 bit alignment for the section's
410
   contents.
411
412
   The value for SIZEOF_ILF_STRINGS is computed as follows:
413
414
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
415
      per symbol for their names (longest section name is .idata$x).
416
417
      There will be two symbols for the imported value, one the symbol name
418
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
419
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
420
421
      The strings in the string table must start STRING__SIZE_SIZE bytes into
422
      the table in order to for the string lookup code in coffgen/coffcode to
423
      work.  */
424
5.16k
#define NUM_ILF_RELOCS    8
425
17.2k
#define NUM_ILF_SECTIONS  6
426
12.9k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
427
428
2.58k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
429
2.58k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
430
2.58k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
431
2.58k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
432
2.58k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
433
2.58k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
434
2.58k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
435
2.58k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
436
2.58k
          + 21 + strlen (source_dll)   \
437
2.58k
          + NUM_ILF_SECTIONS * 9       \
438
2.58k
          + STRING_SIZE_SIZE)
439
1.72k
#define SIZEOF_IDATA2   (5 * 4)
440
441
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
442
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
443
594
#define SIZEOF_IDATA4   (2 * 4)
444
594
#define SIZEOF_IDATA5   (2 * 4)
445
#else
446
1.98k
#define SIZEOF_IDATA4   (1 * 4)
447
1.98k
#define SIZEOF_IDATA5   (1 * 4)
448
#endif
449
450
2.34k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
451
1.72k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
452
1.72k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
453
1.72k
         * sizeof (struct coff_section_tdata))
454
455
#define ILF_DATA_SIZE       \
456
1.72k
    + SIZEOF_ILF_SYMS        \
457
1.72k
    + SIZEOF_ILF_SYM_TABLE      \
458
1.72k
    + SIZEOF_ILF_NATIVE_SYMS      \
459
1.72k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
460
1.72k
    + SIZEOF_ILF_EXT_SYMS      \
461
1.72k
    + SIZEOF_ILF_RELOCS        \
462
1.72k
    + SIZEOF_ILF_INT_RELOCS      \
463
1.72k
    + SIZEOF_ILF_STRINGS      \
464
1.72k
    + SIZEOF_IDATA2        \
465
1.72k
    + SIZEOF_IDATA4        \
466
1.72k
    + SIZEOF_IDATA5        \
467
1.72k
    + SIZEOF_IDATA6        \
468
1.72k
    + SIZEOF_IDATA7        \
469
1.72k
    + SIZEOF_ILF_SECTIONS      \
470
1.72k
    + MAX_TEXT_SECTION_SIZE
471
472
/* Create an empty relocation against the given symbol.  */
473
474
static void
475
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
476
          bfd_vma     address,
477
          bfd_reloc_code_real_type  reloc,
478
          struct bfd_symbol **  sym,
479
          unsigned int    sym_index)
480
1.59k
{
481
1.59k
  arelent *entry;
482
1.59k
  struct internal_reloc *internal;
483
484
1.59k
  entry = vars->reltab + vars->relcount;
485
1.59k
  internal = vars->int_reltab + vars->relcount;
486
487
1.59k
  entry->address     = address;
488
1.59k
  entry->addend      = 0;
489
1.59k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
1.59k
  entry->sym_ptr_ptr = sym;
491
492
1.59k
  internal->r_vaddr  = address;
493
1.59k
  internal->r_symndx = sym_index;
494
1.59k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
1.59k
  vars->relcount ++;
497
498
1.59k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
1.59k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
212
{
481
212
  arelent *entry;
482
212
  struct internal_reloc *internal;
483
484
212
  entry = vars->reltab + vars->relcount;
485
212
  internal = vars->int_reltab + vars->relcount;
486
487
212
  entry->address     = address;
488
212
  entry->addend      = 0;
489
212
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
212
  entry->sym_ptr_ptr = sym;
491
492
212
  internal->r_vaddr  = address;
493
212
  internal->r_symndx = sym_index;
494
212
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
212
  vars->relcount ++;
497
498
212
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
212
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
180
{
481
180
  arelent *entry;
482
180
  struct internal_reloc *internal;
483
484
180
  entry = vars->reltab + vars->relcount;
485
180
  internal = vars->int_reltab + vars->relcount;
486
487
180
  entry->address     = address;
488
180
  entry->addend      = 0;
489
180
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
180
  entry->sym_ptr_ptr = sym;
491
492
180
  internal->r_vaddr  = address;
493
180
  internal->r_symndx = sym_index;
494
180
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
180
  vars->relcount ++;
497
498
180
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
180
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
176
{
481
176
  arelent *entry;
482
176
  struct internal_reloc *internal;
483
484
176
  entry = vars->reltab + vars->relcount;
485
176
  internal = vars->int_reltab + vars->relcount;
486
487
176
  entry->address     = address;
488
176
  entry->addend      = 0;
489
176
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
176
  entry->sym_ptr_ptr = sym;
491
492
176
  internal->r_vaddr  = address;
493
176
  internal->r_symndx = sym_index;
494
176
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
176
  vars->relcount ++;
497
498
176
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
176
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
204
{
481
204
  arelent *entry;
482
204
  struct internal_reloc *internal;
483
484
204
  entry = vars->reltab + vars->relcount;
485
204
  internal = vars->int_reltab + vars->relcount;
486
487
204
  entry->address     = address;
488
204
  entry->addend      = 0;
489
204
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
204
  entry->sym_ptr_ptr = sym;
491
492
204
  internal->r_vaddr  = address;
493
204
  internal->r_symndx = sym_index;
494
204
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
204
  vars->relcount ++;
497
498
204
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
204
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
188
{
481
188
  arelent *entry;
482
188
  struct internal_reloc *internal;
483
484
188
  entry = vars->reltab + vars->relcount;
485
188
  internal = vars->int_reltab + vars->relcount;
486
487
188
  entry->address     = address;
488
188
  entry->addend      = 0;
489
188
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
188
  entry->sym_ptr_ptr = sym;
491
492
188
  internal->r_vaddr  = address;
493
188
  internal->r_symndx = sym_index;
494
188
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
188
  vars->relcount ++;
497
498
188
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
188
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
150
{
481
150
  arelent *entry;
482
150
  struct internal_reloc *internal;
483
484
150
  entry = vars->reltab + vars->relcount;
485
150
  internal = vars->int_reltab + vars->relcount;
486
487
150
  entry->address     = address;
488
150
  entry->addend      = 0;
489
150
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
150
  entry->sym_ptr_ptr = sym;
491
492
150
  internal->r_vaddr  = address;
493
150
  internal->r_symndx = sym_index;
494
150
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
150
  vars->relcount ++;
497
498
150
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
150
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
154
{
481
154
  arelent *entry;
482
154
  struct internal_reloc *internal;
483
484
154
  entry = vars->reltab + vars->relcount;
485
154
  internal = vars->int_reltab + vars->relcount;
486
487
154
  entry->address     = address;
488
154
  entry->addend      = 0;
489
154
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
154
  entry->sym_ptr_ptr = sym;
491
492
154
  internal->r_vaddr  = address;
493
154
  internal->r_symndx = sym_index;
494
154
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
154
  vars->relcount ++;
497
498
154
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
154
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
335
{
481
335
  arelent *entry;
482
335
  struct internal_reloc *internal;
483
484
335
  entry = vars->reltab + vars->relcount;
485
335
  internal = vars->int_reltab + vars->relcount;
486
487
335
  entry->address     = address;
488
335
  entry->addend      = 0;
489
335
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
335
  entry->sym_ptr_ptr = sym;
491
492
335
  internal->r_vaddr  = address;
493
335
  internal->r_symndx = sym_index;
494
335
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
335
  vars->relcount ++;
497
498
335
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
335
}
500
501
/* Create an empty relocation against the given section.  */
502
503
static void
504
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
505
         bfd_vma           address,
506
         bfd_reloc_code_real_type  reloc,
507
         asection_ptr        sec)
508
1.24k
{
509
1.24k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
1.24k
            coff_section_data (vars->abfd, sec)->i);
511
1.24k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
508
160
{
509
160
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
160
            coff_section_data (vars->abfd, sec)->i);
511
160
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
146
{
509
146
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
146
            coff_section_data (vars->abfd, sec)->i);
511
146
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
136
{
509
136
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
136
            coff_section_data (vars->abfd, sec)->i);
511
136
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
154
{
509
154
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
154
            coff_section_data (vars->abfd, sec)->i);
511
154
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
152
{
509
152
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
152
            coff_section_data (vars->abfd, sec)->i);
511
152
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
508
114
{
509
114
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
114
            coff_section_data (vars->abfd, sec)->i);
511
114
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
508
116
{
509
116
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
116
            coff_section_data (vars->abfd, sec)->i);
511
116
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
508
266
{
509
266
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
266
            coff_section_data (vars->abfd, sec)->i);
511
266
}
512
513
/* Move the queued relocs into the given section.  */
514
515
static void
516
pe_ILF_save_relocs (pe_ILF_vars *vars,
517
        asection_ptr sec)
518
1.59k
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
1.59k
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
1.59k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
1.59k
  sec->relocation  = vars->reltab;
527
1.59k
  sec->reloc_count = vars->relcount;
528
1.59k
  sec->flags      |= SEC_RELOC;
529
530
1.59k
  vars->reltab     += vars->relcount;
531
1.59k
  vars->int_reltab += vars->relcount;
532
1.59k
  vars->relcount   = 0;
533
534
1.59k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
1.59k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
518
212
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
212
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
212
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
212
  sec->relocation  = vars->reltab;
527
212
  sec->reloc_count = vars->relcount;
528
212
  sec->flags      |= SEC_RELOC;
529
530
212
  vars->reltab     += vars->relcount;
531
212
  vars->int_reltab += vars->relcount;
532
212
  vars->relcount   = 0;
533
534
212
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
212
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
518
180
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
180
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
180
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
180
  sec->relocation  = vars->reltab;
527
180
  sec->reloc_count = vars->relcount;
528
180
  sec->flags      |= SEC_RELOC;
529
530
180
  vars->reltab     += vars->relcount;
531
180
  vars->int_reltab += vars->relcount;
532
180
  vars->relcount   = 0;
533
534
180
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
180
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
518
176
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
176
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
176
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
176
  sec->relocation  = vars->reltab;
527
176
  sec->reloc_count = vars->relcount;
528
176
  sec->flags      |= SEC_RELOC;
529
530
176
  vars->reltab     += vars->relcount;
531
176
  vars->int_reltab += vars->relcount;
532
176
  vars->relcount   = 0;
533
534
176
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
176
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
518
204
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
204
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
204
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
204
  sec->relocation  = vars->reltab;
527
204
  sec->reloc_count = vars->relcount;
528
204
  sec->flags      |= SEC_RELOC;
529
530
204
  vars->reltab     += vars->relcount;
531
204
  vars->int_reltab += vars->relcount;
532
204
  vars->relcount   = 0;
533
534
204
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
204
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
518
188
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
188
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
188
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
188
  sec->relocation  = vars->reltab;
527
188
  sec->reloc_count = vars->relcount;
528
188
  sec->flags      |= SEC_RELOC;
529
530
188
  vars->reltab     += vars->relcount;
531
188
  vars->int_reltab += vars->relcount;
532
188
  vars->relcount   = 0;
533
534
188
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
188
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
518
150
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
150
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
150
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
150
  sec->relocation  = vars->reltab;
527
150
  sec->reloc_count = vars->relcount;
528
150
  sec->flags      |= SEC_RELOC;
529
530
150
  vars->reltab     += vars->relcount;
531
150
  vars->int_reltab += vars->relcount;
532
150
  vars->relcount   = 0;
533
534
150
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
150
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
518
154
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
154
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
154
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
154
  sec->relocation  = vars->reltab;
527
154
  sec->reloc_count = vars->relcount;
528
154
  sec->flags      |= SEC_RELOC;
529
530
154
  vars->reltab     += vars->relcount;
531
154
  vars->int_reltab += vars->relcount;
532
154
  vars->relcount   = 0;
533
534
154
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
154
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
518
335
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
335
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
335
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
335
  sec->relocation  = vars->reltab;
527
335
  sec->reloc_count = vars->relcount;
528
335
  sec->flags      |= SEC_RELOC;
529
530
335
  vars->reltab     += vars->relcount;
531
335
  vars->int_reltab += vars->relcount;
532
335
  vars->relcount   = 0;
533
534
335
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
335
}
536
537
/* Create a global symbol and add it to the relevant tables.  */
538
539
static void
540
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
541
          const char *   prefix,
542
          const char *   symbol_name,
543
          asection_ptr   section,
544
          flagword       extra_flags)
545
4.86k
{
546
4.86k
  coff_symbol_type *sym;
547
4.86k
  combined_entry_type *ent;
548
4.86k
  SYMENT *esym;
549
4.86k
  unsigned short sclass;
550
551
4.86k
  if (extra_flags & BSF_LOCAL)
552
2.69k
    sclass = C_STAT;
553
2.16k
  else
554
2.16k
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
917
  if (vars->magic == THUMBPEMAGIC)
558
532
    {
559
532
      if (extra_flags & BSF_FUNCTION)
560
40
  sclass = C_THUMBEXTFUNC;
561
492
      else if (extra_flags & BSF_LOCAL)
562
296
  sclass = C_THUMBSTAT;
563
196
      else
564
196
  sclass = C_THUMBEXT;
565
532
    }
566
#endif
567
568
4.86k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
4.86k
  sym = vars->sym_ptr;
571
4.86k
  ent = vars->native_ptr;
572
4.86k
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
4.86k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
4.86k
  if (section == NULL)
578
804
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
4.86k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
4.86k
      esym->e.e.e_offset);
583
4.86k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
4.86k
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
4.86k
  ent->u.syment.n_sclass    = sclass;
591
4.86k
  ent->u.syment.n_scnum     = section->target_index;
592
4.86k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
4.86k
  ent->is_sym = true;
594
595
4.86k
  sym->symbol.the_bfd = vars->abfd;
596
4.86k
  sym->symbol.name    = vars->string_ptr;
597
4.86k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
4.86k
  sym->symbol.section = section;
599
4.86k
  sym->native       = ent;
600
601
4.86k
  *vars->table_ptr = vars->sym_index;
602
4.86k
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
4.86k
  vars->sym_index ++;
606
4.86k
  vars->sym_ptr ++;
607
4.86k
  vars->sym_ptr_ptr ++;
608
4.86k
  vars->table_ptr ++;
609
4.86k
  vars->native_ptr ++;
610
4.86k
  vars->esym_ptr ++;
611
4.86k
  vars->string_ptr += len + 1;
612
613
4.86k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
4.86k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
545
635
{
546
635
  coff_symbol_type *sym;
547
635
  combined_entry_type *ent;
548
635
  SYMENT *esym;
549
635
  unsigned short sclass;
550
551
635
  if (extra_flags & BSF_LOCAL)
552
350
    sclass = C_STAT;
553
285
  else
554
285
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
635
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
635
  sym = vars->sym_ptr;
571
635
  ent = vars->native_ptr;
572
635
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
635
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
635
  if (section == NULL)
578
103
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
635
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
635
      esym->e.e.e_offset);
583
635
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
635
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
635
  ent->u.syment.n_sclass    = sclass;
591
635
  ent->u.syment.n_scnum     = section->target_index;
592
635
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
635
  ent->is_sym = true;
594
595
635
  sym->symbol.the_bfd = vars->abfd;
596
635
  sym->symbol.name    = vars->string_ptr;
597
635
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
635
  sym->symbol.section = section;
599
635
  sym->native       = ent;
600
601
635
  *vars->table_ptr = vars->sym_index;
602
635
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
635
  vars->sym_index ++;
606
635
  vars->sym_ptr ++;
607
635
  vars->sym_ptr_ptr ++;
608
635
  vars->table_ptr ++;
609
635
  vars->native_ptr ++;
610
635
  vars->esym_ptr ++;
611
635
  vars->string_ptr += len + 1;
612
613
635
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
635
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
568
{
546
568
  coff_symbol_type *sym;
547
568
  combined_entry_type *ent;
548
568
  SYMENT *esym;
549
568
  unsigned short sclass;
550
551
568
  if (extra_flags & BSF_LOCAL)
552
309
    sclass = C_STAT;
553
259
  else
554
259
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
568
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
568
  sym = vars->sym_ptr;
571
568
  ent = vars->native_ptr;
572
568
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
568
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
568
  if (section == NULL)
578
95
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
568
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
568
      esym->e.e.e_offset);
583
568
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
568
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
568
  ent->u.syment.n_sclass    = sclass;
591
568
  ent->u.syment.n_scnum     = section->target_index;
592
568
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
568
  ent->is_sym = true;
594
595
568
  sym->symbol.the_bfd = vars->abfd;
596
568
  sym->symbol.name    = vars->string_ptr;
597
568
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
568
  sym->symbol.section = section;
599
568
  sym->native       = ent;
600
601
568
  *vars->table_ptr = vars->sym_index;
602
568
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
568
  vars->sym_index ++;
606
568
  vars->sym_ptr ++;
607
568
  vars->sym_ptr_ptr ++;
608
568
  vars->table_ptr ++;
609
568
  vars->native_ptr ++;
610
568
  vars->esym_ptr ++;
611
568
  vars->string_ptr += len + 1;
612
613
568
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
568
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
547
{
546
547
  coff_symbol_type *sym;
547
547
  combined_entry_type *ent;
548
547
  SYMENT *esym;
549
547
  unsigned short sclass;
550
551
547
  if (extra_flags & BSF_LOCAL)
552
302
    sclass = C_STAT;
553
245
  else
554
245
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
547
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
547
  sym = vars->sym_ptr;
571
547
  ent = vars->native_ptr;
572
547
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
547
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
547
  if (section == NULL)
578
91
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
547
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
547
      esym->e.e.e_offset);
583
547
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
547
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
547
  ent->u.syment.n_sclass    = sclass;
591
547
  ent->u.syment.n_scnum     = section->target_index;
592
547
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
547
  ent->is_sym = true;
594
595
547
  sym->symbol.the_bfd = vars->abfd;
596
547
  sym->symbol.name    = vars->string_ptr;
597
547
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
547
  sym->symbol.section = section;
599
547
  sym->native       = ent;
600
601
547
  *vars->table_ptr = vars->sym_index;
602
547
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
547
  vars->sym_index ++;
606
547
  vars->sym_ptr ++;
607
547
  vars->sym_ptr_ptr ++;
608
547
  vars->table_ptr ++;
609
547
  vars->native_ptr ++;
610
547
  vars->esym_ptr ++;
611
547
  vars->string_ptr += len + 1;
612
613
547
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
547
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
611
{
546
611
  coff_symbol_type *sym;
547
611
  combined_entry_type *ent;
548
611
  SYMENT *esym;
549
611
  unsigned short sclass;
550
551
611
  if (extra_flags & BSF_LOCAL)
552
345
    sclass = C_STAT;
553
266
  else
554
266
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
611
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
611
  sym = vars->sym_ptr;
571
611
  ent = vars->native_ptr;
572
611
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
611
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
611
  if (section == NULL)
578
102
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
611
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
611
      esym->e.e.e_offset);
583
611
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
611
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
611
  ent->u.syment.n_sclass    = sclass;
591
611
  ent->u.syment.n_scnum     = section->target_index;
592
611
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
611
  ent->is_sym = true;
594
595
611
  sym->symbol.the_bfd = vars->abfd;
596
611
  sym->symbol.name    = vars->string_ptr;
597
611
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
611
  sym->symbol.section = section;
599
611
  sym->native       = ent;
600
601
611
  *vars->table_ptr = vars->sym_index;
602
611
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
611
  vars->sym_index ++;
606
611
  vars->sym_ptr ++;
607
611
  vars->sym_ptr_ptr ++;
608
611
  vars->table_ptr ++;
609
611
  vars->native_ptr ++;
610
611
  vars->esym_ptr ++;
611
611
  vars->string_ptr += len + 1;
612
613
611
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
611
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
604
{
546
604
  coff_symbol_type *sym;
547
604
  combined_entry_type *ent;
548
604
  SYMENT *esym;
549
604
  unsigned short sclass;
550
551
604
  if (extra_flags & BSF_LOCAL)
552
326
    sclass = C_STAT;
553
278
  else
554
278
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
604
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
604
  sym = vars->sym_ptr;
571
604
  ent = vars->native_ptr;
572
604
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
604
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
604
  if (section == NULL)
578
101
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
604
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
604
      esym->e.e.e_offset);
583
604
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
604
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
604
  ent->u.syment.n_sclass    = sclass;
591
604
  ent->u.syment.n_scnum     = section->target_index;
592
604
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
604
  ent->is_sym = true;
594
595
604
  sym->symbol.the_bfd = vars->abfd;
596
604
  sym->symbol.name    = vars->string_ptr;
597
604
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
604
  sym->symbol.section = section;
599
604
  sym->native       = ent;
600
601
604
  *vars->table_ptr = vars->sym_index;
602
604
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
604
  vars->sym_index ++;
606
604
  vars->sym_ptr ++;
607
604
  vars->sym_ptr_ptr ++;
608
604
  vars->table_ptr ++;
609
604
  vars->native_ptr ++;
610
604
  vars->esym_ptr ++;
611
604
  vars->string_ptr += len + 1;
612
613
604
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
604
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
545
452
{
546
452
  coff_symbol_type *sym;
547
452
  combined_entry_type *ent;
548
452
  SYMENT *esym;
549
452
  unsigned short sclass;
550
551
452
  if (extra_flags & BSF_LOCAL)
552
255
    sclass = C_STAT;
553
197
  else
554
197
    sclass = C_EXT;
555
556
452
#ifdef THUMBPEMAGIC
557
452
  if (vars->magic == THUMBPEMAGIC)
558
266
    {
559
266
      if (extra_flags & BSF_FUNCTION)
560
20
  sclass = C_THUMBEXTFUNC;
561
246
      else if (extra_flags & BSF_LOCAL)
562
148
  sclass = C_THUMBSTAT;
563
98
      else
564
98
  sclass = C_THUMBEXT;
565
266
    }
566
452
#endif
567
568
452
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
452
  sym = vars->sym_ptr;
571
452
  ent = vars->native_ptr;
572
452
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
452
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
452
  if (section == NULL)
578
73
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
452
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
452
      esym->e.e.e_offset);
583
452
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
452
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
452
  ent->u.syment.n_sclass    = sclass;
591
452
  ent->u.syment.n_scnum     = section->target_index;
592
452
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
452
  ent->is_sym = true;
594
595
452
  sym->symbol.the_bfd = vars->abfd;
596
452
  sym->symbol.name    = vars->string_ptr;
597
452
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
452
  sym->symbol.section = section;
599
452
  sym->native       = ent;
600
601
452
  *vars->table_ptr = vars->sym_index;
602
452
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
452
  vars->sym_index ++;
606
452
  vars->sym_ptr ++;
607
452
  vars->sym_ptr_ptr ++;
608
452
  vars->table_ptr ++;
609
452
  vars->native_ptr ++;
610
452
  vars->esym_ptr ++;
611
452
  vars->string_ptr += len + 1;
612
613
452
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
452
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
545
465
{
546
465
  coff_symbol_type *sym;
547
465
  combined_entry_type *ent;
548
465
  SYMENT *esym;
549
465
  unsigned short sclass;
550
551
465
  if (extra_flags & BSF_LOCAL)
552
262
    sclass = C_STAT;
553
203
  else
554
203
    sclass = C_EXT;
555
556
465
#ifdef THUMBPEMAGIC
557
465
  if (vars->magic == THUMBPEMAGIC)
558
266
    {
559
266
      if (extra_flags & BSF_FUNCTION)
560
20
  sclass = C_THUMBEXTFUNC;
561
246
      else if (extra_flags & BSF_LOCAL)
562
148
  sclass = C_THUMBSTAT;
563
98
      else
564
98
  sclass = C_THUMBEXT;
565
266
    }
566
465
#endif
567
568
465
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
465
  sym = vars->sym_ptr;
571
465
  ent = vars->native_ptr;
572
465
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
465
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
465
  if (section == NULL)
578
75
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
465
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
465
      esym->e.e.e_offset);
583
465
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
465
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
465
  ent->u.syment.n_sclass    = sclass;
591
465
  ent->u.syment.n_scnum     = section->target_index;
592
465
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
465
  ent->is_sym = true;
594
595
465
  sym->symbol.the_bfd = vars->abfd;
596
465
  sym->symbol.name    = vars->string_ptr;
597
465
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
465
  sym->symbol.section = section;
599
465
  sym->native       = ent;
600
601
465
  *vars->table_ptr = vars->sym_index;
602
465
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
465
  vars->sym_index ++;
606
465
  vars->sym_ptr ++;
607
465
  vars->sym_ptr_ptr ++;
608
465
  vars->table_ptr ++;
609
465
  vars->native_ptr ++;
610
465
  vars->esym_ptr ++;
611
465
  vars->string_ptr += len + 1;
612
613
465
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
465
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
545
980
{
546
980
  coff_symbol_type *sym;
547
980
  combined_entry_type *ent;
548
980
  SYMENT *esym;
549
980
  unsigned short sclass;
550
551
980
  if (extra_flags & BSF_LOCAL)
552
548
    sclass = C_STAT;
553
432
  else
554
432
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
980
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
980
  sym = vars->sym_ptr;
571
980
  ent = vars->native_ptr;
572
980
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
980
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
980
  if (section == NULL)
578
164
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
980
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
980
      esym->e.e.e_offset);
583
980
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
980
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
980
  ent->u.syment.n_sclass    = sclass;
591
980
  ent->u.syment.n_scnum     = section->target_index;
592
980
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
980
  ent->is_sym = true;
594
595
980
  sym->symbol.the_bfd = vars->abfd;
596
980
  sym->symbol.name    = vars->string_ptr;
597
980
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
980
  sym->symbol.section = section;
599
980
  sym->native       = ent;
600
601
980
  *vars->table_ptr = vars->sym_index;
602
980
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
980
  vars->sym_index ++;
606
980
  vars->sym_ptr ++;
607
980
  vars->sym_ptr_ptr ++;
608
980
  vars->table_ptr ++;
609
980
  vars->native_ptr ++;
610
980
  vars->esym_ptr ++;
611
980
  vars->string_ptr += len + 1;
612
613
980
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
980
}
615
616
/* Create a section.  */
617
618
static asection_ptr
619
pe_ILF_make_a_section (pe_ILF_vars * vars,
620
           const char *  name,
621
           unsigned int  size,
622
           flagword      extra_flags)
623
2.69k
{
624
2.69k
  asection_ptr sec;
625
2.69k
  flagword     flags;
626
2.69k
  intptr_t alignment;
627
628
2.69k
  sec = bfd_make_section_old_way (vars->abfd, name);
629
2.69k
  if (sec == NULL)
630
0
    return NULL;
631
632
2.69k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
2.69k
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
2.69k
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
2.69k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
2.69k
  bfd_set_section_size (sec, (bfd_size_type) size);
644
2.69k
  sec->contents = vars->data;
645
2.69k
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
2.69k
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
2.69k
  if (size & 1)
655
319
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
2.69k
#if GCC_VERSION >= 3000
662
2.69k
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
2.69k
  vars->data
667
2.69k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
2.69k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
2.69k
  vars->data += sizeof (struct coff_section_tdata);
672
673
2.69k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
2.69k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
2.69k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
2.69k
  return sec;
682
2.69k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
623
350
{
624
350
  asection_ptr sec;
625
350
  flagword     flags;
626
350
  intptr_t alignment;
627
628
350
  sec = bfd_make_section_old_way (vars->abfd, name);
629
350
  if (sec == NULL)
630
0
    return NULL;
631
632
350
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
350
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
350
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
350
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
350
  bfd_set_section_size (sec, (bfd_size_type) size);
644
350
  sec->contents = vars->data;
645
350
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
350
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
350
  if (size & 1)
655
29
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
350
#if GCC_VERSION >= 3000
662
350
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
350
  vars->data
667
350
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
350
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
350
  vars->data += sizeof (struct coff_section_tdata);
672
673
350
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
350
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
350
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
350
  return sec;
682
350
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
623
309
{
624
309
  asection_ptr sec;
625
309
  flagword     flags;
626
309
  intptr_t alignment;
627
628
309
  sec = bfd_make_section_old_way (vars->abfd, name);
629
309
  if (sec == NULL)
630
0
    return NULL;
631
632
309
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
309
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
309
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
309
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
309
  bfd_set_section_size (sec, (bfd_size_type) size);
644
309
  sec->contents = vars->data;
645
309
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
309
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
309
  if (size & 1)
655
41
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
309
#if GCC_VERSION >= 3000
662
309
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
309
  vars->data
667
309
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
309
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
309
  vars->data += sizeof (struct coff_section_tdata);
672
673
309
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
309
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
309
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
309
  return sec;
682
309
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
623
302
{
624
302
  asection_ptr sec;
625
302
  flagword     flags;
626
302
  intptr_t alignment;
627
628
302
  sec = bfd_make_section_old_way (vars->abfd, name);
629
302
  if (sec == NULL)
630
0
    return NULL;
631
632
302
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
302
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
302
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
302
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
302
  bfd_set_section_size (sec, (bfd_size_type) size);
644
302
  sec->contents = vars->data;
645
302
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
302
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
302
  if (size & 1)
655
30
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
302
#if GCC_VERSION >= 3000
662
302
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
302
  vars->data
667
302
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
302
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
302
  vars->data += sizeof (struct coff_section_tdata);
672
673
302
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
302
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
302
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
302
  return sec;
682
302
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
623
345
{
624
345
  asection_ptr sec;
625
345
  flagword     flags;
626
345
  intptr_t alignment;
627
628
345
  sec = bfd_make_section_old_way (vars->abfd, name);
629
345
  if (sec == NULL)
630
0
    return NULL;
631
632
345
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
345
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
345
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
345
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
345
  bfd_set_section_size (sec, (bfd_size_type) size);
644
345
  sec->contents = vars->data;
645
345
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
345
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
345
  if (size & 1)
655
48
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
345
#if GCC_VERSION >= 3000
662
345
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
345
  vars->data
667
345
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
345
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
345
  vars->data += sizeof (struct coff_section_tdata);
672
673
345
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
345
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
345
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
345
  return sec;
682
345
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
623
326
{
624
326
  asection_ptr sec;
625
326
  flagword     flags;
626
326
  intptr_t alignment;
627
628
326
  sec = bfd_make_section_old_way (vars->abfd, name);
629
326
  if (sec == NULL)
630
0
    return NULL;
631
632
326
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
326
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
326
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
326
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
326
  bfd_set_section_size (sec, (bfd_size_type) size);
644
326
  sec->contents = vars->data;
645
326
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
326
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
326
  if (size & 1)
655
32
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
326
#if GCC_VERSION >= 3000
662
326
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
326
  vars->data
667
326
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
326
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
326
  vars->data += sizeof (struct coff_section_tdata);
672
673
326
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
326
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
326
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
326
  return sec;
682
326
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
623
255
{
624
255
  asection_ptr sec;
625
255
  flagword     flags;
626
255
  intptr_t alignment;
627
628
255
  sec = bfd_make_section_old_way (vars->abfd, name);
629
255
  if (sec == NULL)
630
0
    return NULL;
631
632
255
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
255
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
255
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
255
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
255
  bfd_set_section_size (sec, (bfd_size_type) size);
644
255
  sec->contents = vars->data;
645
255
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
255
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
255
  if (size & 1)
655
28
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
255
#if GCC_VERSION >= 3000
662
255
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
255
  vars->data
667
255
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
255
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
255
  vars->data += sizeof (struct coff_section_tdata);
672
673
255
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
255
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
255
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
255
  return sec;
682
255
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
623
262
{
624
262
  asection_ptr sec;
625
262
  flagword     flags;
626
262
  intptr_t alignment;
627
628
262
  sec = bfd_make_section_old_way (vars->abfd, name);
629
262
  if (sec == NULL)
630
0
    return NULL;
631
632
262
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
262
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
262
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
262
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
262
  bfd_set_section_size (sec, (bfd_size_type) size);
644
262
  sec->contents = vars->data;
645
262
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
262
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
262
  if (size & 1)
655
28
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
262
#if GCC_VERSION >= 3000
662
262
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
262
  vars->data
667
262
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
262
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
262
  vars->data += sizeof (struct coff_section_tdata);
672
673
262
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
262
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
262
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
262
  return sec;
682
262
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
623
548
{
624
548
  asection_ptr sec;
625
548
  flagword     flags;
626
548
  intptr_t alignment;
627
628
548
  sec = bfd_make_section_old_way (vars->abfd, name);
629
548
  if (sec == NULL)
630
0
    return NULL;
631
632
548
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
548
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
548
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
548
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
548
  bfd_set_section_size (sec, (bfd_size_type) size);
644
548
  sec->contents = vars->data;
645
548
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
548
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
548
  if (size & 1)
655
83
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
548
#if GCC_VERSION >= 3000
662
548
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
548
  vars->data
667
548
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
548
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
548
  vars->data += sizeof (struct coff_section_tdata);
672
673
548
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
548
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
548
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
548
  return sec;
682
548
}
683
684
/* This structure contains the code that goes into the .text section
685
   in order to perform a jump into the DLL lookup table.  The entries
686
   in the table are index by the magic number used to represent the
687
   machine type in the PE file.  The contents of the data[] arrays in
688
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
689
   The SIZE field says how many bytes in the DATA array are actually
690
   used.  The OFFSET field says where in the data array the address
691
   of the .idata$5 section should be placed.  */
692
1.72k
#define MAX_TEXT_SECTION_SIZE 32
693
694
typedef struct
695
{
696
  unsigned short magic;
697
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
698
  unsigned int   size;
699
  unsigned int   offset;
700
}
701
jump_table;
702
703
static const jump_table jtab[] =
704
{
705
#ifdef I386MAGIC
706
  { I386MAGIC,
707
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
708
    8, 2
709
  },
710
#endif
711
712
#ifdef AMD64MAGIC
713
  { AMD64MAGIC,
714
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
715
    8, 2
716
  },
717
#endif
718
719
#ifdef  MC68MAGIC
720
  { MC68MAGIC,
721
    { /* XXX fill me in */ },
722
    0, 0
723
  },
724
#endif
725
726
#ifdef  MIPS_ARCH_MAGIC_WINCE
727
  { MIPS_ARCH_MAGIC_WINCE,
728
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
729
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
730
    16, 0
731
  },
732
#endif
733
734
#ifdef  SH_ARCH_MAGIC_WINCE
735
  { SH_ARCH_MAGIC_WINCE,
736
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
737
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
738
    12, 8
739
  },
740
#endif
741
742
#ifdef AARCH64MAGIC
743
/* We don't currently support jumping to DLLs, so if
744
   someone does try emit a runtime trap.  Through UDF #0.  */
745
  { AARCH64MAGIC,
746
    { 0x00, 0x00, 0x00, 0x00 },
747
    4, 0
748
  },
749
750
#endif
751
752
#ifdef  ARMPEMAGIC
753
  { ARMPEMAGIC,
754
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
755
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
756
    12, 8
757
  },
758
#endif
759
760
#ifdef  THUMBPEMAGIC
761
  { THUMBPEMAGIC,
762
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
763
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
764
    16, 12
765
  },
766
#endif
767
768
#ifdef LOONGARCH64MAGIC
769
/* We don't currently support jumping to DLLs, so if
770
   someone does try emit a runtime trap.  Through BREAK 0.  */
771
  { LOONGARCH64MAGIC,
772
    { 0x00, 0x00, 0x2a, 0x00 },
773
    4, 0
774
  },
775
776
#endif
777
778
#ifdef RISCV64MAGIC
779
  /* We don't currently support jumping to DLLs, so if
780
     someone does try emit a runtime trap.  Through EBREAK.  */
781
  { RISCV64MAGIC,
782
    { 0x73, 0x00, 0x10, 0x00 },
783
    4, 0
784
  },
785
786
#endif
787
788
  { 0, { 0 }, 0, 0 }
789
};
790
791
#ifndef NUM_ENTRIES
792
355
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
793
#endif
794
795
/* Build a full BFD from the information supplied in a ILF object.  */
796
797
static bool
798
pe_ILF_build_a_bfd (bfd *     abfd,
799
        unsigned int    magic,
800
        char *      symbol_name,
801
        char *      source_dll,
802
        unsigned int    ordinal,
803
        unsigned int    types,
804
        char *      import_name)
805
1.12k
{
806
1.12k
  bfd_byte *       ptr;
807
1.12k
  pe_ILF_vars      vars;
808
1.12k
  struct internal_filehdr  internal_f;
809
1.12k
  unsigned int       import_type;
810
1.12k
  unsigned int       import_name_type;
811
1.12k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
1.12k
  coff_symbol_type **    imp_sym;
813
1.12k
  unsigned int       imp_index;
814
1.12k
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
1.12k
  import_type = types & 0x3;
818
1.12k
  import_name_type = (types & 0x1c) >> 2;
819
820
1.12k
  switch (import_type)
821
1.12k
    {
822
469
    case IMPORT_CODE:
823
765
    case IMPORT_DATA:
824
1.01k
    case IMPORT_CONST:
825
1.01k
      break;
826
827
108
    default:
828
      /* xgettext:c-format */
829
108
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
108
        abfd, import_type);
831
108
      return false;
832
1.12k
    }
833
834
1.01k
  switch (import_name_type)
835
1.01k
    {
836
238
    case IMPORT_ORDINAL:
837
332
    case IMPORT_NAME:
838
486
    case IMPORT_NAME_NOPREFIX:
839
777
    case IMPORT_NAME_UNDECORATE:
840
777
      import_name = symbol_name;
841
777
      break;
842
843
188
    case IMPORT_NAME_EXPORTAS:
844
188
      if (!import_name || !import_name[0])
845
105
  {
846
105
    _bfd_error_handler (_("%pB: missing import name for "
847
105
        "IMPORT_NAME_EXPORTAS for %s"),
848
105
            abfd, symbol_name);
849
105
    return false;
850
105
  }
851
83
      break;
852
853
83
    default:
854
      /* xgettext:c-format */
855
52
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
52
        abfd, import_name_type);
857
52
      return false;
858
1.01k
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
860
  vars.bim
868
860
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
860
  if (vars.bim == NULL)
870
0
    return false;
871
872
860
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
860
  vars.bim->buffer = ptr;
874
860
  vars.bim->size   = ILF_DATA_SIZE;
875
860
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
860
  vars.sym_cache = (coff_symbol_type *) ptr;
881
860
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
860
  vars.sym_index = 0;
883
860
  ptr += SIZEOF_ILF_SYMS;
884
885
860
  vars.sym_table = (unsigned int *) ptr;
886
860
  vars.table_ptr = (unsigned int *) ptr;
887
860
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
860
  vars.native_syms = (combined_entry_type *) ptr;
890
860
  vars.native_ptr  = (combined_entry_type *) ptr;
891
860
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
860
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
860
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
860
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
860
  vars.esym_table = (SYMENT *) ptr;
898
860
  vars.esym_ptr   = (SYMENT *) ptr;
899
860
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
860
  vars.reltab   = (arelent *) ptr;
902
860
  vars.relcount = 0;
903
860
  ptr += SIZEOF_ILF_RELOCS;
904
905
860
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
860
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
860
  vars.string_table = (char *) ptr;
909
860
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
860
  ptr += SIZEOF_ILF_STRINGS;
911
860
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
860
#if GCC_VERSION >= 3000
921
860
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
860
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
860
  vars.data = ptr;
928
860
  vars.abfd = abfd;
929
860
  vars.sec_index = 0;
930
860
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
860
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
860
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
860
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
860
  if (import_name_type == IMPORT_ORDINAL)
946
238
    {
947
238
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
56
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
95
      ((unsigned int *) id4->contents)[0] = ordinal;
954
95
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
95
      ((unsigned int *) id5->contents)[0] = ordinal;
956
95
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
87
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
87
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
87
#endif
961
87
    }
962
622
  else
963
622
    {
964
622
      char *symbol;
965
622
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
622
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
622
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
622
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
622
      if (import_name_type != IMPORT_NAME
983
528
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
445
  {
985
445
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
445
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
424
        || c == '@' || c == '?')
991
124
      symbol++;
992
445
  }
993
994
622
      len = strlen (symbol);
995
622
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
291
  {
997
    /* Truncate at the first '@'.  */
998
291
    char *at = strchr (symbol, '@');
999
1000
291
    if (at != NULL)
1001
68
      len = at - symbol;
1002
291
  }
1003
1004
622
      id6->contents[0] = ordinal & 0xff;
1005
622
      id6->contents[1] = ordinal >> 8;
1006
1007
622
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
622
      id6->contents[len + 2] = '\0';
1009
622
    }
1010
1011
804
  if (import_name_type != IMPORT_ORDINAL)
1012
622
    {
1013
622
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
622
      pe_ILF_save_relocs (&vars, id4);
1015
1016
622
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
622
      pe_ILF_save_relocs (&vars, id5);
1018
622
    }
1019
1020
  /* Create an import symbol.  */
1021
804
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
804
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
804
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
804
  switch (import_type)
1028
804
    {
1029
0
      int i;
1030
1031
355
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
744
      for (i = NUM_ENTRIES (jtab); i--;)
1036
744
  {
1037
744
    if (jtab[i].size == 0)
1038
355
      continue;
1039
389
    if (jtab[i].magic == magic)
1040
355
      break;
1041
389
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
355
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
355
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
355
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
355
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
34
      if (magic == AMD64MAGIC)
1070
34
  {
1071
34
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
34
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
34
              imp_index);
1074
34
  }
1075
0
      else
1076
0
#endif
1077
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
0
            imp_index);
1080
1081
355
      pe_ILF_save_relocs (&vars, text);
1082
355
      break;
1083
1084
247
    case IMPORT_DATA:
1085
449
    case IMPORT_CONST:
1086
449
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
804
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
804
  switch (import_type)
1095
804
    {
1096
355
    case IMPORT_CODE:
1097
355
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
355
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
355
      break;
1101
1102
247
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
247
      break;
1105
1106
202
    case IMPORT_CONST:
1107
202
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
202
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
804
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
804
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
804
  if (ptr)
1118
89
    *ptr = 0;
1119
804
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
804
  if (ptr)
1121
89
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
804
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
804
  internal_f.f_magic  = magic;
1127
804
  internal_f.f_symptr = 0;
1128
804
  internal_f.f_nsyms  = 0;
1129
804
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
804
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
804
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
804
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
804
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
148
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
88
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
804
  bfd_cache_close (abfd);
1148
1149
804
  abfd->iostream = (void *) vars.bim;
1150
804
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
804
  abfd->iovec = &_bfd_memory_iovec;
1152
804
  abfd->where = 0;
1153
804
  abfd->origin = 0;
1154
804
  abfd->size = 0;
1155
804
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
804
  obj_symbols (abfd) = vars.sym_cache;
1159
804
  abfd->symcount = vars.sym_index;
1160
1161
804
  obj_raw_syments (abfd) = vars.native_syms;
1162
804
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
804
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
804
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
804
  obj_coff_keep_syms (abfd) = true;
1167
1168
804
  obj_convert (abfd) = vars.sym_table;
1169
804
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
804
  obj_coff_strings (abfd) = vars.string_table;
1172
804
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
804
  obj_coff_keep_strings (abfd) = true;
1174
1175
804
  return true;
1176
1177
56
 error_return:
1178
56
  free (vars.bim->buffer);
1179
56
  free (vars.bim);
1180
56
  return false;
1181
804
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
805
134
{
806
134
  bfd_byte *       ptr;
807
134
  pe_ILF_vars      vars;
808
134
  struct internal_filehdr  internal_f;
809
134
  unsigned int       import_type;
810
134
  unsigned int       import_name_type;
811
134
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
134
  coff_symbol_type **    imp_sym;
813
134
  unsigned int       imp_index;
814
134
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
134
  import_type = types & 0x3;
818
134
  import_name_type = (types & 0x1c) >> 2;
819
820
134
  switch (import_type)
821
134
    {
822
65
    case IMPORT_CODE:
823
92
    case IMPORT_DATA:
824
127
    case IMPORT_CONST:
825
127
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
134
    }
833
834
127
  switch (import_name_type)
835
127
    {
836
29
    case IMPORT_ORDINAL:
837
49
    case IMPORT_NAME:
838
71
    case IMPORT_NAME_NOPREFIX:
839
100
    case IMPORT_NAME_UNDECORATE:
840
100
      import_name = symbol_name;
841
100
      break;
842
843
19
    case IMPORT_NAME_EXPORTAS:
844
19
      if (!import_name || !import_name[0])
845
10
  {
846
10
    _bfd_error_handler (_("%pB: missing import name for "
847
10
        "IMPORT_NAME_EXPORTAS for %s"),
848
10
            abfd, symbol_name);
849
10
    return false;
850
10
  }
851
9
      break;
852
853
9
    default:
854
      /* xgettext:c-format */
855
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
8
        abfd, import_name_type);
857
8
      return false;
858
127
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
109
  vars.bim
868
109
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
109
  if (vars.bim == NULL)
870
0
    return false;
871
872
109
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
109
  vars.bim->buffer = ptr;
874
109
  vars.bim->size   = ILF_DATA_SIZE;
875
109
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
109
  vars.sym_cache = (coff_symbol_type *) ptr;
881
109
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
109
  vars.sym_index = 0;
883
109
  ptr += SIZEOF_ILF_SYMS;
884
885
109
  vars.sym_table = (unsigned int *) ptr;
886
109
  vars.table_ptr = (unsigned int *) ptr;
887
109
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
109
  vars.native_syms = (combined_entry_type *) ptr;
890
109
  vars.native_ptr  = (combined_entry_type *) ptr;
891
109
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
109
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
109
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
109
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
109
  vars.esym_table = (SYMENT *) ptr;
898
109
  vars.esym_ptr   = (SYMENT *) ptr;
899
109
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
109
  vars.reltab   = (arelent *) ptr;
902
109
  vars.relcount = 0;
903
109
  ptr += SIZEOF_ILF_RELOCS;
904
905
109
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
109
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
109
  vars.string_table = (char *) ptr;
909
109
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
109
  ptr += SIZEOF_ILF_STRINGS;
911
109
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
109
#if GCC_VERSION >= 3000
921
109
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
109
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
109
  vars.data = ptr;
928
109
  vars.abfd = abfd;
929
109
  vars.sec_index = 0;
930
109
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
109
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
109
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
109
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
109
  if (import_name_type == IMPORT_ORDINAL)
946
29
    {
947
29
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
6
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
23
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
23
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
23
#endif
961
23
    }
962
80
  else
963
80
    {
964
80
      char *symbol;
965
80
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
80
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
80
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
80
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
80
      if (import_name_type != IMPORT_NAME
983
60
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
51
  {
985
51
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
51
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
43
        || c == '@' || c == '?')
991
22
      symbol++;
992
51
  }
993
994
80
      len = strlen (symbol);
995
80
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
29
  {
997
    /* Truncate at the first '@'.  */
998
29
    char *at = strchr (symbol, '@');
999
1000
29
    if (at != NULL)
1001
6
      len = at - symbol;
1002
29
  }
1003
1004
80
      id6->contents[0] = ordinal & 0xff;
1005
80
      id6->contents[1] = ordinal >> 8;
1006
1007
80
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
80
      id6->contents[len + 2] = '\0';
1009
80
    }
1010
1011
103
  if (import_name_type != IMPORT_ORDINAL)
1012
80
    {
1013
80
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
80
      pe_ILF_save_relocs (&vars, id4);
1015
1016
80
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
80
      pe_ILF_save_relocs (&vars, id5);
1018
80
    }
1019
1020
  /* Create an import symbol.  */
1021
103
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
103
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
103
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
103
  switch (import_type)
1028
103
    {
1029
0
      int i;
1030
1031
52
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
104
      for (i = NUM_ENTRIES (jtab); i--;)
1036
104
  {
1037
104
    if (jtab[i].size == 0)
1038
52
      continue;
1039
52
    if (jtab[i].magic == magic)
1040
52
      break;
1041
52
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
52
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
52
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
52
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
52
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
52
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
52
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
52
            imp_index);
1080
1081
52
      pe_ILF_save_relocs (&vars, text);
1082
52
      break;
1083
1084
24
    case IMPORT_DATA:
1085
51
    case IMPORT_CONST:
1086
51
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
103
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
103
  switch (import_type)
1095
103
    {
1096
52
    case IMPORT_CODE:
1097
52
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
52
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
52
      break;
1101
1102
24
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
24
      break;
1105
1106
27
    case IMPORT_CONST:
1107
27
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
27
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
103
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
103
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
103
  if (ptr)
1118
10
    *ptr = 0;
1119
103
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
103
  if (ptr)
1121
10
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
103
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
103
  internal_f.f_magic  = magic;
1127
103
  internal_f.f_symptr = 0;
1128
103
  internal_f.f_nsyms  = 0;
1129
103
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
103
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
103
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
103
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
103
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
103
  bfd_cache_close (abfd);
1148
1149
103
  abfd->iostream = (void *) vars.bim;
1150
103
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
103
  abfd->iovec = &_bfd_memory_iovec;
1152
103
  abfd->where = 0;
1153
103
  abfd->origin = 0;
1154
103
  abfd->size = 0;
1155
103
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
103
  obj_symbols (abfd) = vars.sym_cache;
1159
103
  abfd->symcount = vars.sym_index;
1160
1161
103
  obj_raw_syments (abfd) = vars.native_syms;
1162
103
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
103
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
103
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
103
  obj_coff_keep_syms (abfd) = true;
1167
1168
103
  obj_convert (abfd) = vars.sym_table;
1169
103
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
103
  obj_coff_strings (abfd) = vars.string_table;
1172
103
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
103
  obj_coff_keep_strings (abfd) = true;
1174
1175
103
  return true;
1176
1177
6
 error_return:
1178
6
  free (vars.bim->buffer);
1179
6
  free (vars.bim);
1180
  return false;
1181
103
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
126
{
806
126
  bfd_byte *       ptr;
807
126
  pe_ILF_vars      vars;
808
126
  struct internal_filehdr  internal_f;
809
126
  unsigned int       import_type;
810
126
  unsigned int       import_name_type;
811
126
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
126
  coff_symbol_type **    imp_sym;
813
126
  unsigned int       imp_index;
814
126
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
126
  import_type = types & 0x3;
818
126
  import_name_type = (types & 0x1c) >> 2;
819
820
126
  switch (import_type)
821
126
    {
822
43
    case IMPORT_CODE:
823
74
    case IMPORT_DATA:
824
119
    case IMPORT_CONST:
825
119
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
126
    }
833
834
119
  switch (import_name_type)
835
119
    {
836
28
    case IMPORT_ORDINAL:
837
39
    case IMPORT_NAME:
838
56
    case IMPORT_NAME_NOPREFIX:
839
92
    case IMPORT_NAME_UNDECORATE:
840
92
      import_name = symbol_name;
841
92
      break;
842
843
21
    case IMPORT_NAME_EXPORTAS:
844
21
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
9
      break;
852
853
9
    default:
854
      /* xgettext:c-format */
855
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
6
        abfd, import_name_type);
857
6
      return false;
858
119
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
101
  vars.bim
868
101
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
101
  if (vars.bim == NULL)
870
0
    return false;
871
872
101
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
101
  vars.bim->buffer = ptr;
874
101
  vars.bim->size   = ILF_DATA_SIZE;
875
101
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
101
  vars.sym_cache = (coff_symbol_type *) ptr;
881
101
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
101
  vars.sym_index = 0;
883
101
  ptr += SIZEOF_ILF_SYMS;
884
885
101
  vars.sym_table = (unsigned int *) ptr;
886
101
  vars.table_ptr = (unsigned int *) ptr;
887
101
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
101
  vars.native_syms = (combined_entry_type *) ptr;
890
101
  vars.native_ptr  = (combined_entry_type *) ptr;
891
101
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
101
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
101
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
101
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
101
  vars.esym_table = (SYMENT *) ptr;
898
101
  vars.esym_ptr   = (SYMENT *) ptr;
899
101
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
101
  vars.reltab   = (arelent *) ptr;
902
101
  vars.relcount = 0;
903
101
  ptr += SIZEOF_ILF_RELOCS;
904
905
101
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
101
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
101
  vars.string_table = (char *) ptr;
909
101
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
101
  ptr += SIZEOF_ILF_STRINGS;
911
101
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
101
#if GCC_VERSION >= 3000
921
101
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
101
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
101
  vars.data = ptr;
928
101
  vars.abfd = abfd;
929
101
  vars.sec_index = 0;
930
101
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
101
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
101
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
101
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
101
  if (import_name_type == IMPORT_ORDINAL)
946
28
    {
947
28
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
6
  goto error_return;
950
951
22
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
22
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
22
      ((unsigned int *) id4->contents)[0] = ordinal;
954
22
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
22
      ((unsigned int *) id5->contents)[0] = ordinal;
956
22
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
22
    }
962
73
  else
963
73
    {
964
73
      char *symbol;
965
73
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
73
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
73
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
73
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
73
      if (import_name_type != IMPORT_NAME
983
62
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
53
  {
985
53
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
53
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
53
        || c == '@' || c == '?')
991
12
      symbol++;
992
53
  }
993
994
73
      len = strlen (symbol);
995
73
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
36
  {
997
    /* Truncate at the first '@'.  */
998
36
    char *at = strchr (symbol, '@');
999
1000
36
    if (at != NULL)
1001
16
      len = at - symbol;
1002
36
  }
1003
1004
73
      id6->contents[0] = ordinal & 0xff;
1005
73
      id6->contents[1] = ordinal >> 8;
1006
1007
73
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
73
      id6->contents[len + 2] = '\0';
1009
73
    }
1010
1011
95
  if (import_name_type != IMPORT_ORDINAL)
1012
73
    {
1013
73
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
73
      pe_ILF_save_relocs (&vars, id4);
1015
1016
73
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
73
      pe_ILF_save_relocs (&vars, id5);
1018
73
    }
1019
1020
  /* Create an import symbol.  */
1021
95
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
95
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
95
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
95
  switch (import_type)
1028
95
    {
1029
0
      int i;
1030
1031
34
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
68
      for (i = NUM_ENTRIES (jtab); i--;)
1036
68
  {
1037
68
    if (jtab[i].size == 0)
1038
34
      continue;
1039
34
    if (jtab[i].magic == magic)
1040
34
      break;
1041
34
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
34
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
34
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
34
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
34
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
34
#ifdef AMD64MAGIC
1069
34
      if (magic == AMD64MAGIC)
1070
34
  {
1071
34
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
34
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
34
              imp_index);
1074
34
  }
1075
0
      else
1076
0
#endif
1077
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
0
            imp_index);
1080
1081
34
      pe_ILF_save_relocs (&vars, text);
1082
34
      break;
1083
1084
26
    case IMPORT_DATA:
1085
61
    case IMPORT_CONST:
1086
61
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
95
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
95
  switch (import_type)
1095
95
    {
1096
34
    case IMPORT_CODE:
1097
34
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
34
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
34
      break;
1101
1102
26
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
26
      break;
1105
1106
35
    case IMPORT_CONST:
1107
35
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
35
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
95
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
95
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
95
  if (ptr)
1118
14
    *ptr = 0;
1119
95
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
95
  if (ptr)
1121
14
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
95
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
95
  internal_f.f_magic  = magic;
1127
95
  internal_f.f_symptr = 0;
1128
95
  internal_f.f_nsyms  = 0;
1129
95
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
95
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
95
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
95
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
95
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
95
  bfd_cache_close (abfd);
1148
1149
95
  abfd->iostream = (void *) vars.bim;
1150
95
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
95
  abfd->iovec = &_bfd_memory_iovec;
1152
95
  abfd->where = 0;
1153
95
  abfd->origin = 0;
1154
95
  abfd->size = 0;
1155
95
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
95
  obj_symbols (abfd) = vars.sym_cache;
1159
95
  abfd->symcount = vars.sym_index;
1160
1161
95
  obj_raw_syments (abfd) = vars.native_syms;
1162
95
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
95
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
95
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
95
  obj_coff_keep_syms (abfd) = true;
1167
1168
95
  obj_convert (abfd) = vars.sym_table;
1169
95
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
95
  obj_coff_strings (abfd) = vars.string_table;
1172
95
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
95
  obj_coff_keep_strings (abfd) = true;
1174
1175
95
  return true;
1176
1177
6
 error_return:
1178
6
  free (vars.bim->buffer);
1179
6
  free (vars.bim);
1180
  return false;
1181
95
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
122
{
806
122
  bfd_byte *       ptr;
807
122
  pe_ILF_vars      vars;
808
122
  struct internal_filehdr  internal_f;
809
122
  unsigned int       import_type;
810
122
  unsigned int       import_name_type;
811
122
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
122
  coff_symbol_type **    imp_sym;
813
122
  unsigned int       imp_index;
814
122
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
122
  import_type = types & 0x3;
818
122
  import_name_type = (types & 0x1c) >> 2;
819
820
122
  switch (import_type)
821
122
    {
822
50
    case IMPORT_CODE:
823
86
    case IMPORT_DATA:
824
116
    case IMPORT_CONST:
825
116
      break;
826
827
6
    default:
828
      /* xgettext:c-format */
829
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
6
        abfd, import_type);
831
6
      return false;
832
122
    }
833
834
116
  switch (import_name_type)
835
116
    {
836
29
    case IMPORT_ORDINAL:
837
40
    case IMPORT_NAME:
838
55
    case IMPORT_NAME_NOPREFIX:
839
86
    case IMPORT_NAME_UNDECORATE:
840
86
      import_name = symbol_name;
841
86
      break;
842
843
23
    case IMPORT_NAME_EXPORTAS:
844
23
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
11
      break;
852
853
11
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
116
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
97
  vars.bim
868
97
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
97
  if (vars.bim == NULL)
870
0
    return false;
871
872
97
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
97
  vars.bim->buffer = ptr;
874
97
  vars.bim->size   = ILF_DATA_SIZE;
875
97
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
97
  vars.sym_cache = (coff_symbol_type *) ptr;
881
97
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
97
  vars.sym_index = 0;
883
97
  ptr += SIZEOF_ILF_SYMS;
884
885
97
  vars.sym_table = (unsigned int *) ptr;
886
97
  vars.table_ptr = (unsigned int *) ptr;
887
97
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
97
  vars.native_syms = (combined_entry_type *) ptr;
890
97
  vars.native_ptr  = (combined_entry_type *) ptr;
891
97
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
97
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
97
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
97
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
97
  vars.esym_table = (SYMENT *) ptr;
898
97
  vars.esym_ptr   = (SYMENT *) ptr;
899
97
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
97
  vars.reltab   = (arelent *) ptr;
902
97
  vars.relcount = 0;
903
97
  ptr += SIZEOF_ILF_RELOCS;
904
905
97
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
97
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
97
  vars.string_table = (char *) ptr;
909
97
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
97
  ptr += SIZEOF_ILF_STRINGS;
911
97
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
97
#if GCC_VERSION >= 3000
921
97
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
97
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
97
  vars.data = ptr;
928
97
  vars.abfd = abfd;
929
97
  vars.sec_index = 0;
930
97
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
97
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
97
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
97
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
97
  if (import_name_type == IMPORT_ORDINAL)
946
29
    {
947
29
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
6
  goto error_return;
950
951
23
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
23
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
23
      ((unsigned int *) id4->contents)[0] = ordinal;
954
23
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
23
      ((unsigned int *) id5->contents)[0] = ordinal;
956
23
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
23
    }
962
68
  else
963
68
    {
964
68
      char *symbol;
965
68
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
68
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
68
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
68
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
68
      if (import_name_type != IMPORT_NAME
983
57
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
46
  {
985
46
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
46
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
46
        || c == '@' || c == '?')
991
12
      symbol++;
992
46
  }
993
994
68
      len = strlen (symbol);
995
68
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
31
  {
997
    /* Truncate at the first '@'.  */
998
31
    char *at = strchr (symbol, '@');
999
1000
31
    if (at != NULL)
1001
5
      len = at - symbol;
1002
31
  }
1003
1004
68
      id6->contents[0] = ordinal & 0xff;
1005
68
      id6->contents[1] = ordinal >> 8;
1006
1007
68
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
68
      id6->contents[len + 2] = '\0';
1009
68
    }
1010
1011
91
  if (import_name_type != IMPORT_ORDINAL)
1012
68
    {
1013
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
68
      pe_ILF_save_relocs (&vars, id4);
1015
1016
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
68
      pe_ILF_save_relocs (&vars, id5);
1018
68
    }
1019
1020
  /* Create an import symbol.  */
1021
91
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
91
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
91
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
91
  switch (import_type)
1028
91
    {
1029
0
      int i;
1030
1031
40
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
80
      for (i = NUM_ENTRIES (jtab); i--;)
1036
80
  {
1037
80
    if (jtab[i].size == 0)
1038
40
      continue;
1039
40
    if (jtab[i].magic == magic)
1040
40
      break;
1041
40
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
40
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
40
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
40
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
40
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
40
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
40
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
40
            imp_index);
1080
1081
40
      pe_ILF_save_relocs (&vars, text);
1082
40
      break;
1083
1084
28
    case IMPORT_DATA:
1085
51
    case IMPORT_CONST:
1086
51
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
91
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
91
  switch (import_type)
1095
91
    {
1096
40
    case IMPORT_CODE:
1097
40
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
40
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
40
      break;
1101
1102
28
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
28
      break;
1105
1106
23
    case IMPORT_CONST:
1107
23
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
23
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
91
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
91
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
91
  if (ptr)
1118
13
    *ptr = 0;
1119
91
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
91
  if (ptr)
1121
13
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
91
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
91
  internal_f.f_magic  = magic;
1127
91
  internal_f.f_symptr = 0;
1128
91
  internal_f.f_nsyms  = 0;
1129
91
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
91
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
91
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
91
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
91
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
91
  bfd_cache_close (abfd);
1148
1149
91
  abfd->iostream = (void *) vars.bim;
1150
91
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
91
  abfd->iovec = &_bfd_memory_iovec;
1152
91
  abfd->where = 0;
1153
91
  abfd->origin = 0;
1154
91
  abfd->size = 0;
1155
91
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
91
  obj_symbols (abfd) = vars.sym_cache;
1159
91
  abfd->symcount = vars.sym_index;
1160
1161
91
  obj_raw_syments (abfd) = vars.native_syms;
1162
91
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
91
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
91
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
91
  obj_coff_keep_syms (abfd) = true;
1167
1168
91
  obj_convert (abfd) = vars.sym_table;
1169
91
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
91
  obj_coff_strings (abfd) = vars.string_table;
1172
91
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
91
  obj_coff_keep_strings (abfd) = true;
1174
1175
91
  return true;
1176
1177
6
 error_return:
1178
6
  free (vars.bim->buffer);
1179
6
  free (vars.bim);
1180
  return false;
1181
91
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
133
{
806
133
  bfd_byte *       ptr;
807
133
  pe_ILF_vars      vars;
808
133
  struct internal_filehdr  internal_f;
809
133
  unsigned int       import_type;
810
133
  unsigned int       import_name_type;
811
133
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
133
  coff_symbol_type **    imp_sym;
813
133
  unsigned int       imp_index;
814
133
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
133
  import_type = types & 0x3;
818
133
  import_name_type = (types & 0x1c) >> 2;
819
820
133
  switch (import_type)
821
133
    {
822
64
    case IMPORT_CODE:
823
109
    case IMPORT_DATA:
824
127
    case IMPORT_CONST:
825
127
      break;
826
827
6
    default:
828
      /* xgettext:c-format */
829
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
6
        abfd, import_type);
831
6
      return false;
832
133
    }
833
834
127
  switch (import_name_type)
835
127
    {
836
32
    case IMPORT_ORDINAL:
837
42
    case IMPORT_NAME:
838
59
    case IMPORT_NAME_NOPREFIX:
839
97
    case IMPORT_NAME_UNDECORATE:
840
97
      import_name = symbol_name;
841
97
      break;
842
843
24
    case IMPORT_NAME_EXPORTAS:
844
24
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
12
      break;
852
853
12
    default:
854
      /* xgettext:c-format */
855
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
6
        abfd, import_name_type);
857
6
      return false;
858
127
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
109
  vars.bim
868
109
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
109
  if (vars.bim == NULL)
870
0
    return false;
871
872
109
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
109
  vars.bim->buffer = ptr;
874
109
  vars.bim->size   = ILF_DATA_SIZE;
875
109
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
109
  vars.sym_cache = (coff_symbol_type *) ptr;
881
109
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
109
  vars.sym_index = 0;
883
109
  ptr += SIZEOF_ILF_SYMS;
884
885
109
  vars.sym_table = (unsigned int *) ptr;
886
109
  vars.table_ptr = (unsigned int *) ptr;
887
109
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
109
  vars.native_syms = (combined_entry_type *) ptr;
890
109
  vars.native_ptr  = (combined_entry_type *) ptr;
891
109
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
109
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
109
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
109
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
109
  vars.esym_table = (SYMENT *) ptr;
898
109
  vars.esym_ptr   = (SYMENT *) ptr;
899
109
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
109
  vars.reltab   = (arelent *) ptr;
902
109
  vars.relcount = 0;
903
109
  ptr += SIZEOF_ILF_RELOCS;
904
905
109
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
109
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
109
  vars.string_table = (char *) ptr;
909
109
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
109
  ptr += SIZEOF_ILF_STRINGS;
911
109
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
109
#if GCC_VERSION >= 3000
921
109
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
109
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
109
  vars.data = ptr;
928
109
  vars.abfd = abfd;
929
109
  vars.sec_index = 0;
930
109
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
109
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
109
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
109
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
109
  if (import_name_type == IMPORT_ORDINAL)
946
32
    {
947
32
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
7
  goto error_return;
950
951
25
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
25
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
25
      ((unsigned int *) id4->contents)[0] = ordinal;
954
25
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
25
      ((unsigned int *) id5->contents)[0] = ordinal;
956
25
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
25
    }
962
77
  else
963
77
    {
964
77
      char *symbol;
965
77
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
77
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
77
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
77
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
77
      if (import_name_type != IMPORT_NAME
983
67
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
55
  {
985
55
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
55
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
55
        || c == '@' || c == '?')
991
12
      symbol++;
992
55
  }
993
994
77
      len = strlen (symbol);
995
77
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
38
  {
997
    /* Truncate at the first '@'.  */
998
38
    char *at = strchr (symbol, '@');
999
1000
38
    if (at != NULL)
1001
10
      len = at - symbol;
1002
38
  }
1003
1004
77
      id6->contents[0] = ordinal & 0xff;
1005
77
      id6->contents[1] = ordinal >> 8;
1006
1007
77
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
77
      id6->contents[len + 2] = '\0';
1009
77
    }
1010
1011
102
  if (import_name_type != IMPORT_ORDINAL)
1012
77
    {
1013
77
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
77
      pe_ILF_save_relocs (&vars, id4);
1015
1016
77
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
77
      pe_ILF_save_relocs (&vars, id5);
1018
77
    }
1019
1020
  /* Create an import symbol.  */
1021
102
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
102
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
102
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
102
  switch (import_type)
1028
102
    {
1029
0
      int i;
1030
1031
50
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
100
      for (i = NUM_ENTRIES (jtab); i--;)
1036
100
  {
1037
100
    if (jtab[i].size == 0)
1038
50
      continue;
1039
50
    if (jtab[i].magic == magic)
1040
50
      break;
1041
50
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
50
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
50
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
50
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
50
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
50
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
50
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
50
            imp_index);
1080
1081
50
      pe_ILF_save_relocs (&vars, text);
1082
50
      break;
1083
1084
40
    case IMPORT_DATA:
1085
52
    case IMPORT_CONST:
1086
52
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
102
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
102
  switch (import_type)
1095
102
    {
1096
50
    case IMPORT_CODE:
1097
50
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
50
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
50
      break;
1101
1102
40
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
40
      break;
1105
1106
12
    case IMPORT_CONST:
1107
12
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
12
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
102
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
102
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
102
  if (ptr)
1118
10
    *ptr = 0;
1119
102
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
102
  if (ptr)
1121
10
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
102
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
102
  internal_f.f_magic  = magic;
1127
102
  internal_f.f_symptr = 0;
1128
102
  internal_f.f_nsyms  = 0;
1129
102
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
102
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
102
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
102
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
102
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
102
  bfd_cache_close (abfd);
1148
1149
102
  abfd->iostream = (void *) vars.bim;
1150
102
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
102
  abfd->iovec = &_bfd_memory_iovec;
1152
102
  abfd->where = 0;
1153
102
  abfd->origin = 0;
1154
102
  abfd->size = 0;
1155
102
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
102
  obj_symbols (abfd) = vars.sym_cache;
1159
102
  abfd->symcount = vars.sym_index;
1160
1161
102
  obj_raw_syments (abfd) = vars.native_syms;
1162
102
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
102
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
102
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
102
  obj_coff_keep_syms (abfd) = true;
1167
1168
102
  obj_convert (abfd) = vars.sym_table;
1169
102
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
102
  obj_coff_strings (abfd) = vars.string_table;
1172
102
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
102
  obj_coff_keep_strings (abfd) = true;
1174
1175
102
  return true;
1176
1177
7
 error_return:
1178
7
  free (vars.bim->buffer);
1179
7
  free (vars.bim);
1180
  return false;
1181
102
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
131
{
806
131
  bfd_byte *       ptr;
807
131
  pe_ILF_vars      vars;
808
131
  struct internal_filehdr  internal_f;
809
131
  unsigned int       import_type;
810
131
  unsigned int       import_name_type;
811
131
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
131
  coff_symbol_type **    imp_sym;
813
131
  unsigned int       imp_index;
814
131
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
131
  import_type = types & 0x3;
818
131
  import_name_type = (types & 0x1c) >> 2;
819
820
131
  switch (import_type)
821
131
    {
822
51
    case IMPORT_CODE:
823
78
    case IMPORT_DATA:
824
125
    case IMPORT_CONST:
825
125
      break;
826
827
6
    default:
828
      /* xgettext:c-format */
829
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
6
        abfd, import_type);
831
6
      return false;
832
131
    }
833
834
125
  switch (import_name_type)
835
125
    {
836
31
    case IMPORT_ORDINAL:
837
40
    case IMPORT_NAME:
838
60
    case IMPORT_NAME_NOPREFIX:
839
97
    case IMPORT_NAME_UNDECORATE:
840
97
      import_name = symbol_name;
841
97
      break;
842
843
22
    case IMPORT_NAME_EXPORTAS:
844
22
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
10
      break;
852
853
10
    default:
854
      /* xgettext:c-format */
855
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
6
        abfd, import_name_type);
857
6
      return false;
858
125
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
107
  vars.bim
868
107
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
107
  if (vars.bim == NULL)
870
0
    return false;
871
872
107
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
107
  vars.bim->buffer = ptr;
874
107
  vars.bim->size   = ILF_DATA_SIZE;
875
107
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
107
  vars.sym_cache = (coff_symbol_type *) ptr;
881
107
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
107
  vars.sym_index = 0;
883
107
  ptr += SIZEOF_ILF_SYMS;
884
885
107
  vars.sym_table = (unsigned int *) ptr;
886
107
  vars.table_ptr = (unsigned int *) ptr;
887
107
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
107
  vars.native_syms = (combined_entry_type *) ptr;
890
107
  vars.native_ptr  = (combined_entry_type *) ptr;
891
107
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
107
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
107
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
107
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
107
  vars.esym_table = (SYMENT *) ptr;
898
107
  vars.esym_ptr   = (SYMENT *) ptr;
899
107
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
107
  vars.reltab   = (arelent *) ptr;
902
107
  vars.relcount = 0;
903
107
  ptr += SIZEOF_ILF_RELOCS;
904
905
107
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
107
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
107
  vars.string_table = (char *) ptr;
909
107
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
107
  ptr += SIZEOF_ILF_STRINGS;
911
107
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
107
#if GCC_VERSION >= 3000
921
107
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
107
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
107
  vars.data = ptr;
928
107
  vars.abfd = abfd;
929
107
  vars.sec_index = 0;
930
107
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
107
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
107
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
107
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
107
  if (import_name_type == IMPORT_ORDINAL)
946
31
    {
947
31
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
6
  goto error_return;
950
951
25
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
25
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
25
      ((unsigned int *) id4->contents)[0] = ordinal;
954
25
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
25
      ((unsigned int *) id5->contents)[0] = ordinal;
956
25
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
25
    }
962
76
  else
963
76
    {
964
76
      char *symbol;
965
76
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
76
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
76
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
76
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
76
      if (import_name_type != IMPORT_NAME
983
67
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
57
  {
985
57
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
57
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
57
        || c == '@' || c == '?')
991
18
      symbol++;
992
57
  }
993
994
76
      len = strlen (symbol);
995
76
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
37
  {
997
    /* Truncate at the first '@'.  */
998
37
    char *at = strchr (symbol, '@');
999
1000
37
    if (at != NULL)
1001
11
      len = at - symbol;
1002
37
  }
1003
1004
76
      id6->contents[0] = ordinal & 0xff;
1005
76
      id6->contents[1] = ordinal >> 8;
1006
1007
76
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
76
      id6->contents[len + 2] = '\0';
1009
76
    }
1010
1011
101
  if (import_name_type != IMPORT_ORDINAL)
1012
76
    {
1013
76
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
76
      pe_ILF_save_relocs (&vars, id4);
1015
1016
76
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
76
      pe_ILF_save_relocs (&vars, id5);
1018
76
    }
1019
1020
  /* Create an import symbol.  */
1021
101
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
101
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
101
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
101
  switch (import_type)
1028
101
    {
1029
0
      int i;
1030
1031
36
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
72
      for (i = NUM_ENTRIES (jtab); i--;)
1036
72
  {
1037
72
    if (jtab[i].size == 0)
1038
36
      continue;
1039
36
    if (jtab[i].magic == magic)
1040
36
      break;
1041
36
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
36
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
36
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
36
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
36
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
36
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
36
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
36
            imp_index);
1080
1081
36
      pe_ILF_save_relocs (&vars, text);
1082
36
      break;
1083
1084
25
    case IMPORT_DATA:
1085
65
    case IMPORT_CONST:
1086
65
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
101
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
101
  switch (import_type)
1095
101
    {
1096
36
    case IMPORT_CODE:
1097
36
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
36
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
36
      break;
1101
1102
25
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
25
      break;
1105
1106
40
    case IMPORT_CONST:
1107
40
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
40
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
101
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
101
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
101
  if (ptr)
1118
20
    *ptr = 0;
1119
101
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
101
  if (ptr)
1121
20
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
101
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
101
  internal_f.f_magic  = magic;
1127
101
  internal_f.f_symptr = 0;
1128
101
  internal_f.f_nsyms  = 0;
1129
101
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
101
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
101
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
101
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
101
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
101
  bfd_cache_close (abfd);
1148
1149
101
  abfd->iostream = (void *) vars.bim;
1150
101
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
101
  abfd->iovec = &_bfd_memory_iovec;
1152
101
  abfd->where = 0;
1153
101
  abfd->origin = 0;
1154
101
  abfd->size = 0;
1155
101
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
101
  obj_symbols (abfd) = vars.sym_cache;
1159
101
  abfd->symcount = vars.sym_index;
1160
1161
101
  obj_raw_syments (abfd) = vars.native_syms;
1162
101
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
101
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
101
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
101
  obj_coff_keep_syms (abfd) = true;
1167
1168
101
  obj_convert (abfd) = vars.sym_table;
1169
101
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
101
  obj_coff_strings (abfd) = vars.string_table;
1172
101
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
101
  obj_coff_keep_strings (abfd) = true;
1174
1175
101
  return true;
1176
1177
6
 error_return:
1178
6
  free (vars.bim->buffer);
1179
6
  free (vars.bim);
1180
  return false;
1181
101
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
805
106
{
806
106
  bfd_byte *       ptr;
807
106
  pe_ILF_vars      vars;
808
106
  struct internal_filehdr  internal_f;
809
106
  unsigned int       import_type;
810
106
  unsigned int       import_name_type;
811
106
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
106
  coff_symbol_type **    imp_sym;
813
106
  unsigned int       imp_index;
814
106
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
106
  import_type = types & 0x3;
818
106
  import_name_type = (types & 0x1c) >> 2;
819
820
106
  switch (import_type)
821
106
    {
822
50
    case IMPORT_CODE:
823
82
    case IMPORT_DATA:
824
100
    case IMPORT_CONST:
825
100
      break;
826
827
6
    default:
828
      /* xgettext:c-format */
829
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
6
        abfd, import_type);
831
6
      return false;
832
106
    }
833
834
100
  switch (import_name_type)
835
100
    {
836
24
    case IMPORT_ORDINAL:
837
32
    case IMPORT_NAME:
838
51
    case IMPORT_NAME_NOPREFIX:
839
76
    case IMPORT_NAME_UNDECORATE:
840
76
      import_name = symbol_name;
841
76
      break;
842
843
18
    case IMPORT_NAME_EXPORTAS:
844
18
      if (!import_name || !import_name[0])
845
13
  {
846
13
    _bfd_error_handler (_("%pB: missing import name for "
847
13
        "IMPORT_NAME_EXPORTAS for %s"),
848
13
            abfd, symbol_name);
849
13
    return false;
850
13
  }
851
5
      break;
852
853
6
    default:
854
      /* xgettext:c-format */
855
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
6
        abfd, import_name_type);
857
6
      return false;
858
100
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
81
  vars.bim
868
81
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
81
  if (vars.bim == NULL)
870
0
    return false;
871
872
81
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
81
  vars.bim->buffer = ptr;
874
81
  vars.bim->size   = ILF_DATA_SIZE;
875
81
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
81
  vars.sym_cache = (coff_symbol_type *) ptr;
881
81
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
81
  vars.sym_index = 0;
883
81
  ptr += SIZEOF_ILF_SYMS;
884
885
81
  vars.sym_table = (unsigned int *) ptr;
886
81
  vars.table_ptr = (unsigned int *) ptr;
887
81
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
81
  vars.native_syms = (combined_entry_type *) ptr;
890
81
  vars.native_ptr  = (combined_entry_type *) ptr;
891
81
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
81
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
81
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
81
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
81
  vars.esym_table = (SYMENT *) ptr;
898
81
  vars.esym_ptr   = (SYMENT *) ptr;
899
81
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
81
  vars.reltab   = (arelent *) ptr;
902
81
  vars.relcount = 0;
903
81
  ptr += SIZEOF_ILF_RELOCS;
904
905
81
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
81
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
81
  vars.string_table = (char *) ptr;
909
81
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
81
  ptr += SIZEOF_ILF_STRINGS;
911
81
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
81
#if GCC_VERSION >= 3000
921
81
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
81
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
81
  vars.data = ptr;
928
81
  vars.abfd = abfd;
929
81
  vars.sec_index = 0;
930
81
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
81
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
81
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
81
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
81
  if (import_name_type == IMPORT_ORDINAL)
946
24
    {
947
24
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
8
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
16
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
16
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
16
#endif
961
16
    }
962
57
  else
963
57
    {
964
57
      char *symbol;
965
57
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
57
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
57
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
57
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
57
      if (import_name_type != IMPORT_NAME
983
49
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
44
  {
985
44
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
44
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
44
        || c == '@' || c == '?')
991
10
      symbol++;
992
44
  }
993
994
57
      len = strlen (symbol);
995
57
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
25
  {
997
    /* Truncate at the first '@'.  */
998
25
    char *at = strchr (symbol, '@');
999
1000
25
    if (at != NULL)
1001
5
      len = at - symbol;
1002
25
  }
1003
1004
57
      id6->contents[0] = ordinal & 0xff;
1005
57
      id6->contents[1] = ordinal >> 8;
1006
1007
57
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
57
      id6->contents[len + 2] = '\0';
1009
57
    }
1010
1011
73
  if (import_name_type != IMPORT_ORDINAL)
1012
57
    {
1013
57
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
57
      pe_ILF_save_relocs (&vars, id4);
1015
1016
57
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
57
      pe_ILF_save_relocs (&vars, id5);
1018
57
    }
1019
1020
  /* Create an import symbol.  */
1021
73
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
73
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
73
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
73
  switch (import_type)
1028
73
    {
1029
0
      int i;
1030
1031
36
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
88
      for (i = NUM_ENTRIES (jtab); i--;)
1036
88
  {
1037
88
    if (jtab[i].size == 0)
1038
36
      continue;
1039
52
    if (jtab[i].magic == magic)
1040
36
      break;
1041
52
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
36
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
36
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
36
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
36
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
36
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
36
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
36
            imp_index);
1080
1081
36
      pe_ILF_save_relocs (&vars, text);
1082
36
      break;
1083
1084
22
    case IMPORT_DATA:
1085
37
    case IMPORT_CONST:
1086
37
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
73
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
73
  switch (import_type)
1095
73
    {
1096
36
    case IMPORT_CODE:
1097
36
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
36
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
36
      break;
1101
1102
22
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
22
      break;
1105
1106
15
    case IMPORT_CONST:
1107
15
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
15
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
73
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
73
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
73
  if (ptr)
1118
6
    *ptr = 0;
1119
73
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
73
  if (ptr)
1121
6
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
73
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
73
  internal_f.f_magic  = magic;
1127
73
  internal_f.f_symptr = 0;
1128
73
  internal_f.f_nsyms  = 0;
1129
73
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
73
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
73
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
73
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
73
  obj_pe (abfd) = true;
1139
73
#ifdef THUMBPEMAGIC
1140
73
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
44
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
73
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
73
  bfd_cache_close (abfd);
1148
1149
73
  abfd->iostream = (void *) vars.bim;
1150
73
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
73
  abfd->iovec = &_bfd_memory_iovec;
1152
73
  abfd->where = 0;
1153
73
  abfd->origin = 0;
1154
73
  abfd->size = 0;
1155
73
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
73
  obj_symbols (abfd) = vars.sym_cache;
1159
73
  abfd->symcount = vars.sym_index;
1160
1161
73
  obj_raw_syments (abfd) = vars.native_syms;
1162
73
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
73
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
73
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
73
  obj_coff_keep_syms (abfd) = true;
1167
1168
73
  obj_convert (abfd) = vars.sym_table;
1169
73
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
73
  obj_coff_strings (abfd) = vars.string_table;
1172
73
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
73
  obj_coff_keep_strings (abfd) = true;
1174
1175
73
  return true;
1176
1177
8
 error_return:
1178
8
  free (vars.bim->buffer);
1179
8
  free (vars.bim);
1180
  return false;
1181
73
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
805
108
{
806
108
  bfd_byte *       ptr;
807
108
  pe_ILF_vars      vars;
808
108
  struct internal_filehdr  internal_f;
809
108
  unsigned int       import_type;
810
108
  unsigned int       import_name_type;
811
108
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
108
  coff_symbol_type **    imp_sym;
813
108
  unsigned int       imp_index;
814
108
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
108
  import_type = types & 0x3;
818
108
  import_name_type = (types & 0x1c) >> 2;
819
820
108
  switch (import_type)
821
108
    {
822
52
    case IMPORT_CODE:
823
84
    case IMPORT_DATA:
824
102
    case IMPORT_CONST:
825
102
      break;
826
827
6
    default:
828
      /* xgettext:c-format */
829
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
6
        abfd, import_type);
831
6
      return false;
832
108
    }
833
834
102
  switch (import_name_type)
835
102
    {
836
25
    case IMPORT_ORDINAL:
837
33
    case IMPORT_NAME:
838
53
    case IMPORT_NAME_NOPREFIX:
839
78
    case IMPORT_NAME_UNDECORATE:
840
78
      import_name = symbol_name;
841
78
      break;
842
843
18
    case IMPORT_NAME_EXPORTAS:
844
18
      if (!import_name || !import_name[0])
845
13
  {
846
13
    _bfd_error_handler (_("%pB: missing import name for "
847
13
        "IMPORT_NAME_EXPORTAS for %s"),
848
13
            abfd, symbol_name);
849
13
    return false;
850
13
  }
851
5
      break;
852
853
6
    default:
854
      /* xgettext:c-format */
855
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
6
        abfd, import_name_type);
857
6
      return false;
858
102
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
83
  vars.bim
868
83
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
83
  if (vars.bim == NULL)
870
0
    return false;
871
872
83
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
83
  vars.bim->buffer = ptr;
874
83
  vars.bim->size   = ILF_DATA_SIZE;
875
83
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
83
  vars.sym_cache = (coff_symbol_type *) ptr;
881
83
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
83
  vars.sym_index = 0;
883
83
  ptr += SIZEOF_ILF_SYMS;
884
885
83
  vars.sym_table = (unsigned int *) ptr;
886
83
  vars.table_ptr = (unsigned int *) ptr;
887
83
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
83
  vars.native_syms = (combined_entry_type *) ptr;
890
83
  vars.native_ptr  = (combined_entry_type *) ptr;
891
83
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
83
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
83
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
83
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
83
  vars.esym_table = (SYMENT *) ptr;
898
83
  vars.esym_ptr   = (SYMENT *) ptr;
899
83
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
83
  vars.reltab   = (arelent *) ptr;
902
83
  vars.relcount = 0;
903
83
  ptr += SIZEOF_ILF_RELOCS;
904
905
83
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
83
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
83
  vars.string_table = (char *) ptr;
909
83
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
83
  ptr += SIZEOF_ILF_STRINGS;
911
83
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
83
#if GCC_VERSION >= 3000
921
83
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
83
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
83
  vars.data = ptr;
928
83
  vars.abfd = abfd;
929
83
  vars.sec_index = 0;
930
83
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
83
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
83
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
83
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
83
  if (import_name_type == IMPORT_ORDINAL)
946
25
    {
947
25
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
8
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
17
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
17
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
17
#endif
961
17
    }
962
58
  else
963
58
    {
964
58
      char *symbol;
965
58
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
58
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
58
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
58
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
58
      if (import_name_type != IMPORT_NAME
983
50
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
45
  {
985
45
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
45
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
41
        || c == '@' || c == '?')
991
14
      symbol++;
992
45
  }
993
994
58
      len = strlen (symbol);
995
58
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
25
  {
997
    /* Truncate at the first '@'.  */
998
25
    char *at = strchr (symbol, '@');
999
1000
25
    if (at != NULL)
1001
5
      len = at - symbol;
1002
25
  }
1003
1004
58
      id6->contents[0] = ordinal & 0xff;
1005
58
      id6->contents[1] = ordinal >> 8;
1006
1007
58
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
58
      id6->contents[len + 2] = '\0';
1009
58
    }
1010
1011
75
  if (import_name_type != IMPORT_ORDINAL)
1012
58
    {
1013
58
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
58
      pe_ILF_save_relocs (&vars, id4);
1015
1016
58
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
58
      pe_ILF_save_relocs (&vars, id5);
1018
58
    }
1019
1020
  /* Create an import symbol.  */
1021
75
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
75
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
75
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
75
  switch (import_type)
1028
75
    {
1029
0
      int i;
1030
1031
38
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
94
      for (i = NUM_ENTRIES (jtab); i--;)
1036
94
  {
1037
94
    if (jtab[i].size == 0)
1038
38
      continue;
1039
56
    if (jtab[i].magic == magic)
1040
38
      break;
1041
56
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
38
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
38
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
38
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
38
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
38
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
38
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
38
            imp_index);
1080
1081
38
      pe_ILF_save_relocs (&vars, text);
1082
38
      break;
1083
1084
22
    case IMPORT_DATA:
1085
37
    case IMPORT_CONST:
1086
37
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
75
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
75
  switch (import_type)
1095
75
    {
1096
38
    case IMPORT_CODE:
1097
38
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
38
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
38
      break;
1101
1102
22
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
22
      break;
1105
1106
15
    case IMPORT_CONST:
1107
15
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
15
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
75
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
75
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
75
  if (ptr)
1118
6
    *ptr = 0;
1119
75
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
75
  if (ptr)
1121
6
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
75
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
75
  internal_f.f_magic  = magic;
1127
75
  internal_f.f_symptr = 0;
1128
75
  internal_f.f_nsyms  = 0;
1129
75
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
75
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
75
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
75
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
75
  obj_pe (abfd) = true;
1139
75
#ifdef THUMBPEMAGIC
1140
75
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
44
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
75
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
75
  bfd_cache_close (abfd);
1148
1149
75
  abfd->iostream = (void *) vars.bim;
1150
75
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
75
  abfd->iovec = &_bfd_memory_iovec;
1152
75
  abfd->where = 0;
1153
75
  abfd->origin = 0;
1154
75
  abfd->size = 0;
1155
75
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
75
  obj_symbols (abfd) = vars.sym_cache;
1159
75
  abfd->symcount = vars.sym_index;
1160
1161
75
  obj_raw_syments (abfd) = vars.native_syms;
1162
75
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
75
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
75
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
75
  obj_coff_keep_syms (abfd) = true;
1167
1168
75
  obj_convert (abfd) = vars.sym_table;
1169
75
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
75
  obj_coff_strings (abfd) = vars.string_table;
1172
75
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
75
  obj_coff_keep_strings (abfd) = true;
1174
1175
75
  return true;
1176
1177
8
 error_return:
1178
8
  free (vars.bim->buffer);
1179
8
  free (vars.bim);
1180
  return false;
1181
75
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
805
265
{
806
265
  bfd_byte *       ptr;
807
265
  pe_ILF_vars      vars;
808
265
  struct internal_filehdr  internal_f;
809
265
  unsigned int       import_type;
810
265
  unsigned int       import_name_type;
811
265
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
265
  coff_symbol_type **    imp_sym;
813
265
  unsigned int       imp_index;
814
265
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
265
  import_type = types & 0x3;
818
265
  import_name_type = (types & 0x1c) >> 2;
819
820
265
  switch (import_type)
821
265
    {
822
94
    case IMPORT_CODE:
823
160
    case IMPORT_DATA:
824
201
    case IMPORT_CONST:
825
201
      break;
826
827
64
    default:
828
      /* xgettext:c-format */
829
64
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
64
        abfd, import_type);
831
64
      return false;
832
265
    }
833
834
201
  switch (import_name_type)
835
201
    {
836
40
    case IMPORT_ORDINAL:
837
57
    case IMPORT_NAME:
838
81
    case IMPORT_NAME_NOPREFIX:
839
151
    case IMPORT_NAME_UNDECORATE:
840
151
      import_name = symbol_name;
841
151
      break;
842
843
43
    case IMPORT_NAME_EXPORTAS:
844
43
      if (!import_name || !import_name[0])
845
21
  {
846
21
    _bfd_error_handler (_("%pB: missing import name for "
847
21
        "IMPORT_NAME_EXPORTAS for %s"),
848
21
            abfd, symbol_name);
849
21
    return false;
850
21
  }
851
22
      break;
852
853
22
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
201
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
173
  vars.bim
868
173
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
173
  if (vars.bim == NULL)
870
0
    return false;
871
872
173
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
173
  vars.bim->buffer = ptr;
874
173
  vars.bim->size   = ILF_DATA_SIZE;
875
173
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
173
  vars.sym_cache = (coff_symbol_type *) ptr;
881
173
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
173
  vars.sym_index = 0;
883
173
  ptr += SIZEOF_ILF_SYMS;
884
885
173
  vars.sym_table = (unsigned int *) ptr;
886
173
  vars.table_ptr = (unsigned int *) ptr;
887
173
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
173
  vars.native_syms = (combined_entry_type *) ptr;
890
173
  vars.native_ptr  = (combined_entry_type *) ptr;
891
173
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
173
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
173
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
173
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
173
  vars.esym_table = (SYMENT *) ptr;
898
173
  vars.esym_ptr   = (SYMENT *) ptr;
899
173
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
173
  vars.reltab   = (arelent *) ptr;
902
173
  vars.relcount = 0;
903
173
  ptr += SIZEOF_ILF_RELOCS;
904
905
173
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
173
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
173
  vars.string_table = (char *) ptr;
909
173
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
173
  ptr += SIZEOF_ILF_STRINGS;
911
173
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
173
#if GCC_VERSION >= 3000
921
173
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
173
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
173
  vars.data = ptr;
928
173
  vars.abfd = abfd;
929
173
  vars.sec_index = 0;
930
173
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
173
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
173
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
173
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
173
  if (import_name_type == IMPORT_ORDINAL)
946
40
    {
947
40
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
9
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
31
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
31
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
31
#endif
961
31
    }
962
133
  else
963
133
    {
964
133
      char *symbol;
965
133
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
133
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
133
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
133
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
133
      if (import_name_type != IMPORT_NAME
983
116
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
94
  {
985
94
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
94
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
85
        || c == '@' || c == '?')
991
24
      symbol++;
992
94
  }
993
994
133
      len = strlen (symbol);
995
133
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
70
  {
997
    /* Truncate at the first '@'.  */
998
70
    char *at = strchr (symbol, '@');
999
1000
70
    if (at != NULL)
1001
10
      len = at - symbol;
1002
70
  }
1003
1004
133
      id6->contents[0] = ordinal & 0xff;
1005
133
      id6->contents[1] = ordinal >> 8;
1006
1007
133
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
133
      id6->contents[len + 2] = '\0';
1009
133
    }
1010
1011
164
  if (import_name_type != IMPORT_ORDINAL)
1012
133
    {
1013
133
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
133
      pe_ILF_save_relocs (&vars, id4);
1015
1016
133
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
133
      pe_ILF_save_relocs (&vars, id5);
1018
133
    }
1019
1020
  /* Create an import symbol.  */
1021
164
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
164
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
164
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
164
  switch (import_type)
1028
164
    {
1029
0
      int i;
1030
1031
69
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
138
      for (i = NUM_ENTRIES (jtab); i--;)
1036
138
  {
1037
138
    if (jtab[i].size == 0)
1038
69
      continue;
1039
69
    if (jtab[i].magic == magic)
1040
69
      break;
1041
69
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
69
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
69
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
69
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
69
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
69
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
69
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
69
            imp_index);
1080
1081
69
      pe_ILF_save_relocs (&vars, text);
1082
69
      break;
1083
1084
60
    case IMPORT_DATA:
1085
95
    case IMPORT_CONST:
1086
95
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
164
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
164
  switch (import_type)
1095
164
    {
1096
69
    case IMPORT_CODE:
1097
69
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
69
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
69
      break;
1101
1102
60
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
60
      break;
1105
1106
35
    case IMPORT_CONST:
1107
35
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
35
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
164
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
164
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
164
  if (ptr)
1118
10
    *ptr = 0;
1119
164
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
164
  if (ptr)
1121
10
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
164
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
164
  internal_f.f_magic  = magic;
1127
164
  internal_f.f_symptr = 0;
1128
164
  internal_f.f_nsyms  = 0;
1129
164
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
164
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
164
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
164
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
164
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
164
  bfd_cache_close (abfd);
1148
1149
164
  abfd->iostream = (void *) vars.bim;
1150
164
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
164
  abfd->iovec = &_bfd_memory_iovec;
1152
164
  abfd->where = 0;
1153
164
  abfd->origin = 0;
1154
164
  abfd->size = 0;
1155
164
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
164
  obj_symbols (abfd) = vars.sym_cache;
1159
164
  abfd->symcount = vars.sym_index;
1160
1161
164
  obj_raw_syments (abfd) = vars.native_syms;
1162
164
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
164
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
164
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
164
  obj_coff_keep_syms (abfd) = true;
1167
1168
164
  obj_convert (abfd) = vars.sym_table;
1169
164
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
164
  obj_coff_strings (abfd) = vars.string_table;
1172
164
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
164
  obj_coff_keep_strings (abfd) = true;
1174
1175
164
  return true;
1176
1177
9
 error_return:
1178
9
  free (vars.bim->buffer);
1179
9
  free (vars.bim);
1180
  return false;
1181
164
}
1182
1183
/* Cleanup function, returned from check_format hook.  */
1184
1185
static void
1186
pe_ILF_cleanup (bfd *abfd)
1187
70
{
1188
70
  coff_object_cleanup (abfd);
1189
1190
70
  struct bfd_in_memory *bim = abfd->iostream;
1191
70
  free (bim->buffer);
1192
70
  free (bim);
1193
70
  abfd->iostream = NULL;
1194
70
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-riscv64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1187
35
{
1188
35
  coff_object_cleanup (abfd);
1189
1190
35
  struct bfd_in_memory *bim = abfd->iostream;
1191
35
  free (bim->buffer);
1192
35
  free (bim);
1193
  abfd->iostream = NULL;
1194
35
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1187
35
{
1188
35
  coff_object_cleanup (abfd);
1189
1190
35
  struct bfd_in_memory *bim = abfd->iostream;
1191
35
  free (bim->buffer);
1192
35
  free (bim);
1193
  abfd->iostream = NULL;
1194
35
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1195
1196
/* We have detected an Import Library Format archive element.
1197
   Decode the element and return the appropriate target.  */
1198
1199
static bfd_cleanup
1200
pe_ILF_object_p (bfd *abfd)
1201
36.6k
{
1202
36.6k
  bfd_byte    buffer[14];
1203
36.6k
  bfd_byte *    ptr;
1204
36.6k
  char *    symbol_name;
1205
36.6k
  char *    source_dll;
1206
36.6k
  char *    import_name;
1207
36.6k
  unsigned int    machine;
1208
36.6k
  bfd_size_type   size;
1209
36.6k
  unsigned int    ordinal;
1210
36.6k
  unsigned int    types;
1211
36.6k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
36.6k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
504
    return NULL;
1217
1218
36.1k
  ptr = buffer;
1219
1220
36.1k
  machine = H_GET_16 (abfd, ptr);
1221
36.1k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
36.1k
  magic = 0;
1225
1226
36.1k
  switch (machine)
1227
36.1k
    {
1228
75
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
111
    case IMAGE_FILE_MACHINE_ALPHA:
1230
147
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
201
    case IMAGE_FILE_MACHINE_IA64:
1232
201
      break;
1233
1234
2.85k
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
354
      magic = I386MAGIC;
1237
#endif
1238
2.85k
      break;
1239
1240
2.23k
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
283
      magic = AMD64MAGIC;
1243
#endif
1244
2.23k
      break;
1245
1246
39
    case IMAGE_FILE_MACHINE_R3000:
1247
93
    case IMAGE_FILE_MACHINE_R4000:
1248
147
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
201
    case IMAGE_FILE_MACHINE_MIPS16:
1251
255
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
309
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
309
      break;
1257
1258
12.4k
    case IMAGE_FILE_MACHINE_SH3:
1259
13.9k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
1.61k
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
13.9k
      break;
1264
1265
1.24k
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
322
      magic = ARMPEMAGIC;
1268
#endif
1269
1.24k
      break;
1270
1271
2.37k
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
297
      magic = AARCH64MAGIC;
1274
#endif
1275
2.37k
      break;
1276
1277
2.33k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
296
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
2.33k
      break;
1282
1283
2.52k
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
317
      magic = RISCV64MAGIC;
1286
#endif
1287
2.52k
      break;
1288
1289
1.50k
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
338
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
332
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
1.50k
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
6.61k
    default:
1303
6.61k
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
6.61k
  (_("%pB: unrecognised machine type (0x%x)"
1306
6.61k
     " in Import Library Format archive"),
1307
6.61k
   abfd, machine);
1308
6.61k
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
6.61k
      return NULL;
1311
0
      break;
1312
36.1k
    }
1313
1314
29.5k
  if (magic == 0)
1315
25.6k
    {
1316
25.6k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
25.6k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
25.6k
     " in Import Library Format archive"),
1320
25.6k
   abfd, machine);
1321
25.6k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
25.6k
      return NULL;
1324
25.6k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
3.81k
  ptr += 4;
1329
1330
3.81k
  size = H_GET_32 (abfd, ptr);
1331
3.81k
  ptr += 4;
1332
1333
3.81k
  if (size == 0)
1334
56
    {
1335
56
      _bfd_error_handler
1336
56
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
56
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
56
      return NULL;
1340
56
    }
1341
1342
3.75k
  ordinal = H_GET_16 (abfd, ptr);
1343
3.75k
  ptr += 2;
1344
1345
3.75k
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
3.75k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
3.75k
  if (ptr == NULL)
1351
1.55k
    return NULL;
1352
1353
2.20k
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
2.20k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
2.20k
  if (ptr[size - 1] != 0
1359
1.17k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
1.08k
    {
1361
1.08k
      _bfd_error_handler
1362
1.08k
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
1.08k
      bfd_set_error (bfd_error_malformed_archive);
1364
1.08k
      bfd_release (abfd, ptr);
1365
1.08k
      return NULL;
1366
1.08k
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
1.12k
  import_name = source_dll + strlen (source_dll) + 1;
1375
1.12k
  if ((bfd_byte *) import_name >= ptr + size)
1376
390
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
390
      import_name = NULL;
1380
390
    }
1381
1382
  /* Now construct the bfd.  */
1383
1.12k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
1.12k
          source_dll, ordinal, types,
1385
1.12k
          import_name))
1386
321
    {
1387
321
      bfd_release (abfd, ptr);
1388
321
      return NULL;
1389
321
    }
1390
1391
804
  return pe_ILF_cleanup;
1392
1.12k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1201
4.06k
{
1202
4.06k
  bfd_byte    buffer[14];
1203
4.06k
  bfd_byte *    ptr;
1204
4.06k
  char *    symbol_name;
1205
4.06k
  char *    source_dll;
1206
4.06k
  char *    import_name;
1207
4.06k
  unsigned int    machine;
1208
4.06k
  bfd_size_type   size;
1209
4.06k
  unsigned int    ordinal;
1210
4.06k
  unsigned int    types;
1211
4.06k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.06k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
4.01k
  ptr = buffer;
1219
1220
4.01k
  machine = H_GET_16 (abfd, ptr);
1221
4.01k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.01k
  magic = 0;
1225
1226
4.01k
  switch (machine)
1227
4.01k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
354
    case IMAGE_FILE_MACHINE_I386:
1235
354
#ifdef I386MAGIC
1236
354
      magic = I386MAGIC;
1237
354
#endif
1238
354
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
126
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
126
      break;
1270
1271
260
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
260
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
276
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
276
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
4.01k
    }
1313
1314
3.28k
  if (magic == 0)
1315
2.93k
    {
1316
2.93k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.93k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.93k
     " in Import Library Format archive"),
1320
2.93k
   abfd, machine);
1321
2.93k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.93k
      return NULL;
1324
2.93k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
354
  ptr += 4;
1329
1330
354
  size = H_GET_32 (abfd, ptr);
1331
354
  ptr += 4;
1332
1333
354
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
347
  ordinal = H_GET_16 (abfd, ptr);
1343
347
  ptr += 2;
1344
1345
347
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
347
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
347
  if (ptr == NULL)
1351
201
    return NULL;
1352
1353
146
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
146
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
146
  if (ptr[size - 1] != 0
1359
140
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
12
    {
1361
12
      _bfd_error_handler
1362
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
12
      bfd_set_error (bfd_error_malformed_archive);
1364
12
      bfd_release (abfd, ptr);
1365
12
      return NULL;
1366
12
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
134
  import_name = source_dll + strlen (source_dll) + 1;
1375
134
  if ((bfd_byte *) import_name >= ptr + size)
1376
41
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
41
      import_name = NULL;
1380
41
    }
1381
1382
  /* Now construct the bfd.  */
1383
134
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
134
          source_dll, ordinal, types,
1385
134
          import_name))
1386
31
    {
1387
31
      bfd_release (abfd, ptr);
1388
31
      return NULL;
1389
31
    }
1390
1391
103
  return pe_ILF_cleanup;
1392
134
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1201
4.02k
{
1202
4.02k
  bfd_byte    buffer[14];
1203
4.02k
  bfd_byte *    ptr;
1204
4.02k
  char *    symbol_name;
1205
4.02k
  char *    source_dll;
1206
4.02k
  char *    import_name;
1207
4.02k
  unsigned int    machine;
1208
4.02k
  bfd_size_type   size;
1209
4.02k
  unsigned int    ordinal;
1210
4.02k
  unsigned int    types;
1211
4.02k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.02k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
3.97k
  ptr = buffer;
1219
1220
3.97k
  machine = H_GET_16 (abfd, ptr);
1221
3.97k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.97k
  magic = 0;
1225
1226
3.97k
  switch (machine)
1227
3.97k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
312
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
312
      break;
1239
1240
283
    case IMAGE_FILE_MACHINE_AMD64:
1241
283
#ifdef AMD64MAGIC
1242
283
      magic = AMD64MAGIC;
1243
283
#endif
1244
283
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.35k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.51k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.51k
      break;
1264
1265
126
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
126
      break;
1270
1271
260
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
260
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
275
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
275
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
3.97k
    }
1313
1314
3.24k
  if (magic == 0)
1315
2.96k
    {
1316
2.96k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.96k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.96k
     " in Import Library Format archive"),
1320
2.96k
   abfd, machine);
1321
2.96k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.96k
      return NULL;
1324
2.96k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
283
  ptr += 4;
1329
1330
283
  size = H_GET_32 (abfd, ptr);
1331
283
  ptr += 4;
1332
1333
283
  if (size == 0)
1334
6
    {
1335
6
      _bfd_error_handler
1336
6
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
6
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
6
      return NULL;
1340
6
    }
1341
1342
277
  ordinal = H_GET_16 (abfd, ptr);
1343
277
  ptr += 2;
1344
1345
277
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
277
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
277
  if (ptr == NULL)
1351
139
    return NULL;
1352
1353
138
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
138
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
138
  if (ptr[size - 1] != 0
1359
132
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
12
    {
1361
12
      _bfd_error_handler
1362
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
12
      bfd_set_error (bfd_error_malformed_archive);
1364
12
      bfd_release (abfd, ptr);
1365
12
      return NULL;
1366
12
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
126
  import_name = source_dll + strlen (source_dll) + 1;
1375
126
  if ((bfd_byte *) import_name >= ptr + size)
1376
51
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
51
      import_name = NULL;
1380
51
    }
1381
1382
  /* Now construct the bfd.  */
1383
126
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
126
          source_dll, ordinal, types,
1385
126
          import_name))
1386
31
    {
1387
31
      bfd_release (abfd, ptr);
1388
31
      return NULL;
1389
31
    }
1390
1391
95
  return pe_ILF_cleanup;
1392
126
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1201
4.06k
{
1202
4.06k
  bfd_byte    buffer[14];
1203
4.06k
  bfd_byte *    ptr;
1204
4.06k
  char *    symbol_name;
1205
4.06k
  char *    source_dll;
1206
4.06k
  char *    import_name;
1207
4.06k
  unsigned int    machine;
1208
4.06k
  bfd_size_type   size;
1209
4.06k
  unsigned int    ordinal;
1210
4.06k
  unsigned int    types;
1211
4.06k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.06k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
4.00k
  ptr = buffer;
1219
1220
4.00k
  machine = H_GET_16 (abfd, ptr);
1221
4.00k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.00k
  magic = 0;
1225
1226
4.00k
  switch (machine)
1227
4.00k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
313
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
313
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
128
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
128
      break;
1270
1271
297
    case IMAGE_FILE_MACHINE_ARM64:
1272
297
#ifdef AARCH64MAGIC
1273
297
      magic = AARCH64MAGIC;
1274
297
#endif
1275
297
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
276
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
276
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
4.00k
    }
1313
1314
3.28k
  if (magic == 0)
1315
2.98k
    {
1316
2.98k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.98k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.98k
     " in Import Library Format archive"),
1320
2.98k
   abfd, machine);
1321
2.98k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.98k
      return NULL;
1324
2.98k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
297
  ptr += 4;
1329
1330
297
  size = H_GET_32 (abfd, ptr);
1331
297
  ptr += 4;
1332
1333
297
  if (size == 0)
1334
6
    {
1335
6
      _bfd_error_handler
1336
6
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
6
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
6
      return NULL;
1340
6
    }
1341
1342
291
  ordinal = H_GET_16 (abfd, ptr);
1343
291
  ptr += 2;
1344
1345
291
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
291
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
291
  if (ptr == NULL)
1351
157
    return NULL;
1352
1353
134
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
134
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
134
  if (ptr[size - 1] != 0
1359
128
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
12
    {
1361
12
      _bfd_error_handler
1362
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
12
      bfd_set_error (bfd_error_malformed_archive);
1364
12
      bfd_release (abfd, ptr);
1365
12
      return NULL;
1366
12
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
122
  import_name = source_dll + strlen (source_dll) + 1;
1375
122
  if ((bfd_byte *) import_name >= ptr + size)
1376
47
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
47
      import_name = NULL;
1380
47
    }
1381
1382
  /* Now construct the bfd.  */
1383
122
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
122
          source_dll, ordinal, types,
1385
122
          import_name))
1386
31
    {
1387
31
      bfd_release (abfd, ptr);
1388
31
      return NULL;
1389
31
    }
1390
1391
91
  return pe_ILF_cleanup;
1392
122
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1201
4.02k
{
1202
4.02k
  bfd_byte    buffer[14];
1203
4.02k
  bfd_byte *    ptr;
1204
4.02k
  char *    symbol_name;
1205
4.02k
  char *    source_dll;
1206
4.02k
  char *    import_name;
1207
4.02k
  unsigned int    machine;
1208
4.02k
  bfd_size_type   size;
1209
4.02k
  unsigned int    ordinal;
1210
4.02k
  unsigned int    types;
1211
4.02k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.02k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
3.97k
  ptr = buffer;
1219
1220
3.97k
  machine = H_GET_16 (abfd, ptr);
1221
3.97k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.97k
  magic = 0;
1225
1226
3.97k
  switch (machine)
1227
3.97k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
312
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
312
      break;
1239
1240
243
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
243
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.35k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.51k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.51k
      break;
1264
1265
126
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
126
      break;
1270
1271
260
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
260
      break;
1276
1277
296
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
296
#ifdef LOONGARCH64MAGIC
1279
296
      magic = LOONGARCH64MAGIC;
1280
296
#endif
1281
296
      break;
1282
1283
275
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
275
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
3.97k
    }
1313
1314
3.24k
  if (magic == 0)
1315
2.94k
    {
1316
2.94k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.94k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.94k
     " in Import Library Format archive"),
1320
2.94k
   abfd, machine);
1321
2.94k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.94k
      return NULL;
1324
2.94k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
296
  ptr += 4;
1329
1330
296
  size = H_GET_32 (abfd, ptr);
1331
296
  ptr += 4;
1332
1333
296
  if (size == 0)
1334
6
    {
1335
6
      _bfd_error_handler
1336
6
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
6
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
6
      return NULL;
1340
6
    }
1341
1342
290
  ordinal = H_GET_16 (abfd, ptr);
1343
290
  ptr += 2;
1344
1345
290
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
290
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
290
  if (ptr == NULL)
1351
145
    return NULL;
1352
1353
145
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
145
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
145
  if (ptr[size - 1] != 0
1359
139
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
12
    {
1361
12
      _bfd_error_handler
1362
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
12
      bfd_set_error (bfd_error_malformed_archive);
1364
12
      bfd_release (abfd, ptr);
1365
12
      return NULL;
1366
12
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
133
  import_name = source_dll + strlen (source_dll) + 1;
1375
133
  if ((bfd_byte *) import_name >= ptr + size)
1376
47
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
47
      import_name = NULL;
1380
47
    }
1381
1382
  /* Now construct the bfd.  */
1383
133
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
133
          source_dll, ordinal, types,
1385
133
          import_name))
1386
31
    {
1387
31
      bfd_release (abfd, ptr);
1388
31
      return NULL;
1389
31
    }
1390
1391
102
  return pe_ILF_cleanup;
1392
133
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1201
4.06k
{
1202
4.06k
  bfd_byte    buffer[14];
1203
4.06k
  bfd_byte *    ptr;
1204
4.06k
  char *    symbol_name;
1205
4.06k
  char *    source_dll;
1206
4.06k
  char *    import_name;
1207
4.06k
  unsigned int    machine;
1208
4.06k
  bfd_size_type   size;
1209
4.06k
  unsigned int    ordinal;
1210
4.06k
  unsigned int    types;
1211
4.06k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.06k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
4.01k
  ptr = buffer;
1219
1220
4.01k
  machine = H_GET_16 (abfd, ptr);
1221
4.01k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.01k
  magic = 0;
1225
1226
4.01k
  switch (machine)
1227
4.01k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
312
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
312
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
126
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
126
      break;
1270
1271
260
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
260
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
317
    case IMAGE_FILE_MACHINE_RISCV64:
1284
317
#ifdef RISCV64MAGIC
1285
317
      magic = RISCV64MAGIC;
1286
317
#endif
1287
317
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
4.01k
    }
1313
1314
3.28k
  if (magic == 0)
1315
2.96k
    {
1316
2.96k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.96k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.96k
     " in Import Library Format archive"),
1320
2.96k
   abfd, machine);
1321
2.96k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.96k
      return NULL;
1324
2.96k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
317
  ptr += 4;
1329
1330
317
  size = H_GET_32 (abfd, ptr);
1331
317
  ptr += 4;
1332
1333
317
  if (size == 0)
1334
6
    {
1335
6
      _bfd_error_handler
1336
6
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
6
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
6
      return NULL;
1340
6
    }
1341
1342
311
  ordinal = H_GET_16 (abfd, ptr);
1343
311
  ptr += 2;
1344
1345
311
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
311
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
311
  if (ptr == NULL)
1351
168
    return NULL;
1352
1353
143
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
143
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
143
  if (ptr[size - 1] != 0
1359
137
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
12
    {
1361
12
      _bfd_error_handler
1362
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
12
      bfd_set_error (bfd_error_malformed_archive);
1364
12
      bfd_release (abfd, ptr);
1365
12
      return NULL;
1366
12
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
131
  import_name = source_dll + strlen (source_dll) + 1;
1375
131
  if ((bfd_byte *) import_name >= ptr + size)
1376
39
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
39
      import_name = NULL;
1380
39
    }
1381
1382
  /* Now construct the bfd.  */
1383
131
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
131
          source_dll, ordinal, types,
1385
131
          import_name))
1386
30
    {
1387
30
      bfd_release (abfd, ptr);
1388
30
      return NULL;
1389
30
    }
1390
1391
101
  return pe_ILF_cleanup;
1392
131
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1201
4.09k
{
1202
4.09k
  bfd_byte    buffer[14];
1203
4.09k
  bfd_byte *    ptr;
1204
4.09k
  char *    symbol_name;
1205
4.09k
  char *    source_dll;
1206
4.09k
  char *    import_name;
1207
4.09k
  unsigned int    machine;
1208
4.09k
  bfd_size_type   size;
1209
4.09k
  unsigned int    ordinal;
1210
4.09k
  unsigned int    types;
1211
4.09k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.09k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
4.03k
  ptr = buffer;
1219
1220
4.03k
  machine = H_GET_16 (abfd, ptr);
1221
4.03k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.03k
  magic = 0;
1225
1226
4.03k
  switch (machine)
1227
4.03k
    {
1228
11
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
15
    case IMAGE_FILE_MACHINE_ALPHA:
1230
19
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
25
    case IMAGE_FILE_MACHINE_IA64:
1232
25
      break;
1233
1234
313
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
313
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
17
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
23
    case IMAGE_FILE_MACHINE_MIPS16:
1251
29
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
35
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
35
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
160
    case IMAGE_FILE_MACHINE_ARM:
1266
160
#ifdef ARMPEMAGIC
1267
160
      magic = ARMPEMAGIC;
1268
160
#endif
1269
160
      break;
1270
1271
259
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
259
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
276
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
276
      break;
1288
1289
169
    case IMAGE_FILE_MACHINE_THUMB:
1290
169
#ifdef THUMBPEMAGIC
1291
169
      {
1292
169
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
169
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
166
    magic = THUMBPEMAGIC;
1296
169
      }
1297
169
#endif
1298
169
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
753
    default:
1303
753
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
753
  (_("%pB: unrecognised machine type (0x%x)"
1306
753
     " in Import Library Format archive"),
1307
753
   abfd, machine);
1308
753
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
753
      return NULL;
1311
0
      break;
1312
4.03k
    }
1313
1314
3.28k
  if (magic == 0)
1315
2.95k
    {
1316
2.95k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.95k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.95k
     " in Import Library Format archive"),
1320
2.95k
   abfd, machine);
1321
2.95k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.95k
      return NULL;
1324
2.95k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
326
  ptr += 4;
1329
1330
326
  size = H_GET_32 (abfd, ptr);
1331
326
  ptr += 4;
1332
1333
326
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
319
  ordinal = H_GET_16 (abfd, ptr);
1343
319
  ptr += 2;
1344
1345
319
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
319
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
319
  if (ptr == NULL)
1351
193
    return NULL;
1352
1353
126
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
126
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
126
  if (ptr[size - 1] != 0
1359
112
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
20
    {
1361
20
      _bfd_error_handler
1362
20
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
20
      bfd_set_error (bfd_error_malformed_archive);
1364
20
      bfd_release (abfd, ptr);
1365
20
      return NULL;
1366
20
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
106
  import_name = source_dll + strlen (source_dll) + 1;
1375
106
  if ((bfd_byte *) import_name >= ptr + size)
1376
54
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
54
      import_name = NULL;
1380
54
    }
1381
1382
  /* Now construct the bfd.  */
1383
106
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
106
          source_dll, ordinal, types,
1385
106
          import_name))
1386
33
    {
1387
33
      bfd_release (abfd, ptr);
1388
33
      return NULL;
1389
33
    }
1390
1391
73
  return pe_ILF_cleanup;
1392
106
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1201
4.10k
{
1202
4.10k
  bfd_byte    buffer[14];
1203
4.10k
  bfd_byte *    ptr;
1204
4.10k
  char *    symbol_name;
1205
4.10k
  char *    source_dll;
1206
4.10k
  char *    import_name;
1207
4.10k
  unsigned int    machine;
1208
4.10k
  bfd_size_type   size;
1209
4.10k
  unsigned int    ordinal;
1210
4.10k
  unsigned int    types;
1211
4.10k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.10k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
4.04k
  ptr = buffer;
1219
1220
4.04k
  machine = H_GET_16 (abfd, ptr);
1221
4.04k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.04k
  magic = 0;
1225
1226
4.04k
  switch (machine)
1227
4.04k
    {
1228
11
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
15
    case IMAGE_FILE_MACHINE_ALPHA:
1230
19
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
25
    case IMAGE_FILE_MACHINE_IA64:
1232
25
      break;
1233
1234
313
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
313
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
17
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
23
    case IMAGE_FILE_MACHINE_MIPS16:
1251
29
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
35
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
35
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
162
    case IMAGE_FILE_MACHINE_ARM:
1266
162
#ifdef ARMPEMAGIC
1267
162
      magic = ARMPEMAGIC;
1268
162
#endif
1269
162
      break;
1270
1271
259
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
259
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
276
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
276
      break;
1288
1289
169
    case IMAGE_FILE_MACHINE_THUMB:
1290
169
#ifdef THUMBPEMAGIC
1291
169
      {
1292
169
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
169
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
166
    magic = THUMBPEMAGIC;
1296
169
      }
1297
169
#endif
1298
169
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
753
    default:
1303
753
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
753
  (_("%pB: unrecognised machine type (0x%x)"
1306
753
     " in Import Library Format archive"),
1307
753
   abfd, machine);
1308
753
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
753
      return NULL;
1311
0
      break;
1312
4.04k
    }
1313
1314
3.28k
  if (magic == 0)
1315
2.95k
    {
1316
2.95k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.95k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.95k
     " in Import Library Format archive"),
1320
2.95k
   abfd, machine);
1321
2.95k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.95k
      return NULL;
1324
2.95k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
328
  ptr += 4;
1329
1330
328
  size = H_GET_32 (abfd, ptr);
1331
328
  ptr += 4;
1332
1333
328
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
321
  ordinal = H_GET_16 (abfd, ptr);
1343
321
  ptr += 2;
1344
1345
321
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
321
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
321
  if (ptr == NULL)
1351
193
    return NULL;
1352
1353
128
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
128
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
128
  if (ptr[size - 1] != 0
1359
114
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
20
    {
1361
20
      _bfd_error_handler
1362
20
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
20
      bfd_set_error (bfd_error_malformed_archive);
1364
20
      bfd_release (abfd, ptr);
1365
20
      return NULL;
1366
20
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
108
  import_name = source_dll + strlen (source_dll) + 1;
1375
108
  if ((bfd_byte *) import_name >= ptr + size)
1376
54
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
54
      import_name = NULL;
1380
54
    }
1381
1382
  /* Now construct the bfd.  */
1383
108
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
108
          source_dll, ordinal, types,
1385
108
          import_name))
1386
33
    {
1387
33
      bfd_release (abfd, ptr);
1388
33
      return NULL;
1389
33
    }
1390
1391
75
  return pe_ILF_cleanup;
1392
108
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1201
4.09k
{
1202
4.09k
  bfd_byte    buffer[14];
1203
4.09k
  bfd_byte *    ptr;
1204
4.09k
  char *    symbol_name;
1205
4.09k
  char *    source_dll;
1206
4.09k
  char *    import_name;
1207
4.09k
  unsigned int    machine;
1208
4.09k
  bfd_size_type   size;
1209
4.09k
  unsigned int    ordinal;
1210
4.09k
  unsigned int    types;
1211
4.09k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.09k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
4.03k
  ptr = buffer;
1219
1220
4.03k
  machine = H_GET_16 (abfd, ptr);
1221
4.03k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.03k
  magic = 0;
1225
1226
4.03k
  switch (machine)
1227
4.03k
    {
1228
11
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
15
    case IMAGE_FILE_MACHINE_ALPHA:
1230
19
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
25
    case IMAGE_FILE_MACHINE_IA64:
1232
25
      break;
1233
1234
312
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
312
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
17
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
23
    case IMAGE_FILE_MACHINE_MIPS16:
1251
29
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
35
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
35
      break;
1257
1258
1.38k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.54k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.54k
      break;
1264
1265
160
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
160
      break;
1270
1271
259
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
259
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
276
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
276
      break;
1288
1289
169
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
169
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
753
    default:
1303
753
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
753
  (_("%pB: unrecognised machine type (0x%x)"
1306
753
     " in Import Library Format archive"),
1307
753
   abfd, machine);
1308
753
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
753
      return NULL;
1311
0
      break;
1312
4.03k
    }
1313
1314
3.28k
  if (magic == 0)
1315
3.28k
    {
1316
3.28k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
3.28k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
3.28k
     " in Import Library Format archive"),
1320
3.28k
   abfd, machine);
1321
3.28k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
3.28k
      return NULL;
1324
3.28k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
0
  ptr += 4;
1329
1330
0
  size = H_GET_32 (abfd, ptr);
1331
0
  ptr += 4;
1332
1333
0
  if (size == 0)
1334
0
    {
1335
0
      _bfd_error_handler
1336
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
0
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
0
      return NULL;
1340
0
    }
1341
1342
0
  ordinal = H_GET_16 (abfd, ptr);
1343
0
  ptr += 2;
1344
1345
0
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
0
  if (ptr == NULL)
1351
0
    return NULL;
1352
1353
0
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
0
  if (ptr[size - 1] != 0
1359
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
0
    {
1361
0
      _bfd_error_handler
1362
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
0
      bfd_set_error (bfd_error_malformed_archive);
1364
0
      bfd_release (abfd, ptr);
1365
0
      return NULL;
1366
0
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
0
  import_name = source_dll + strlen (source_dll) + 1;
1375
0
  if ((bfd_byte *) import_name >= ptr + size)
1376
0
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
0
      import_name = NULL;
1380
0
    }
1381
1382
  /* Now construct the bfd.  */
1383
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
0
          source_dll, ordinal, types,
1385
0
          import_name))
1386
0
    {
1387
0
      bfd_release (abfd, ptr);
1388
0
      return NULL;
1389
0
    }
1390
1391
0
  return pe_ILF_cleanup;
1392
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1201
4.08k
{
1202
4.08k
  bfd_byte    buffer[14];
1203
4.08k
  bfd_byte *    ptr;
1204
4.08k
  char *    symbol_name;
1205
4.08k
  char *    source_dll;
1206
4.08k
  char *    import_name;
1207
4.08k
  unsigned int    machine;
1208
4.08k
  bfd_size_type   size;
1209
4.08k
  unsigned int    ordinal;
1210
4.08k
  unsigned int    types;
1211
4.08k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.08k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
54
    return NULL;
1217
1218
4.03k
  ptr = buffer;
1219
1220
4.03k
  machine = H_GET_16 (abfd, ptr);
1221
4.03k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
4.03k
  magic = 0;
1225
1226
4.03k
  switch (machine)
1227
4.03k
    {
1228
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
11
    case IMAGE_FILE_MACHINE_ALPHA:
1230
15
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
21
    case IMAGE_FILE_MACHINE_IA64:
1232
21
      break;
1233
1234
312
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
312
      break;
1239
1240
244
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
244
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
16
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
22
    case IMAGE_FILE_MACHINE_MIPS16:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
34
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
34
      break;
1257
1258
1.42k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.61k
    case IMAGE_FILE_MACHINE_SH4:
1260
1.61k
#ifdef SH_ARCH_MAGIC_WINCE
1261
1.61k
      magic = SH_ARCH_MAGIC_WINCE;
1262
1.61k
#endif
1263
1.61k
      break;
1264
1265
126
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
126
      break;
1270
1271
259
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
259
      break;
1276
1277
255
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
255
      break;
1282
1283
275
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
275
      break;
1288
1289
166
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
166
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
726
    default:
1303
726
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
726
  (_("%pB: unrecognised machine type (0x%x)"
1306
726
     " in Import Library Format archive"),
1307
726
   abfd, machine);
1308
726
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
726
      return NULL;
1311
0
      break;
1312
4.03k
    }
1313
1314
3.30k
  if (magic == 0)
1315
1.69k
    {
1316
1.69k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
1.69k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
1.69k
     " in Import Library Format archive"),
1320
1.69k
   abfd, machine);
1321
1.69k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
1.69k
      return NULL;
1324
1.69k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
1.61k
  ptr += 4;
1329
1330
1.61k
  size = H_GET_32 (abfd, ptr);
1331
1.61k
  ptr += 4;
1332
1333
1.61k
  if (size == 0)
1334
11
    {
1335
11
      _bfd_error_handler
1336
11
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
11
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
11
      return NULL;
1340
11
    }
1341
1342
1.60k
  ordinal = H_GET_16 (abfd, ptr);
1343
1.60k
  ptr += 2;
1344
1345
1.60k
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
1.60k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
1.60k
  if (ptr == NULL)
1351
357
    return NULL;
1352
1353
1.24k
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
1.24k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
1.24k
  if (ptr[size - 1] != 0
1359
277
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
981
    {
1361
981
      _bfd_error_handler
1362
981
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
981
      bfd_set_error (bfd_error_malformed_archive);
1364
981
      bfd_release (abfd, ptr);
1365
981
      return NULL;
1366
981
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
265
  import_name = source_dll + strlen (source_dll) + 1;
1375
265
  if ((bfd_byte *) import_name >= ptr + size)
1376
57
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
57
      import_name = NULL;
1380
57
    }
1381
1382
  /* Now construct the bfd.  */
1383
265
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
265
          source_dll, ordinal, types,
1385
265
          import_name))
1386
101
    {
1387
101
      bfd_release (abfd, ptr);
1388
101
      return NULL;
1389
101
    }
1390
1391
164
  return pe_ILF_cleanup;
1392
265
}
1393
1394
static void
1395
pe_bfd_read_buildid (bfd *abfd)
1396
47.3k
{
1397
47.3k
  pe_data_type *pe = pe_data (abfd);
1398
47.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
47.3k
  asection *section;
1400
47.3k
  bfd_byte *data = 0;
1401
47.3k
  bfd_size_type dataoff;
1402
47.3k
  unsigned int i;
1403
47.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
47.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
47.3k
  if (size == 0)
1407
27.4k
    return;
1408
1409
19.9k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
143k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
133k
    {
1414
133k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
10.2k
  break;
1416
133k
    }
1417
1418
19.9k
  if (section == NULL)
1419
9.66k
    return;
1420
1421
10.2k
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
398
    return;
1423
1424
9.88k
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
9.88k
  if (dataoff >= section->size
1430
9.88k
      || size > section->size - dataoff)
1431
3.59k
    {
1432
3.59k
      _bfd_error_handler
1433
3.59k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
3.59k
   abfd);
1435
3.59k
      return;
1436
3.59k
    }
1437
1438
  /* Read the whole section. */
1439
6.29k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
1.85k
    {
1441
1.85k
      free (data);
1442
1.85k
      return;
1443
1.85k
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
311k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
308k
    {
1448
308k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
308k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
308k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
308k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
308k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
1.77k
  {
1456
1.77k
    char buffer[256 + 1];
1457
1.77k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
1.77k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
1.77k
                (file_ptr) idd.PointerToRawData,
1465
1.77k
                idd.SizeOfData, cvinfo, NULL))
1466
117
      {
1467
117
        struct bfd_build_id *build_id;
1468
117
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
117
        build_id = bfd_alloc (abfd, bidlen);
1471
117
        if (build_id)
1472
117
    {
1473
117
      build_id->size = cvinfo->SignatureLength;
1474
117
      memcpy(build_id->data, cvinfo->Signature,
1475
117
       cvinfo->SignatureLength);
1476
117
      abfd->build_id = build_id;
1477
117
    }
1478
117
      }
1479
1.77k
    break;
1480
1.77k
  }
1481
308k
    }
1482
1483
4.44k
  free (data);
1484
4.44k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1396
8.54k
{
1397
8.54k
  pe_data_type *pe = pe_data (abfd);
1398
8.54k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
8.54k
  asection *section;
1400
8.54k
  bfd_byte *data = 0;
1401
8.54k
  bfd_size_type dataoff;
1402
8.54k
  unsigned int i;
1403
8.54k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
8.54k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
8.54k
  if (size == 0)
1407
6.71k
    return;
1408
1409
1.83k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
14.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
13.4k
    {
1414
13.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
964
  break;
1416
13.4k
    }
1417
1418
1.83k
  if (section == NULL)
1419
872
    return;
1420
1421
964
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
54
    return;
1423
1424
910
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
910
  if (dataoff >= section->size
1430
910
      || size > section->size - dataoff)
1431
404
    {
1432
404
      _bfd_error_handler
1433
404
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
404
   abfd);
1435
404
      return;
1436
404
    }
1437
1438
  /* Read the whole section. */
1439
506
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
229
    {
1441
229
      free (data);
1442
229
      return;
1443
229
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
8.45k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
8.32k
    {
1448
8.32k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
8.32k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
8.32k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
8.32k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
8.32k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
150
  {
1456
150
    char buffer[256 + 1];
1457
150
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
150
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
150
                (file_ptr) idd.PointerToRawData,
1465
150
                idd.SizeOfData, cvinfo, NULL))
1466
15
      {
1467
15
        struct bfd_build_id *build_id;
1468
15
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
15
        build_id = bfd_alloc (abfd, bidlen);
1471
15
        if (build_id)
1472
15
    {
1473
15
      build_id->size = cvinfo->SignatureLength;
1474
15
      memcpy(build_id->data, cvinfo->Signature,
1475
15
       cvinfo->SignatureLength);
1476
15
      abfd->build_id = build_id;
1477
15
    }
1478
15
      }
1479
150
    break;
1480
150
  }
1481
8.32k
    }
1482
1483
277
  free (data);
1484
277
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1396
6.42k
{
1397
6.42k
  pe_data_type *pe = pe_data (abfd);
1398
6.42k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
6.42k
  asection *section;
1400
6.42k
  bfd_byte *data = 0;
1401
6.42k
  bfd_size_type dataoff;
1402
6.42k
  unsigned int i;
1403
6.42k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
6.42k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
6.42k
  if (size == 0)
1407
3.84k
    return;
1408
1409
2.57k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
24.7k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
23.2k
    {
1414
23.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
1.13k
  break;
1416
23.2k
    }
1417
1418
2.57k
  if (section == NULL)
1419
1.43k
    return;
1420
1421
1.13k
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
47
    return;
1423
1424
1.09k
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
1.09k
  if (dataoff >= section->size
1430
1.09k
      || size > section->size - dataoff)
1431
503
    {
1432
503
      _bfd_error_handler
1433
503
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
503
   abfd);
1435
503
      return;
1436
503
    }
1437
1438
  /* Read the whole section. */
1439
587
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
251
    {
1441
251
      free (data);
1442
251
      return;
1443
251
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
9.28k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
9.16k
    {
1448
9.16k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
9.16k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
9.16k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
9.16k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
9.16k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
217
  {
1456
217
    char buffer[256 + 1];
1457
217
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
217
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
217
                (file_ptr) idd.PointerToRawData,
1465
217
                idd.SizeOfData, cvinfo, NULL))
1466
37
      {
1467
37
        struct bfd_build_id *build_id;
1468
37
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
37
        build_id = bfd_alloc (abfd, bidlen);
1471
37
        if (build_id)
1472
37
    {
1473
37
      build_id->size = cvinfo->SignatureLength;
1474
37
      memcpy(build_id->data, cvinfo->Signature,
1475
37
       cvinfo->SignatureLength);
1476
37
      abfd->build_id = build_id;
1477
37
    }
1478
37
      }
1479
217
    break;
1480
217
  }
1481
9.16k
    }
1482
1483
336
  free (data);
1484
336
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1396
6.65k
{
1397
6.65k
  pe_data_type *pe = pe_data (abfd);
1398
6.65k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
6.65k
  asection *section;
1400
6.65k
  bfd_byte *data = 0;
1401
6.65k
  bfd_size_type dataoff;
1402
6.65k
  unsigned int i;
1403
6.65k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
6.65k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
6.65k
  if (size == 0)
1407
2.36k
    return;
1408
1409
4.28k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
25.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
24.1k
    {
1414
24.1k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
3.00k
  break;
1416
24.1k
    }
1417
1418
4.28k
  if (section == NULL)
1419
1.27k
    return;
1420
1421
3.00k
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
17
    return;
1423
1424
2.98k
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
2.98k
  if (dataoff >= section->size
1430
2.98k
      || size > section->size - dataoff)
1431
430
    {
1432
430
      _bfd_error_handler
1433
430
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
430
   abfd);
1435
430
      return;
1436
430
    }
1437
1438
  /* Read the whole section. */
1439
2.55k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
364
    {
1441
364
      free (data);
1442
364
      return;
1443
364
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
259k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
258k
    {
1448
258k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
258k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
258k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
258k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
258k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
514
  {
1456
514
    char buffer[256 + 1];
1457
514
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
514
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
514
                (file_ptr) idd.PointerToRawData,
1465
514
                idd.SizeOfData, cvinfo, NULL))
1466
15
      {
1467
15
        struct bfd_build_id *build_id;
1468
15
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
15
        build_id = bfd_alloc (abfd, bidlen);
1471
15
        if (build_id)
1472
15
    {
1473
15
      build_id->size = cvinfo->SignatureLength;
1474
15
      memcpy(build_id->data, cvinfo->Signature,
1475
15
       cvinfo->SignatureLength);
1476
15
      abfd->build_id = build_id;
1477
15
    }
1478
15
      }
1479
514
    break;
1480
514
  }
1481
258k
    }
1482
1483
2.19k
  free (data);
1484
2.19k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1396
4.74k
{
1397
4.74k
  pe_data_type *pe = pe_data (abfd);
1398
4.74k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
4.74k
  asection *section;
1400
4.74k
  bfd_byte *data = 0;
1401
4.74k
  bfd_size_type dataoff;
1402
4.74k
  unsigned int i;
1403
4.74k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
4.74k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
4.74k
  if (size == 0)
1407
3.03k
    return;
1408
1409
1.70k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
9.69k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
8.59k
    {
1414
8.59k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
605
  break;
1416
8.59k
    }
1417
1418
1.70k
  if (section == NULL)
1419
1.10k
    return;
1420
1421
605
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
19
    return;
1423
1424
586
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
586
  if (dataoff >= section->size
1430
586
      || size > section->size - dataoff)
1431
260
    {
1432
260
      _bfd_error_handler
1433
260
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
260
   abfd);
1435
260
      return;
1436
260
    }
1437
1438
  /* Read the whole section. */
1439
326
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
91
    {
1441
91
      free (data);
1442
91
      return;
1443
91
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
5.91k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
5.84k
    {
1448
5.84k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
5.84k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
5.84k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
5.84k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
5.84k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
163
  {
1456
163
    char buffer[256 + 1];
1457
163
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
163
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
163
                (file_ptr) idd.PointerToRawData,
1465
163
                idd.SizeOfData, cvinfo, NULL))
1466
4
      {
1467
4
        struct bfd_build_id *build_id;
1468
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
4
        build_id = bfd_alloc (abfd, bidlen);
1471
4
        if (build_id)
1472
4
    {
1473
4
      build_id->size = cvinfo->SignatureLength;
1474
4
      memcpy(build_id->data, cvinfo->Signature,
1475
4
       cvinfo->SignatureLength);
1476
4
      abfd->build_id = build_id;
1477
4
    }
1478
4
      }
1479
163
    break;
1480
163
  }
1481
5.84k
    }
1482
1483
235
  free (data);
1484
235
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1396
4.43k
{
1397
4.43k
  pe_data_type *pe = pe_data (abfd);
1398
4.43k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
4.43k
  asection *section;
1400
4.43k
  bfd_byte *data = 0;
1401
4.43k
  bfd_size_type dataoff;
1402
4.43k
  unsigned int i;
1403
4.43k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
4.43k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
4.43k
  if (size == 0)
1407
2.42k
    return;
1408
1409
2.00k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
12.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
11.5k
    {
1414
11.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
919
  break;
1416
11.5k
    }
1417
1418
2.00k
  if (section == NULL)
1419
1.08k
    return;
1420
1421
919
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
35
    return;
1423
1424
884
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
884
  if (dataoff >= section->size
1430
884
      || size > section->size - dataoff)
1431
389
    {
1432
389
      _bfd_error_handler
1433
389
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
389
   abfd);
1435
389
      return;
1436
389
    }
1437
1438
  /* Read the whole section. */
1439
495
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
157
    {
1441
157
      free (data);
1442
157
      return;
1443
157
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
7.61k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
7.48k
    {
1448
7.48k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
7.48k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
7.48k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
7.48k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
7.48k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
210
  {
1456
210
    char buffer[256 + 1];
1457
210
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
210
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
210
                (file_ptr) idd.PointerToRawData,
1465
210
                idd.SizeOfData, cvinfo, NULL))
1466
9
      {
1467
9
        struct bfd_build_id *build_id;
1468
9
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
9
        build_id = bfd_alloc (abfd, bidlen);
1471
9
        if (build_id)
1472
9
    {
1473
9
      build_id->size = cvinfo->SignatureLength;
1474
9
      memcpy(build_id->data, cvinfo->Signature,
1475
9
       cvinfo->SignatureLength);
1476
9
      abfd->build_id = build_id;
1477
9
    }
1478
9
      }
1479
210
    break;
1480
210
  }
1481
7.48k
    }
1482
1483
338
  free (data);
1484
338
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.67k
{
1397
3.67k
  pe_data_type *pe = pe_data (abfd);
1398
3.67k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.67k
  asection *section;
1400
3.67k
  bfd_byte *data = 0;
1401
3.67k
  bfd_size_type dataoff;
1402
3.67k
  unsigned int i;
1403
3.67k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.67k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.67k
  if (size == 0)
1407
2.35k
    return;
1408
1409
1.32k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
17.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
16.4k
    {
1414
16.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
547
  break;
1416
16.4k
    }
1417
1418
1.32k
  if (section == NULL)
1419
777
    return;
1420
1421
547
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
31
    return;
1423
1424
516
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
516
  if (dataoff >= section->size
1430
516
      || size > section->size - dataoff)
1431
177
    {
1432
177
      _bfd_error_handler
1433
177
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
177
   abfd);
1435
177
      return;
1436
177
    }
1437
1438
  /* Read the whole section. */
1439
339
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
83
    {
1441
83
      free (data);
1442
83
      return;
1443
83
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
2.94k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
2.88k
    {
1448
2.88k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
2.88k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
2.88k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
2.88k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
2.88k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
189
  {
1456
189
    char buffer[256 + 1];
1457
189
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
189
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
189
                (file_ptr) idd.PointerToRawData,
1465
189
                idd.SizeOfData, cvinfo, NULL))
1466
6
      {
1467
6
        struct bfd_build_id *build_id;
1468
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
6
        build_id = bfd_alloc (abfd, bidlen);
1471
6
        if (build_id)
1472
6
    {
1473
6
      build_id->size = cvinfo->SignatureLength;
1474
6
      memcpy(build_id->data, cvinfo->Signature,
1475
6
       cvinfo->SignatureLength);
1476
6
      abfd->build_id = build_id;
1477
6
    }
1478
6
      }
1479
189
    break;
1480
189
  }
1481
2.88k
    }
1482
1483
256
  free (data);
1484
256
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1396
2.42k
{
1397
2.42k
  pe_data_type *pe = pe_data (abfd);
1398
2.42k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
2.42k
  asection *section;
1400
2.42k
  bfd_byte *data = 0;
1401
2.42k
  bfd_size_type dataoff;
1402
2.42k
  unsigned int i;
1403
2.42k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
2.42k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
2.42k
  if (size == 0)
1407
932
    return;
1408
1409
1.48k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
6.66k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
5.89k
    {
1414
5.89k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
723
  break;
1416
5.89k
    }
1417
1418
1.48k
  if (section == NULL)
1419
765
    return;
1420
1421
723
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
54
    return;
1423
1424
669
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
669
  if (dataoff >= section->size
1430
669
      || size > section->size - dataoff)
1431
384
    {
1432
384
      _bfd_error_handler
1433
384
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
384
   abfd);
1435
384
      return;
1436
384
    }
1437
1438
  /* Read the whole section. */
1439
285
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
153
    {
1441
153
      free (data);
1442
153
      return;
1443
153
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
2.20k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
2.13k
    {
1448
2.13k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
2.13k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
2.13k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
2.13k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
2.13k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
62
  {
1456
62
    char buffer[256 + 1];
1457
62
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
62
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
62
                (file_ptr) idd.PointerToRawData,
1465
62
                idd.SizeOfData, cvinfo, NULL))
1466
6
      {
1467
6
        struct bfd_build_id *build_id;
1468
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
6
        build_id = bfd_alloc (abfd, bidlen);
1471
6
        if (build_id)
1472
6
    {
1473
6
      build_id->size = cvinfo->SignatureLength;
1474
6
      memcpy(build_id->data, cvinfo->Signature,
1475
6
       cvinfo->SignatureLength);
1476
6
      abfd->build_id = build_id;
1477
6
    }
1478
6
      }
1479
62
    break;
1480
62
  }
1481
2.13k
    }
1482
1483
132
  free (data);
1484
132
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.47k
{
1397
3.47k
  pe_data_type *pe = pe_data (abfd);
1398
3.47k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.47k
  asection *section;
1400
3.47k
  bfd_byte *data = 0;
1401
3.47k
  bfd_size_type dataoff;
1402
3.47k
  unsigned int i;
1403
3.47k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.47k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.47k
  if (size == 0)
1407
1.72k
    return;
1408
1409
1.74k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
10.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
9.43k
    {
1414
9.43k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
893
  break;
1416
9.43k
    }
1417
1418
1.74k
  if (section == NULL)
1419
854
    return;
1420
1421
893
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
40
    return;
1423
1424
853
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
853
  if (dataoff >= section->size
1430
853
      || size > section->size - dataoff)
1431
406
    {
1432
406
      _bfd_error_handler
1433
406
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
406
   abfd);
1435
406
      return;
1436
406
    }
1437
1438
  /* Read the whole section. */
1439
447
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
191
    {
1441
191
      free (data);
1442
191
      return;
1443
191
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
3.95k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
3.77k
    {
1448
3.77k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
3.77k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
3.77k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
3.77k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
3.77k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
83
  {
1456
83
    char buffer[256 + 1];
1457
83
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
83
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
83
                (file_ptr) idd.PointerToRawData,
1465
83
                idd.SizeOfData, cvinfo, NULL))
1466
19
      {
1467
19
        struct bfd_build_id *build_id;
1468
19
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
19
        build_id = bfd_alloc (abfd, bidlen);
1471
19
        if (build_id)
1472
19
    {
1473
19
      build_id->size = cvinfo->SignatureLength;
1474
19
      memcpy(build_id->data, cvinfo->Signature,
1475
19
       cvinfo->SignatureLength);
1476
19
      abfd->build_id = build_id;
1477
19
    }
1478
19
      }
1479
83
    break;
1480
83
  }
1481
3.77k
    }
1482
1483
256
  free (data);
1484
256
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.27k
{
1397
3.27k
  pe_data_type *pe = pe_data (abfd);
1398
3.27k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.27k
  asection *section;
1400
3.27k
  bfd_byte *data = 0;
1401
3.27k
  bfd_size_type dataoff;
1402
3.27k
  unsigned int i;
1403
3.27k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.27k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.27k
  if (size == 0)
1407
1.90k
    return;
1408
1409
1.36k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
12.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
11.5k
    {
1414
11.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
646
  break;
1416
11.5k
    }
1417
1418
1.36k
  if (section == NULL)
1419
718
    return;
1420
1421
646
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
46
    return;
1423
1424
600
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
600
  if (dataoff >= section->size
1430
600
      || size > section->size - dataoff)
1431
288
    {
1432
288
      _bfd_error_handler
1433
288
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
288
   abfd);
1435
288
      return;
1436
288
    }
1437
1438
  /* Read the whole section. */
1439
312
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
138
    {
1441
138
      free (data);
1442
138
      return;
1443
138
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
5.38k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
5.28k
    {
1448
5.28k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
5.28k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
5.28k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
5.28k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
5.28k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
80
  {
1456
80
    char buffer[256 + 1];
1457
80
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
80
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
80
                (file_ptr) idd.PointerToRawData,
1465
80
                idd.SizeOfData, cvinfo, NULL))
1466
3
      {
1467
3
        struct bfd_build_id *build_id;
1468
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
3
        build_id = bfd_alloc (abfd, bidlen);
1471
3
        if (build_id)
1472
3
    {
1473
3
      build_id->size = cvinfo->SignatureLength;
1474
3
      memcpy(build_id->data, cvinfo->Signature,
1475
3
       cvinfo->SignatureLength);
1476
3
      abfd->build_id = build_id;
1477
3
    }
1478
3
      }
1479
80
    break;
1480
80
  }
1481
5.28k
    }
1482
1483
174
  free (data);
1484
174
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.71k
{
1397
3.71k
  pe_data_type *pe = pe_data (abfd);
1398
3.71k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.71k
  asection *section;
1400
3.71k
  bfd_byte *data = 0;
1401
3.71k
  bfd_size_type dataoff;
1402
3.71k
  unsigned int i;
1403
3.71k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.71k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.71k
  if (size == 0)
1407
2.08k
    return;
1408
1409
1.62k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
10.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
9.63k
    {
1414
9.63k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
846
  break;
1416
9.63k
    }
1417
1418
1.62k
  if (section == NULL)
1419
776
    return;
1420
1421
846
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
55
    return;
1423
1424
791
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
791
  if (dataoff >= section->size
1430
791
      || size > section->size - dataoff)
1431
357
    {
1432
357
      _bfd_error_handler
1433
357
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
357
   abfd);
1435
357
      return;
1436
357
    }
1437
1438
  /* Read the whole section. */
1439
434
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
193
    {
1441
193
      free (data);
1442
193
      return;
1443
193
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
5.60k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
5.47k
    {
1448
5.47k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
5.47k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
5.47k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
5.47k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
5.47k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
111
  {
1456
111
    char buffer[256 + 1];
1457
111
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
111
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
111
                (file_ptr) idd.PointerToRawData,
1465
111
                idd.SizeOfData, cvinfo, NULL))
1466
3
      {
1467
3
        struct bfd_build_id *build_id;
1468
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
3
        build_id = bfd_alloc (abfd, bidlen);
1471
3
        if (build_id)
1472
3
    {
1473
3
      build_id->size = cvinfo->SignatureLength;
1474
3
      memcpy(build_id->data, cvinfo->Signature,
1475
3
       cvinfo->SignatureLength);
1476
3
      abfd->build_id = build_id;
1477
3
    }
1478
3
      }
1479
111
    break;
1480
111
  }
1481
5.47k
    }
1482
1483
241
  free (data);
1484
241
}
1485
1486
static bfd_cleanup
1487
pe_bfd_object_p (bfd *abfd)
1488
2.40M
{
1489
2.40M
  bfd_byte buffer[6];
1490
2.40M
  struct external_DOS_hdr dos_hdr;
1491
2.40M
  struct external_PEI_IMAGE_hdr image_hdr;
1492
2.40M
  struct internal_filehdr internal_f;
1493
2.40M
  struct internal_aouthdr internal_a;
1494
2.40M
  bfd_size_type opt_hdr_size;
1495
2.40M
  file_ptr offset;
1496
2.40M
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
2.40M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
2.40M
      || bfd_read (buffer, 6, abfd) != 6)
1502
22.4k
    {
1503
22.4k
      if (bfd_get_error () != bfd_error_system_call)
1504
20.4k
  bfd_set_error (bfd_error_wrong_format);
1505
22.4k
      return NULL;
1506
22.4k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
2.38M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
43.2k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
36.6k
    return pe_ILF_object_p (abfd);
1512
1513
2.34M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
2.34M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
519k
    {
1516
519k
      if (bfd_get_error () != bfd_error_system_call)
1517
519k
  bfd_set_error (bfd_error_wrong_format);
1518
519k
      return NULL;
1519
519k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
1.82M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
1.32M
    {
1533
1.32M
      bfd_set_error (bfd_error_wrong_format);
1534
1.32M
      return NULL;
1535
1.32M
    }
1536
1537
499k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
499k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
499k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
3.34k
    {
1541
3.34k
      if (bfd_get_error () != bfd_error_system_call)
1542
3.34k
  bfd_set_error (bfd_error_wrong_format);
1543
3.34k
      return NULL;
1544
3.34k
    }
1545
1546
496k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
5.43k
    {
1548
5.43k
      bfd_set_error (bfd_error_wrong_format);
1549
5.43k
      return NULL;
1550
5.43k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
491k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
491k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
73.7k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
417k
    {
1559
417k
      bfd_set_error (bfd_error_wrong_format);
1560
417k
      return NULL;
1561
417k
    }
1562
1563
73.5k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
73.5k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
73.5k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
73.5k
  if (opt_hdr_size != 0)
1570
44.2k
    {
1571
44.2k
      bfd_size_type amt = opt_hdr_size;
1572
44.2k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
44.2k
      if (amt < sizeof (PEAOUTHDR))
1576
40.7k
  amt = sizeof (PEAOUTHDR);
1577
1578
44.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
44.2k
      if (opthdr == NULL)
1580
364
  return NULL;
1581
43.9k
      if (amt > opt_hdr_size)
1582
40.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
43.9k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
43.9k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
4.90k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
5.15k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
1.62k
#endif
1596
4.40k
  {
1597
4.40k
    bfd_set_error (bfd_error_wrong_format);
1598
4.40k
    return NULL;
1599
4.40k
  }
1600
5.66k
#endif
1601
1602
39.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
18.3k
    || a->SectionAlignment >= 0x80000000)
1604
21.5k
  {
1605
21.5k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
21.5k
            abfd);
1607
21.5k
    a->SectionAlignment &= -a->SectionAlignment;
1608
21.5k
    if (a->SectionAlignment >= 0x80000000)
1609
348
      a->SectionAlignment = 0x40000000;
1610
21.5k
  }
1611
1612
39.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
19.3k
    || a->FileAlignment > a->SectionAlignment)
1614
26.5k
  {
1615
26.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
26.5k
            abfd);
1617
26.5k
    a->FileAlignment &= -a->FileAlignment;
1618
26.5k
    if (a->FileAlignment > a->SectionAlignment)
1619
18.4k
      a->FileAlignment = a->SectionAlignment;
1620
26.5k
  }
1621
1622
39.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
21.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
5.66k
    }
1625
1626
68.7k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
68.7k
             (opt_hdr_size != 0
1628
68.7k
        ? &internal_a
1629
68.7k
        : (struct internal_aouthdr *) NULL));
1630
1631
68.7k
  if (result)
1632
47.3k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
47.3k
      pe_bfd_read_buildid(abfd);
1635
47.3k
    }
1636
1637
68.7k
  return result;
1638
73.5k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1488
213k
{
1489
213k
  bfd_byte buffer[6];
1490
213k
  struct external_DOS_hdr dos_hdr;
1491
213k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
213k
  struct internal_filehdr internal_f;
1493
213k
  struct internal_aouthdr internal_a;
1494
213k
  bfd_size_type opt_hdr_size;
1495
213k
  file_ptr offset;
1496
213k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
213k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
213k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.87k
    {
1503
1.87k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.70k
  bfd_set_error (bfd_error_wrong_format);
1505
1.87k
      return NULL;
1506
1.87k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
211k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.82k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.06k
    return pe_ILF_object_p (abfd);
1512
1513
207k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
207k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
44.5k
    {
1516
44.5k
      if (bfd_get_error () != bfd_error_system_call)
1517
44.5k
  bfd_set_error (bfd_error_wrong_format);
1518
44.5k
      return NULL;
1519
44.5k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
162k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
106k
    {
1533
106k
      bfd_set_error (bfd_error_wrong_format);
1534
106k
      return NULL;
1535
106k
    }
1536
1537
55.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
55.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
55.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
166
    {
1541
166
      if (bfd_get_error () != bfd_error_system_call)
1542
166
  bfd_set_error (bfd_error_wrong_format);
1543
166
      return NULL;
1544
166
    }
1545
1546
55.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
365
    {
1548
365
      bfd_set_error (bfd_error_wrong_format);
1549
365
      return NULL;
1550
365
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
55.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
55.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
9.94k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
45.3k
    {
1559
45.3k
      bfd_set_error (bfd_error_wrong_format);
1560
45.3k
      return NULL;
1561
45.3k
    }
1562
1563
9.92k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
9.92k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
9.92k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
9.92k
  if (opt_hdr_size != 0)
1570
4.88k
    {
1571
4.88k
      bfd_size_type amt = opt_hdr_size;
1572
4.88k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.88k
      if (amt < sizeof (PEAOUTHDR))
1576
4.14k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.88k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.88k
      if (opthdr == NULL)
1580
36
  return NULL;
1581
4.84k
      if (amt > opt_hdr_size)
1582
4.10k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.84k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.84k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.84k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.66k
    || a->SectionAlignment >= 0x80000000)
1604
2.25k
  {
1605
2.25k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
2.25k
            abfd);
1607
2.25k
    a->SectionAlignment &= -a->SectionAlignment;
1608
2.25k
    if (a->SectionAlignment >= 0x80000000)
1609
71
      a->SectionAlignment = 0x40000000;
1610
2.25k
  }
1611
1612
4.84k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
2.68k
    || a->FileAlignment > a->SectionAlignment)
1614
2.63k
  {
1615
2.63k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.63k
            abfd);
1617
2.63k
    a->FileAlignment &= -a->FileAlignment;
1618
2.63k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.69k
      a->FileAlignment = a->SectionAlignment;
1620
2.63k
  }
1621
1622
4.84k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.33k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.84k
    }
1625
1626
9.88k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
9.88k
             (opt_hdr_size != 0
1628
9.88k
        ? &internal_a
1629
9.88k
        : (struct internal_aouthdr *) NULL));
1630
1631
9.88k
  if (result)
1632
8.54k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
8.54k
      pe_bfd_read_buildid(abfd);
1635
8.54k
    }
1636
1637
9.88k
  return result;
1638
9.92k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1488
212k
{
1489
212k
  bfd_byte buffer[6];
1490
212k
  struct external_DOS_hdr dos_hdr;
1491
212k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
212k
  struct internal_filehdr internal_f;
1493
212k
  struct internal_aouthdr internal_a;
1494
212k
  bfd_size_type opt_hdr_size;
1495
212k
  file_ptr offset;
1496
212k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
212k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
212k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.87k
    {
1503
1.87k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.70k
  bfd_set_error (bfd_error_wrong_format);
1505
1.87k
      return NULL;
1506
1.87k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
210k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.78k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.02k
    return pe_ILF_object_p (abfd);
1512
1513
206k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
206k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
44.5k
    {
1516
44.5k
      if (bfd_get_error () != bfd_error_system_call)
1517
44.5k
  bfd_set_error (bfd_error_wrong_format);
1518
44.5k
      return NULL;
1519
44.5k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
161k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
106k
    {
1533
106k
      bfd_set_error (bfd_error_wrong_format);
1534
106k
      return NULL;
1535
106k
    }
1536
1537
54.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
54.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
54.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
166
    {
1541
166
      if (bfd_get_error () != bfd_error_system_call)
1542
166
  bfd_set_error (bfd_error_wrong_format);
1543
166
      return NULL;
1544
166
    }
1545
1546
54.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
365
    {
1548
365
      bfd_set_error (bfd_error_wrong_format);
1549
365
      return NULL;
1550
365
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
54.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
54.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.04k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
46.2k
    {
1559
46.2k
      bfd_set_error (bfd_error_wrong_format);
1560
46.2k
      return NULL;
1561
46.2k
    }
1562
1563
8.01k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.01k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.01k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.01k
  if (opt_hdr_size != 0)
1570
5.02k
    {
1571
5.02k
      bfd_size_type amt = opt_hdr_size;
1572
5.02k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
5.02k
      if (amt < sizeof (PEAOUTHDR))
1576
4.62k
  amt = sizeof (PEAOUTHDR);
1577
1578
5.02k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
5.02k
      if (opthdr == NULL)
1580
40
  return NULL;
1581
4.98k
      if (amt > opt_hdr_size)
1582
4.58k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.98k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.98k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.98k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.72k
    || a->SectionAlignment >= 0x80000000)
1604
2.30k
  {
1605
2.30k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
2.30k
            abfd);
1607
2.30k
    a->SectionAlignment &= -a->SectionAlignment;
1608
2.30k
    if (a->SectionAlignment >= 0x80000000)
1609
50
      a->SectionAlignment = 0x40000000;
1610
2.30k
  }
1611
1612
4.98k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
2.16k
    || a->FileAlignment > a->SectionAlignment)
1614
3.28k
  {
1615
3.28k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
3.28k
            abfd);
1617
3.28k
    a->FileAlignment &= -a->FileAlignment;
1618
3.28k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.77k
      a->FileAlignment = a->SectionAlignment;
1620
3.28k
  }
1621
1622
4.98k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.81k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.98k
    }
1625
1626
7.97k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
7.97k
             (opt_hdr_size != 0
1628
7.97k
        ? &internal_a
1629
7.97k
        : (struct internal_aouthdr *) NULL));
1630
1631
7.97k
  if (result)
1632
6.42k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
6.42k
      pe_bfd_read_buildid(abfd);
1635
6.42k
    }
1636
1637
7.97k
  return result;
1638
8.01k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1488
210k
{
1489
210k
  bfd_byte buffer[6];
1490
210k
  struct external_DOS_hdr dos_hdr;
1491
210k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
210k
  struct internal_filehdr internal_f;
1493
210k
  struct internal_aouthdr internal_a;
1494
210k
  bfd_size_type opt_hdr_size;
1495
210k
  file_ptr offset;
1496
210k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
210k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
210k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.87k
    {
1503
1.87k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.70k
  bfd_set_error (bfd_error_wrong_format);
1505
1.87k
      return NULL;
1506
1.87k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
208k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.82k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.06k
    return pe_ILF_object_p (abfd);
1512
1513
204k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
204k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
44.4k
    {
1516
44.4k
      if (bfd_get_error () != bfd_error_system_call)
1517
44.4k
  bfd_set_error (bfd_error_wrong_format);
1518
44.4k
      return NULL;
1519
44.4k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
159k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
104k
    {
1533
104k
      bfd_set_error (bfd_error_wrong_format);
1534
104k
      return NULL;
1535
104k
    }
1536
1537
54.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
54.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
54.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
800
    {
1541
800
      if (bfd_get_error () != bfd_error_system_call)
1542
800
  bfd_set_error (bfd_error_wrong_format);
1543
800
      return NULL;
1544
800
    }
1545
1546
53.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.12k
    {
1548
1.12k
      bfd_set_error (bfd_error_wrong_format);
1549
1.12k
      return NULL;
1550
1.12k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
52.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
52.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.73k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
44.1k
    {
1559
44.1k
      bfd_set_error (bfd_error_wrong_format);
1560
44.1k
      return NULL;
1561
44.1k
    }
1562
1563
8.72k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.72k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.72k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.72k
  if (opt_hdr_size != 0)
1570
6.43k
    {
1571
6.43k
      bfd_size_type amt = opt_hdr_size;
1572
6.43k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
6.43k
      if (amt < sizeof (PEAOUTHDR))
1576
6.22k
  amt = sizeof (PEAOUTHDR);
1577
1578
6.43k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
6.43k
      if (opthdr == NULL)
1580
23
  return NULL;
1581
6.41k
      if (amt > opt_hdr_size)
1582
6.20k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
6.41k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
6.41k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
6.41k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.03k
    || a->SectionAlignment >= 0x80000000)
1604
4.40k
  {
1605
4.40k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
4.40k
            abfd);
1607
4.40k
    a->SectionAlignment &= -a->SectionAlignment;
1608
4.40k
    if (a->SectionAlignment >= 0x80000000)
1609
25
      a->SectionAlignment = 0x40000000;
1610
4.40k
  }
1611
1612
6.41k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
4.32k
    || a->FileAlignment > a->SectionAlignment)
1614
5.04k
  {
1615
5.04k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
5.04k
            abfd);
1617
5.04k
    a->FileAlignment &= -a->FileAlignment;
1618
5.04k
    if (a->FileAlignment > a->SectionAlignment)
1619
4.02k
      a->FileAlignment = a->SectionAlignment;
1620
5.04k
  }
1621
1622
6.41k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.73k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
6.41k
    }
1625
1626
8.70k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
8.70k
             (opt_hdr_size != 0
1628
8.70k
        ? &internal_a
1629
8.70k
        : (struct internal_aouthdr *) NULL));
1630
1631
8.70k
  if (result)
1632
6.65k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
6.65k
      pe_bfd_read_buildid(abfd);
1635
6.65k
    }
1636
1637
8.70k
  return result;
1638
8.72k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1488
16.9k
{
1489
16.9k
  bfd_byte buffer[6];
1490
16.9k
  struct external_DOS_hdr dos_hdr;
1491
16.9k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
16.9k
  struct internal_filehdr internal_f;
1493
16.9k
  struct internal_aouthdr internal_a;
1494
16.9k
  bfd_size_type opt_hdr_size;
1495
16.9k
  file_ptr offset;
1496
16.9k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
16.9k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
16.9k
      || bfd_read (buffer, 6, abfd) != 6)
1502
0
    {
1503
0
      if (bfd_get_error () != bfd_error_system_call)
1504
0
  bfd_set_error (bfd_error_wrong_format);
1505
0
      return NULL;
1506
0
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
16.9k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
0
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
0
    return pe_ILF_object_p (abfd);
1512
1513
16.9k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
16.9k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
0
    {
1516
0
      if (bfd_get_error () != bfd_error_system_call)
1517
0
  bfd_set_error (bfd_error_wrong_format);
1518
0
      return NULL;
1519
0
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
16.9k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
0
    {
1533
0
      bfd_set_error (bfd_error_wrong_format);
1534
0
      return NULL;
1535
0
    }
1536
1537
16.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
16.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
16.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
0
    {
1541
0
      if (bfd_get_error () != bfd_error_system_call)
1542
0
  bfd_set_error (bfd_error_wrong_format);
1543
0
      return NULL;
1544
0
    }
1545
1546
16.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
0
    {
1548
0
      bfd_set_error (bfd_error_wrong_format);
1549
0
      return NULL;
1550
0
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
16.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
16.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
7.10k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
9.83k
    {
1559
9.83k
      bfd_set_error (bfd_error_wrong_format);
1560
9.83k
      return NULL;
1561
9.83k
    }
1562
1563
7.09k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
7.09k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
7.09k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
7.09k
  if (opt_hdr_size != 0)
1570
3.40k
    {
1571
3.40k
      bfd_size_type amt = opt_hdr_size;
1572
3.40k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
3.40k
      if (amt < sizeof (PEAOUTHDR))
1576
3.27k
  amt = sizeof (PEAOUTHDR);
1577
1578
3.40k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
3.40k
      if (opthdr == NULL)
1580
33
  return NULL;
1581
3.37k
      if (amt > opt_hdr_size)
1582
3.24k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
3.37k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
3.37k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
3.37k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.45k
    || a->SectionAlignment >= 0x80000000)
1604
1.94k
  {
1605
1.94k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.94k
            abfd);
1607
1.94k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.94k
    if (a->SectionAlignment >= 0x80000000)
1609
26
      a->SectionAlignment = 0x40000000;
1610
1.94k
  }
1611
1612
3.37k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.38k
    || a->FileAlignment > a->SectionAlignment)
1614
2.41k
  {
1615
2.41k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.41k
            abfd);
1617
2.41k
    a->FileAlignment &= -a->FileAlignment;
1618
2.41k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.19k
      a->FileAlignment = a->SectionAlignment;
1620
2.41k
  }
1621
1622
3.37k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.33k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.37k
    }
1625
1626
7.05k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
7.05k
             (opt_hdr_size != 0
1628
7.05k
        ? &internal_a
1629
7.05k
        : (struct internal_aouthdr *) NULL));
1630
1631
7.05k
  if (result)
1632
4.74k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
4.74k
      pe_bfd_read_buildid(abfd);
1635
4.74k
    }
1636
1637
7.05k
  return result;
1638
7.09k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1488
210k
{
1489
210k
  bfd_byte buffer[6];
1490
210k
  struct external_DOS_hdr dos_hdr;
1491
210k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
210k
  struct internal_filehdr internal_f;
1493
210k
  struct internal_aouthdr internal_a;
1494
210k
  bfd_size_type opt_hdr_size;
1495
210k
  file_ptr offset;
1496
210k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
210k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
210k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.87k
    {
1503
1.87k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.70k
  bfd_set_error (bfd_error_wrong_format);
1505
1.87k
      return NULL;
1506
1.87k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
208k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.78k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.02k
    return pe_ILF_object_p (abfd);
1512
1513
204k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
204k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
44.5k
    {
1516
44.5k
      if (bfd_get_error () != bfd_error_system_call)
1517
44.5k
  bfd_set_error (bfd_error_wrong_format);
1518
44.5k
      return NULL;
1519
44.5k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
159k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
106k
    {
1533
106k
      bfd_set_error (bfd_error_wrong_format);
1534
106k
      return NULL;
1535
106k
    }
1536
1537
53.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
53.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
53.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
166
    {
1541
166
      if (bfd_get_error () != bfd_error_system_call)
1542
166
  bfd_set_error (bfd_error_wrong_format);
1543
166
      return NULL;
1544
166
    }
1545
1546
52.8k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
365
    {
1548
365
      bfd_set_error (bfd_error_wrong_format);
1549
365
      return NULL;
1550
365
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
52.5k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
52.5k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
6.59k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
45.9k
    {
1559
45.9k
      bfd_set_error (bfd_error_wrong_format);
1560
45.9k
      return NULL;
1561
45.9k
    }
1562
1563
6.57k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
6.57k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
6.57k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
6.57k
  if (opt_hdr_size != 0)
1570
4.34k
    {
1571
4.34k
      bfd_size_type amt = opt_hdr_size;
1572
4.34k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.34k
      if (amt < sizeof (PEAOUTHDR))
1576
3.98k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.34k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.34k
      if (opthdr == NULL)
1580
32
  return NULL;
1581
4.31k
      if (amt > opt_hdr_size)
1582
3.96k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.31k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.31k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.31k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.41k
    || a->SectionAlignment >= 0x80000000)
1604
1.92k
  {
1605
1.92k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.92k
            abfd);
1607
1.92k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.92k
    if (a->SectionAlignment >= 0x80000000)
1609
25
      a->SectionAlignment = 0x40000000;
1610
1.92k
  }
1611
1612
4.31k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.87k
    || a->FileAlignment > a->SectionAlignment)
1614
2.84k
  {
1615
2.84k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.84k
            abfd);
1617
2.84k
    a->FileAlignment &= -a->FileAlignment;
1618
2.84k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.73k
      a->FileAlignment = a->SectionAlignment;
1620
2.84k
  }
1621
1622
4.31k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.57k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.31k
    }
1625
1626
6.54k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
6.54k
             (opt_hdr_size != 0
1628
6.54k
        ? &internal_a
1629
6.54k
        : (struct internal_aouthdr *) NULL));
1630
1631
6.54k
  if (result)
1632
4.43k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
4.43k
      pe_bfd_read_buildid(abfd);
1635
4.43k
    }
1636
1637
6.54k
  return result;
1638
6.57k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1488
210k
{
1489
210k
  bfd_byte buffer[6];
1490
210k
  struct external_DOS_hdr dos_hdr;
1491
210k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
210k
  struct internal_filehdr internal_f;
1493
210k
  struct internal_aouthdr internal_a;
1494
210k
  bfd_size_type opt_hdr_size;
1495
210k
  file_ptr offset;
1496
210k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
210k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
210k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.87k
    {
1503
1.87k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.70k
  bfd_set_error (bfd_error_wrong_format);
1505
1.87k
      return NULL;
1506
1.87k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
208k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.82k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.06k
    return pe_ILF_object_p (abfd);
1512
1513
204k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
204k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
44.5k
    {
1516
44.5k
      if (bfd_get_error () != bfd_error_system_call)
1517
44.5k
  bfd_set_error (bfd_error_wrong_format);
1518
44.5k
      return NULL;
1519
44.5k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
159k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
106k
    {
1533
106k
      bfd_set_error (bfd_error_wrong_format);
1534
106k
      return NULL;
1535
106k
    }
1536
1537
52.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
166
    {
1541
166
      if (bfd_get_error () != bfd_error_system_call)
1542
166
  bfd_set_error (bfd_error_wrong_format);
1543
166
      return NULL;
1544
166
    }
1545
1546
52.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
365
    {
1548
365
      bfd_set_error (bfd_error_wrong_format);
1549
365
      return NULL;
1550
365
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
52.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
52.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
5.95k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
46.3k
    {
1559
46.3k
      bfd_set_error (bfd_error_wrong_format);
1560
46.3k
      return NULL;
1561
46.3k
    }
1562
1563
5.93k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
5.93k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
5.93k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
5.93k
  if (opt_hdr_size != 0)
1570
3.95k
    {
1571
3.95k
      bfd_size_type amt = opt_hdr_size;
1572
3.95k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
3.95k
      if (amt < sizeof (PEAOUTHDR))
1576
3.59k
  amt = sizeof (PEAOUTHDR);
1577
1578
3.95k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
3.95k
      if (opthdr == NULL)
1580
31
  return NULL;
1581
3.91k
      if (amt > opt_hdr_size)
1582
3.56k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
3.91k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
3.91k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
3.91k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.15k
    || a->SectionAlignment >= 0x80000000)
1604
1.79k
  {
1605
1.79k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.79k
            abfd);
1607
1.79k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.79k
    if (a->SectionAlignment >= 0x80000000)
1609
23
      a->SectionAlignment = 0x40000000;
1610
1.79k
  }
1611
1612
3.91k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.74k
    || a->FileAlignment > a->SectionAlignment)
1614
2.48k
  {
1615
2.48k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.48k
            abfd);
1617
2.48k
    a->FileAlignment &= -a->FileAlignment;
1618
2.48k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.76k
      a->FileAlignment = a->SectionAlignment;
1620
2.48k
  }
1621
1622
3.91k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.05k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.91k
    }
1625
1626
5.90k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.90k
             (opt_hdr_size != 0
1628
5.90k
        ? &internal_a
1629
5.90k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.90k
  if (result)
1632
3.67k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.67k
      pe_bfd_read_buildid(abfd);
1635
3.67k
    }
1636
1637
5.90k
  return result;
1638
5.93k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1488
379k
{
1489
379k
  bfd_byte buffer[6];
1490
379k
  struct external_DOS_hdr dos_hdr;
1491
379k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
379k
  struct internal_filehdr internal_f;
1493
379k
  struct internal_aouthdr internal_a;
1494
379k
  bfd_size_type opt_hdr_size;
1495
379k
  file_ptr offset;
1496
379k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
379k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
379k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.74k
    {
1503
3.74k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.40k
  bfd_set_error (bfd_error_wrong_format);
1505
3.74k
      return NULL;
1506
3.74k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
375k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.81k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.09k
    return pe_ILF_object_p (abfd);
1512
1513
371k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
371k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
85.0k
    {
1516
85.0k
      if (bfd_get_error () != bfd_error_system_call)
1517
85.0k
  bfd_set_error (bfd_error_wrong_format);
1518
85.0k
      return NULL;
1519
85.0k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
286k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
233k
    {
1533
233k
      bfd_set_error (bfd_error_wrong_format);
1534
233k
      return NULL;
1535
233k
    }
1536
1537
53.4k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
53.4k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
53.4k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
775
    {
1541
775
      if (bfd_get_error () != bfd_error_system_call)
1542
775
  bfd_set_error (bfd_error_wrong_format);
1543
775
      return NULL;
1544
775
    }
1545
1546
52.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.06k
    {
1548
1.06k
      bfd_set_error (bfd_error_wrong_format);
1549
1.06k
      return NULL;
1550
1.06k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.31k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
43.3k
    {
1559
43.3k
      bfd_set_error (bfd_error_wrong_format);
1560
43.3k
      return NULL;
1561
43.3k
    }
1562
1563
8.26k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.26k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.26k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.26k
  if (opt_hdr_size != 0)
1570
4.96k
    {
1571
4.96k
      bfd_size_type amt = opt_hdr_size;
1572
4.96k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.96k
      if (amt < sizeof (PEAOUTHDR))
1576
4.53k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.96k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.96k
      if (opthdr == NULL)
1580
53
  return NULL;
1581
4.90k
      if (amt > opt_hdr_size)
1582
4.49k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.90k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.90k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
4.90k
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
4.90k
#ifdef WINCE
1592
4.90k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
2.77k
  {
1597
2.77k
    bfd_set_error (bfd_error_wrong_format);
1598
2.77k
    return NULL;
1599
2.77k
  }
1600
2.13k
#endif
1601
1602
2.13k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
495
    || a->SectionAlignment >= 0x80000000)
1604
1.66k
  {
1605
1.66k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.66k
            abfd);
1607
1.66k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.66k
    if (a->SectionAlignment >= 0x80000000)
1609
30
      a->SectionAlignment = 0x40000000;
1610
1.66k
  }
1611
1612
2.13k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
545
    || a->FileAlignment > a->SectionAlignment)
1614
1.91k
  {
1615
1.91k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.91k
            abfd);
1617
1.91k
    a->FileAlignment &= -a->FileAlignment;
1618
1.91k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.51k
      a->FileAlignment = a->SectionAlignment;
1620
1.91k
  }
1621
1622
2.13k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.63k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
2.13k
    }
1625
1626
5.43k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.43k
             (opt_hdr_size != 0
1628
5.43k
        ? &internal_a
1629
5.43k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.43k
  if (result)
1632
2.42k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
2.42k
      pe_bfd_read_buildid(abfd);
1635
2.42k
    }
1636
1637
5.43k
  return result;
1638
8.26k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1488
379k
{
1489
379k
  bfd_byte buffer[6];
1490
379k
  struct external_DOS_hdr dos_hdr;
1491
379k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
379k
  struct internal_filehdr internal_f;
1493
379k
  struct internal_aouthdr internal_a;
1494
379k
  bfd_size_type opt_hdr_size;
1495
379k
  file_ptr offset;
1496
379k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
379k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
379k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.74k
    {
1503
3.74k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.40k
  bfd_set_error (bfd_error_wrong_format);
1505
3.74k
      return NULL;
1506
3.74k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
376k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.81k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.10k
    return pe_ILF_object_p (abfd);
1512
1513
372k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
372k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
85.0k
    {
1516
85.0k
      if (bfd_get_error () != bfd_error_system_call)
1517
85.0k
  bfd_set_error (bfd_error_wrong_format);
1518
85.0k
      return NULL;
1519
85.0k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
287k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
233k
    {
1533
233k
      bfd_set_error (bfd_error_wrong_format);
1534
233k
      return NULL;
1535
233k
    }
1536
1537
53.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
53.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
53.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
775
    {
1541
775
      if (bfd_get_error () != bfd_error_system_call)
1542
775
  bfd_set_error (bfd_error_wrong_format);
1543
775
      return NULL;
1544
775
    }
1545
1546
52.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.06k
    {
1548
1.06k
      bfd_set_error (bfd_error_wrong_format);
1549
1.06k
      return NULL;
1550
1.06k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.56k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
43.3k
    {
1559
43.3k
      bfd_set_error (bfd_error_wrong_format);
1560
43.3k
      return NULL;
1561
43.3k
    }
1562
1563
8.51k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.51k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.51k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.51k
  if (opt_hdr_size != 0)
1570
5.20k
    {
1571
5.20k
      bfd_size_type amt = opt_hdr_size;
1572
5.20k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
5.20k
      if (amt < sizeof (PEAOUTHDR))
1576
4.77k
  amt = sizeof (PEAOUTHDR);
1577
1578
5.20k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
5.20k
      if (opthdr == NULL)
1580
53
  return NULL;
1581
5.15k
      if (amt > opt_hdr_size)
1582
4.72k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
5.15k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
5.15k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
5.15k
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
5.15k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
1.62k
#endif
1596
1.62k
  {
1597
1.62k
    bfd_set_error (bfd_error_wrong_format);
1598
1.62k
    return NULL;
1599
1.62k
  }
1600
3.52k
#endif
1601
1602
3.52k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.62k
    || a->SectionAlignment >= 0x80000000)
1604
1.94k
  {
1605
1.94k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.94k
            abfd);
1607
1.94k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.94k
    if (a->SectionAlignment >= 0x80000000)
1609
48
      a->SectionAlignment = 0x40000000;
1610
1.94k
  }
1611
1612
3.52k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.72k
    || a->FileAlignment > a->SectionAlignment)
1614
2.18k
  {
1615
2.18k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.18k
            abfd);
1617
2.18k
    a->FileAlignment &= -a->FileAlignment;
1618
2.18k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.66k
      a->FileAlignment = a->SectionAlignment;
1620
2.18k
  }
1621
1622
3.52k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.91k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.52k
    }
1625
1626
6.83k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
6.83k
             (opt_hdr_size != 0
1628
6.83k
        ? &internal_a
1629
6.83k
        : (struct internal_aouthdr *) NULL));
1630
1631
6.83k
  if (result)
1632
3.47k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.47k
      pe_bfd_read_buildid(abfd);
1635
3.47k
    }
1636
1637
6.83k
  return result;
1638
8.51k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1488
380k
{
1489
380k
  bfd_byte buffer[6];
1490
380k
  struct external_DOS_hdr dos_hdr;
1491
380k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
380k
  struct internal_filehdr internal_f;
1493
380k
  struct internal_aouthdr internal_a;
1494
380k
  bfd_size_type opt_hdr_size;
1495
380k
  file_ptr offset;
1496
380k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
380k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
380k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.74k
    {
1503
3.74k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.40k
  bfd_set_error (bfd_error_wrong_format);
1505
3.74k
      return NULL;
1506
3.74k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
376k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.81k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.09k
    return pe_ILF_object_p (abfd);
1512
1513
372k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
372k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
85.1k
    {
1516
85.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
85.1k
  bfd_set_error (bfd_error_wrong_format);
1518
85.1k
      return NULL;
1519
85.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
287k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
235k
    {
1533
235k
      bfd_set_error (bfd_error_wrong_format);
1534
235k
      return NULL;
1535
235k
    }
1536
1537
52.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
164
    {
1541
164
      if (bfd_get_error () != bfd_error_system_call)
1542
164
  bfd_set_error (bfd_error_wrong_format);
1543
164
      return NULL;
1544
164
    }
1545
1546
51.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
365
    {
1548
365
      bfd_set_error (bfd_error_wrong_format);
1549
365
      return NULL;
1550
365
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.5k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.5k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
5.05k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
46.5k
    {
1559
46.5k
      bfd_set_error (bfd_error_wrong_format);
1560
46.5k
      return NULL;
1561
46.5k
    }
1562
1563
5.04k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
5.04k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
5.04k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
5.04k
  if (opt_hdr_size != 0)
1570
2.91k
    {
1571
2.91k
      bfd_size_type amt = opt_hdr_size;
1572
2.91k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
2.91k
      if (amt < sizeof (PEAOUTHDR))
1576
2.72k
  amt = sizeof (PEAOUTHDR);
1577
1578
2.91k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
2.91k
      if (opthdr == NULL)
1580
24
  return NULL;
1581
2.88k
      if (amt > opt_hdr_size)
1582
2.70k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
2.88k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
2.88k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
2.88k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.32k
    || a->SectionAlignment >= 0x80000000)
1604
1.60k
  {
1605
1.60k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.60k
            abfd);
1607
1.60k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.60k
    if (a->SectionAlignment >= 0x80000000)
1609
35
      a->SectionAlignment = 0x40000000;
1610
1.60k
  }
1611
1612
2.88k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.31k
    || a->FileAlignment > a->SectionAlignment)
1614
1.81k
  {
1615
1.81k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.81k
            abfd);
1617
1.81k
    a->FileAlignment &= -a->FileAlignment;
1618
1.81k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.53k
      a->FileAlignment = a->SectionAlignment;
1620
1.81k
  }
1621
1622
2.88k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.60k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
2.88k
    }
1625
1626
5.01k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.01k
             (opt_hdr_size != 0
1628
5.01k
        ? &internal_a
1629
5.01k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.01k
  if (result)
1632
3.27k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.27k
      pe_bfd_read_buildid(abfd);
1635
3.27k
    }
1636
1637
5.01k
  return result;
1638
5.04k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1488
192k
{
1489
192k
  bfd_byte buffer[6];
1490
192k
  struct external_DOS_hdr dos_hdr;
1491
192k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
192k
  struct internal_filehdr internal_f;
1493
192k
  struct internal_aouthdr internal_a;
1494
192k
  bfd_size_type opt_hdr_size;
1495
192k
  file_ptr offset;
1496
192k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
192k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
192k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.86k
    {
1503
1.86k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.69k
  bfd_set_error (bfd_error_wrong_format);
1505
1.86k
      return NULL;
1506
1.86k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
190k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.79k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.08k
    return pe_ILF_object_p (abfd);
1512
1513
186k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
186k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
41.2k
    {
1516
41.2k
      if (bfd_get_error () != bfd_error_system_call)
1517
41.2k
  bfd_set_error (bfd_error_wrong_format);
1518
41.2k
      return NULL;
1519
41.2k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
144k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
92.6k
    {
1533
92.6k
      bfd_set_error (bfd_error_wrong_format);
1534
92.6k
      return NULL;
1535
92.6k
    }
1536
1537
52.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
164
    {
1541
164
      if (bfd_get_error () != bfd_error_system_call)
1542
164
  bfd_set_error (bfd_error_wrong_format);
1543
164
      return NULL;
1544
164
    }
1545
1546
52.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
363
    {
1548
363
      bfd_set_error (bfd_error_wrong_format);
1549
363
      return NULL;
1550
363
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
5.45k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
46.3k
    {
1559
46.3k
      bfd_set_error (bfd_error_wrong_format);
1560
46.3k
      return NULL;
1561
46.3k
    }
1562
1563
5.43k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
5.43k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
5.43k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
5.43k
  if (opt_hdr_size != 0)
1570
3.14k
    {
1571
3.14k
      bfd_size_type amt = opt_hdr_size;
1572
3.14k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
3.14k
      if (amt < sizeof (PEAOUTHDR))
1576
2.91k
  amt = sizeof (PEAOUTHDR);
1577
1578
3.14k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
3.14k
      if (opthdr == NULL)
1580
39
  return NULL;
1581
3.10k
      if (amt > opt_hdr_size)
1582
2.88k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
3.10k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
3.10k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
3.10k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.44k
    || a->SectionAlignment >= 0x80000000)
1604
1.67k
  {
1605
1.67k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.67k
            abfd);
1607
1.67k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.67k
    if (a->SectionAlignment >= 0x80000000)
1609
15
      a->SectionAlignment = 0x40000000;
1610
1.67k
  }
1611
1612
3.10k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.59k
    || a->FileAlignment > a->SectionAlignment)
1614
1.94k
  {
1615
1.94k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.94k
            abfd);
1617
1.94k
    a->FileAlignment &= -a->FileAlignment;
1618
1.94k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.50k
      a->FileAlignment = a->SectionAlignment;
1620
1.94k
  }
1621
1622
3.10k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.84k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.10k
    }
1625
1626
5.39k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.39k
             (opt_hdr_size != 0
1628
5.39k
        ? &internal_a
1629
5.39k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.39k
  if (result)
1632
3.71k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.71k
      pe_bfd_read_buildid(abfd);
1635
3.71k
    }
1636
1637
5.39k
  return result;
1638
5.43k
}
1639
1640
16.9k
#define coff_object_p pe_bfd_object_p
1641
#endif /* COFF_IMAGE_WITH_PE */