Coverage Report

Created: 2026-04-04 08:16

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
44.7k
{
137
44.7k
  RELOC *reloc_src = (RELOC *) src;
138
44.7k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
44.7k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
44.7k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
44.7k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
20.2k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
44.7k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
3.39k
{
137
3.39k
  RELOC *reloc_src = (RELOC *) src;
138
3.39k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.39k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.39k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.39k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.39k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
1.71k
{
137
1.71k
  RELOC *reloc_src = (RELOC *) src;
138
1.71k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.71k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.71k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.71k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
1.71k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.56k
{
137
3.56k
  RELOC *reloc_src = (RELOC *) src;
138
3.56k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.56k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.56k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.56k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.56k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
1.80k
{
137
1.80k
  RELOC *reloc_src = (RELOC *) src;
138
1.80k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.80k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.80k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.80k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
1.80k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.73k
{
137
3.73k
  RELOC *reloc_src = (RELOC *) src;
138
3.73k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.73k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.73k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.73k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.73k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
2.17k
{
137
2.17k
  RELOC *reloc_src = (RELOC *) src;
138
2.17k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.17k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.17k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.17k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.17k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
2.00k
{
137
2.00k
  RELOC *reloc_src = (RELOC *) src;
138
2.00k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.00k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.00k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.00k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.00k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.00k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.00k
#endif
146
2.00k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.04k
{
137
3.04k
  RELOC *reloc_src = (RELOC *) src;
138
3.04k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.04k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.04k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.04k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.04k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.04k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.04k
#endif
146
3.04k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.51k
{
137
1.51k
  RELOC *reloc_src = (RELOC *) src;
138
1.51k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.51k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.51k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.51k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.51k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.51k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.51k
#endif
146
1.51k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.51k
{
137
1.51k
  RELOC *reloc_src = (RELOC *) src;
138
1.51k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.51k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.51k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.51k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.51k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.51k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.51k
#endif
146
1.51k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
3.58k
{
137
3.58k
  RELOC *reloc_src = (RELOC *) src;
138
3.58k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.58k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.58k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.58k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.58k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
2.09k
{
137
2.09k
  RELOC *reloc_src = (RELOC *) src;
138
2.09k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.09k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.09k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.09k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.09k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.09k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.09k
#endif
146
2.09k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.22k
{
137
2.22k
  RELOC *reloc_src = (RELOC *) src;
138
2.22k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.22k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.22k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.22k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.22k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
3.48k
{
137
3.48k
  RELOC *reloc_src = (RELOC *) src;
138
3.48k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.48k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.48k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.48k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.48k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.48k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.48k
#endif
146
3.48k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
3.65k
{
137
3.65k
  RELOC *reloc_src = (RELOC *) src;
138
3.65k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.65k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.65k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.65k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.65k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.65k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.65k
#endif
146
3.65k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
2.89k
{
137
2.89k
  RELOC *reloc_src = (RELOC *) src;
138
2.89k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.89k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.89k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.89k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.89k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.89k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.89k
#endif
146
2.89k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.37k
{
137
2.37k
  RELOC *reloc_src = (RELOC *) src;
138
2.37k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.37k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.37k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.37k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.37k
}
147
148
static unsigned int
149
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
150
0
{
151
0
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
0
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
0
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
0
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
0
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
0
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
0
  return RELSZ;
165
0
}
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
Unexecuted instantiation: pe-aarch64.c:coff_swap_reloc_out
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
166
#endif /* not NO_COFF_RELOCS */
167
168
#ifdef COFF_IMAGE_WITH_PE
169
#undef FILHDR
170
364k
#define FILHDR struct external_PEI_IMAGE_hdr
171
#endif
172
173
static void
174
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
175
1.49M
{
176
1.49M
  FILHDR *filehdr_src = (FILHDR *) src;
177
1.49M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
1.49M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
1.49M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
1.49M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
1.49M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
1.49M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
1.49M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
1.49M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
141k
    {
190
141k
      filehdr_dst->f_nsyms = 0;
191
141k
      filehdr_dst->f_flags |= F_LSYMS;
192
141k
    }
193
194
1.49M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
1.49M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
41.0k
{
176
41.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
41.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
41.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
41.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
41.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
41.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
41.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
41.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
41.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.71k
    {
190
3.71k
      filehdr_dst->f_nsyms = 0;
191
3.71k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.71k
    }
193
194
41.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
41.0k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
122k
{
176
122k
  FILHDR *filehdr_src = (FILHDR *) src;
177
122k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
122k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
122k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
122k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
122k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
122k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
122k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
122k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
12.3k
    {
190
12.3k
      filehdr_dst->f_nsyms = 0;
191
12.3k
      filehdr_dst->f_flags |= F_LSYMS;
192
12.3k
    }
193
194
122k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
122k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
39.9k
{
176
39.9k
  FILHDR *filehdr_src = (FILHDR *) src;
177
39.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
39.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
39.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
39.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
39.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
39.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
39.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
39.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.61k
    {
190
3.61k
      filehdr_dst->f_nsyms = 0;
191
3.61k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.61k
    }
193
194
39.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
39.9k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
121k
{
176
121k
  FILHDR *filehdr_src = (FILHDR *) src;
177
121k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
121k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
121k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
121k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
121k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
121k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
121k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
121k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
12.2k
    {
190
12.2k
      filehdr_dst->f_nsyms = 0;
191
12.2k
      filehdr_dst->f_flags |= F_LSYMS;
192
12.2k
    }
193
194
121k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
121k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
38.8k
{
176
38.8k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.8k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.52k
    {
190
3.52k
      filehdr_dst->f_nsyms = 0;
191
3.52k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.52k
    }
193
194
38.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.8k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
175
14.9k
{
176
14.9k
  FILHDR *filehdr_src = (FILHDR *) src;
177
14.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
14.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
14.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
14.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
14.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
14.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
14.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
14.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
654
    {
190
654
      filehdr_dst->f_nsyms = 0;
191
654
      filehdr_dst->f_flags |= F_LSYMS;
192
654
    }
193
194
14.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
14.9k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
38.3k
{
176
38.3k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.50k
    {
190
3.50k
      filehdr_dst->f_nsyms = 0;
191
3.50k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.50k
    }
193
194
38.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.3k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
175
38.5k
{
176
38.5k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.5k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.5k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.5k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.5k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.5k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.5k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.5k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.5k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.45k
    {
190
3.45k
      filehdr_dst->f_nsyms = 0;
191
3.45k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.45k
    }
193
194
38.5k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.5k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
217k
{
176
217k
  FILHDR *filehdr_src = (FILHDR *) src;
177
217k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
217k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
217k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
217k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
217k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
217k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
217k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
217k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
20.6k
    {
190
20.6k
      filehdr_dst->f_nsyms = 0;
191
20.6k
      filehdr_dst->f_flags |= F_LSYMS;
192
20.6k
    }
193
194
217k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
217k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
217k
{
176
217k
  FILHDR *filehdr_src = (FILHDR *) src;
177
217k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
217k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
217k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
217k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
217k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
217k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
217k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
217k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
20.6k
    {
190
20.6k
      filehdr_dst->f_nsyms = 0;
191
20.6k
      filehdr_dst->f_flags |= F_LSYMS;
192
20.6k
    }
193
194
217k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
217k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
121k
{
176
121k
  FILHDR *filehdr_src = (FILHDR *) src;
177
121k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
121k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
121k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
121k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
121k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
121k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
121k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
121k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
12.2k
    {
190
12.2k
      filehdr_dst->f_nsyms = 0;
191
12.2k
      filehdr_dst->f_flags |= F_LSYMS;
192
12.2k
    }
193
194
121k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
121k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
217k
{
176
217k
  FILHDR *filehdr_src = (FILHDR *) src;
177
217k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
217k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
217k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
217k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
217k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
217k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
217k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
217k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
20.8k
    {
190
20.8k
      filehdr_dst->f_nsyms = 0;
191
20.8k
      filehdr_dst->f_flags |= F_LSYMS;
192
20.8k
    }
193
194
217k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
217k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
110k
{
176
110k
  FILHDR *filehdr_src = (FILHDR *) src;
177
110k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
110k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
110k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
110k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
110k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
110k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
110k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
110k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
10.5k
    {
190
10.5k
      filehdr_dst->f_nsyms = 0;
191
10.5k
      filehdr_dst->f_flags |= F_LSYMS;
192
10.5k
    }
193
194
110k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
110k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
38.2k
{
176
38.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.49k
    {
190
3.49k
      filehdr_dst->f_nsyms = 0;
191
3.49k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.49k
    }
193
194
38.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.2k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
38.3k
{
176
38.3k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.49k
    {
190
3.49k
      filehdr_dst->f_nsyms = 0;
191
3.49k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.49k
    }
193
194
38.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.3k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
38.0k
{
176
38.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.45k
    {
190
3.45k
      filehdr_dst->f_nsyms = 0;
191
3.45k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.45k
    }
193
194
38.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.0k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
38.1k
{
176
38.1k
  FILHDR *filehdr_src = (FILHDR *) src;
177
38.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
38.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
38.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
38.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
38.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
38.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
38.1k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
38.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.45k
    {
190
3.45k
      filehdr_dst->f_nsyms = 0;
191
3.45k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.45k
    }
193
194
38.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
38.1k
}
196
197
#ifdef COFF_IMAGE_WITH_PE
198
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
199
#elif defined COFF_WITH_peAArch64
200
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
201
#elif defined COFF_WITH_pex64
202
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
203
#elif defined COFF_WITH_pep
204
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
205
#else
206
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
207
#endif
208
209
static void
210
coff_swap_scnhdr_in (bfd *abfd, void *ext, void *in)
211
676k
{
212
676k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
676k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
676k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
676k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
676k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
676k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
676k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
676k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
676k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
676k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
460k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
460k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
215k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
215k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
676k
  if (scnhdr_int->s_vaddr != 0)
238
433k
    {
239
433k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
433k
    }
246
247
676k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
676k
  if (scnhdr_int->s_paddr > 0
253
482k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
114k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
438k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
136k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
676k
#endif
262
676k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
52.7k
{
212
52.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
52.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
52.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
52.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
52.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
52.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
52.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
52.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
52.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
52.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
52.7k
#ifdef COFF_IMAGE_WITH_PE
229
52.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
52.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
52.7k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
52.7k
  if (scnhdr_int->s_vaddr != 0)
238
33.7k
    {
239
33.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
33.7k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
33.7k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
33.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
33.7k
#endif
245
33.7k
    }
246
247
52.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
52.7k
  if (scnhdr_int->s_paddr > 0
253
37.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.70k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
36.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
13.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
52.7k
#endif
262
52.7k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
46.1k
{
212
46.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
46.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
46.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
46.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
46.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
46.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
46.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
46.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
46.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
46.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
46.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
46.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
46.1k
#endif
236
237
46.1k
  if (scnhdr_int->s_vaddr != 0)
238
26.0k
    {
239
26.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
26.0k
    }
246
247
46.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
46.1k
  if (scnhdr_int->s_paddr > 0
253
27.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
5.00k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
22.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
5.00k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
46.1k
#endif
262
46.1k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
49.2k
{
212
49.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
49.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
49.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
49.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
49.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
49.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
49.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
49.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
49.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
49.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
49.2k
#ifdef COFF_IMAGE_WITH_PE
229
49.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
49.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
49.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
49.2k
  if (scnhdr_int->s_vaddr != 0)
238
31.4k
    {
239
31.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
31.4k
    }
246
247
49.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
49.2k
  if (scnhdr_int->s_paddr > 0
253
34.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.64k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
12.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
49.2k
#endif
262
49.2k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
27.6k
{
212
27.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
27.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
27.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
27.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
27.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
27.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
27.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
27.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
27.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
27.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
27.6k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
27.6k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
27.6k
#endif
236
237
27.6k
  if (scnhdr_int->s_vaddr != 0)
238
16.9k
    {
239
16.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
16.9k
    }
246
247
27.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
27.6k
  if (scnhdr_int->s_paddr > 0
253
18.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.63k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
14.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.63k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
27.6k
#endif
262
27.6k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
57.5k
{
212
57.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
57.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
57.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
57.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
57.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
57.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
57.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
57.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
57.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
57.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
57.5k
#ifdef COFF_IMAGE_WITH_PE
229
57.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
57.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
57.5k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
57.5k
  if (scnhdr_int->s_vaddr != 0)
238
40.1k
    {
239
40.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
40.1k
    }
246
247
57.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
57.5k
  if (scnhdr_int->s_paddr > 0
253
40.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.78k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
39.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
14.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
57.5k
#endif
262
57.5k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
211
38.9k
{
212
38.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
38.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
38.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
38.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
38.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
38.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
38.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
38.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
38.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
38.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
38.9k
#ifdef COFF_IMAGE_WITH_PE
229
38.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
38.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
38.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
38.9k
  if (scnhdr_int->s_vaddr != 0)
238
25.3k
    {
239
25.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
25.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
25.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
25.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
25.3k
#endif
245
25.3k
    }
246
247
38.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
38.9k
  if (scnhdr_int->s_paddr > 0
253
27.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.59k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
26.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.53k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
38.9k
#endif
262
38.9k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
40.9k
{
212
40.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
40.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
40.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
40.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
40.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
40.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
40.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
40.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
40.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
40.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
40.9k
#ifdef COFF_IMAGE_WITH_PE
229
40.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
40.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
40.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
40.9k
  if (scnhdr_int->s_vaddr != 0)
238
26.9k
    {
239
26.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
26.9k
    }
246
247
40.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
40.9k
  if (scnhdr_int->s_paddr > 0
253
29.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.13k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
28.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.05k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
40.9k
#endif
262
40.9k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
211
47.6k
{
212
47.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
47.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
47.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
47.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
47.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
47.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
47.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
47.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
47.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
47.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
47.6k
#ifdef COFF_IMAGE_WITH_PE
229
47.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
47.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
47.6k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
47.6k
  if (scnhdr_int->s_vaddr != 0)
238
29.5k
    {
239
29.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
29.5k
    }
246
247
47.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
47.6k
  if (scnhdr_int->s_paddr > 0
253
34.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.52k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.01k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
47.6k
#endif
262
47.6k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
19.1k
{
212
19.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
19.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
19.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
19.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
19.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
19.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
19.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
19.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
19.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
19.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
19.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
19.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
19.1k
#endif
236
237
19.1k
  if (scnhdr_int->s_vaddr != 0)
238
11.6k
    {
239
11.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
11.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
11.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
11.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
11.6k
#endif
245
11.6k
    }
246
247
19.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
19.1k
  if (scnhdr_int->s_paddr > 0
253
12.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.30k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
9.31k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.30k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
19.1k
#endif
262
19.1k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
19.1k
{
212
19.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
19.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
19.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
19.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
19.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
19.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
19.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
19.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
19.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
19.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
19.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
19.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
19.1k
#endif
236
237
19.1k
  if (scnhdr_int->s_vaddr != 0)
238
11.6k
    {
239
11.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
11.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
11.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
11.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
11.6k
#endif
245
11.6k
    }
246
247
19.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
19.1k
  if (scnhdr_int->s_paddr > 0
253
12.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.30k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
9.31k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.30k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
19.1k
#endif
262
19.1k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
44.7k
{
212
44.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
44.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
44.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
44.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
44.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
44.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
44.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
44.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
44.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
44.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
44.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
44.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
44.7k
#endif
236
237
44.7k
  if (scnhdr_int->s_vaddr != 0)
238
28.4k
    {
239
28.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
28.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
28.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
28.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
28.4k
#endif
245
28.4k
    }
246
247
44.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
44.7k
  if (scnhdr_int->s_paddr > 0
253
32.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.73k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
25.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
7.73k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
44.7k
#endif
262
44.7k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
21.1k
{
212
21.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
21.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
21.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
21.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
21.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
21.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
21.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
21.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
21.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
21.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
21.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
21.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
21.1k
#endif
236
237
21.1k
  if (scnhdr_int->s_vaddr != 0)
238
12.9k
    {
239
12.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
12.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
12.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
12.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
12.9k
#endif
245
12.9k
    }
246
247
21.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
21.1k
  if (scnhdr_int->s_paddr > 0
253
15.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.03k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.03k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
21.1k
#endif
262
21.1k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
37.4k
{
212
37.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
37.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
37.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
37.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
37.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
37.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
37.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
37.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
37.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
37.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
37.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
37.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
37.4k
#endif
236
237
37.4k
  if (scnhdr_int->s_vaddr != 0)
238
23.3k
    {
239
23.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
23.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
23.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
23.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
23.3k
#endif
245
23.3k
    }
246
247
37.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
37.4k
  if (scnhdr_int->s_paddr > 0
253
26.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
5.40k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
20.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
5.40k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
37.4k
#endif
262
37.4k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
38.8k
{
212
38.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
38.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
38.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
38.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
38.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
38.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
38.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
38.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
38.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
38.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
38.8k
#ifdef COFF_IMAGE_WITH_PE
229
38.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
38.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
38.8k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
38.8k
  if (scnhdr_int->s_vaddr != 0)
238
25.5k
    {
239
25.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
25.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
25.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
25.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
25.5k
#endif
245
25.5k
    }
246
247
38.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
38.8k
  if (scnhdr_int->s_paddr > 0
253
30.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.21k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
28.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
8.65k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
38.8k
#endif
262
38.8k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
48.7k
{
212
48.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
48.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
48.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
48.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
48.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
48.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
48.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
48.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
48.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
48.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
48.7k
#ifdef COFF_IMAGE_WITH_PE
229
48.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
48.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
48.7k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
48.7k
  if (scnhdr_int->s_vaddr != 0)
238
32.9k
    {
239
32.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
32.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
32.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
32.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
32.9k
#endif
245
32.9k
    }
246
247
48.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
48.7k
  if (scnhdr_int->s_paddr > 0
253
37.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
36.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
48.7k
#endif
262
48.7k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
46.9k
{
212
46.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
46.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
46.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
46.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
46.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
46.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
46.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
46.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
46.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
46.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
46.9k
#ifdef COFF_IMAGE_WITH_PE
229
46.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
46.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
46.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
46.9k
  if (scnhdr_int->s_vaddr != 0)
238
30.4k
    {
239
30.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
30.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
30.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
30.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
30.4k
#endif
245
30.4k
    }
246
247
46.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
46.9k
  if (scnhdr_int->s_paddr > 0
253
34.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.69k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
8.84k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
46.9k
#endif
262
46.9k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
39.2k
{
212
39.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
39.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
39.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
39.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
39.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
39.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
39.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
39.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
39.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
39.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
39.2k
#ifdef COFF_IMAGE_WITH_PE
229
39.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
39.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
39.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
39.2k
  if (scnhdr_int->s_vaddr != 0)
238
26.5k
    {
239
26.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
26.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
26.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
26.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
26.5k
#endif
245
26.5k
    }
246
247
39.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
39.2k
  if (scnhdr_int->s_paddr > 0
253
29.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.08k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
28.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.48k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
39.2k
#endif
262
39.2k
}
263
264
static bool
265
pe_mkobject (bfd *abfd)
266
71.9k
{
267
  /* Some x86 code followed by an ascii string.  */
268
71.9k
  static const char default_dos_message[64] = {
269
71.9k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
71.9k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
71.9k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
71.9k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
71.9k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
71.9k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
71.9k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
71.9k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
71.9k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
71.9k
  abfd->tdata.pe_obj_data = pe;
280
71.9k
  if (pe == NULL)
281
0
    return false;
282
283
71.9k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
71.9k
  pe->in_reloc_p = in_reloc_p;
287
288
71.9k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
71.9k
  bfd_coff_long_section_names (abfd)
291
71.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
71.9k
  return true;
294
71.9k
}
pei-i386.c:pe_mkobject
Line
Count
Source
266
8.33k
{
267
  /* Some x86 code followed by an ascii string.  */
268
8.33k
  static const char default_dos_message[64] = {
269
8.33k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
8.33k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
8.33k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
8.33k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
8.33k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
8.33k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
8.33k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
8.33k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
8.33k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
8.33k
  abfd->tdata.pe_obj_data = pe;
280
8.33k
  if (pe == NULL)
281
0
    return false;
282
283
8.33k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
8.33k
  pe->in_reloc_p = in_reloc_p;
287
288
8.33k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
8.33k
  bfd_coff_long_section_names (abfd)
291
8.33k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
8.33k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
266
4.50k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.50k
  static const char default_dos_message[64] = {
269
4.50k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.50k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.50k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.50k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.50k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.50k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.50k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.50k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.50k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.50k
  abfd->tdata.pe_obj_data = pe;
280
4.50k
  if (pe == NULL)
281
0
    return false;
282
283
4.50k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.50k
  pe->in_reloc_p = in_reloc_p;
287
288
4.50k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.50k
  bfd_coff_long_section_names (abfd)
291
4.50k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.50k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
266
6.18k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.18k
  static const char default_dos_message[64] = {
269
6.18k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.18k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.18k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.18k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.18k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.18k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.18k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.18k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.18k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.18k
  abfd->tdata.pe_obj_data = pe;
280
6.18k
  if (pe == NULL)
281
0
    return false;
282
283
6.18k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.18k
  pe->in_reloc_p = in_reloc_p;
287
288
6.18k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.18k
  bfd_coff_long_section_names (abfd)
291
6.18k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.18k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
266
2.49k
{
267
  /* Some x86 code followed by an ascii string.  */
268
2.49k
  static const char default_dos_message[64] = {
269
2.49k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
2.49k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
2.49k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
2.49k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
2.49k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
2.49k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
2.49k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
2.49k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
2.49k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
2.49k
  abfd->tdata.pe_obj_data = pe;
280
2.49k
  if (pe == NULL)
281
0
    return false;
282
283
2.49k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
2.49k
  pe->in_reloc_p = in_reloc_p;
287
288
2.49k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
2.49k
  bfd_coff_long_section_names (abfd)
291
2.49k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
2.49k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
266
6.26k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.26k
  static const char default_dos_message[64] = {
269
6.26k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.26k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.26k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.26k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.26k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.26k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.26k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.26k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.26k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.26k
  abfd->tdata.pe_obj_data = pe;
280
6.26k
  if (pe == NULL)
281
0
    return false;
282
283
6.26k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.26k
  pe->in_reloc_p = in_reloc_p;
287
288
6.26k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.26k
  bfd_coff_long_section_names (abfd)
291
6.26k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.26k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
266
4.24k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.24k
  static const char default_dos_message[64] = {
269
4.24k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.24k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.24k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.24k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.24k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.24k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.24k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.24k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.24k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.24k
  abfd->tdata.pe_obj_data = pe;
280
4.24k
  if (pe == NULL)
281
0
    return false;
282
283
4.24k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.24k
  pe->in_reloc_p = in_reloc_p;
287
288
4.24k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.24k
  bfd_coff_long_section_names (abfd)
291
4.24k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.24k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
266
4.21k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.21k
  static const char default_dos_message[64] = {
269
4.21k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.21k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.21k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.21k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.21k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.21k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.21k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.21k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.21k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.21k
  abfd->tdata.pe_obj_data = pe;
280
4.21k
  if (pe == NULL)
281
0
    return false;
282
283
4.21k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.21k
  pe->in_reloc_p = in_reloc_p;
287
288
4.21k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.21k
  bfd_coff_long_section_names (abfd)
291
4.21k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.21k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
266
4.85k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.85k
  static const char default_dos_message[64] = {
269
4.85k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.85k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.85k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.85k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.85k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.85k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.85k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.85k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.85k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.85k
  abfd->tdata.pe_obj_data = pe;
280
4.85k
  if (pe == NULL)
281
0
    return false;
282
283
4.85k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.85k
  pe->in_reloc_p = in_reloc_p;
287
288
4.85k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.85k
  bfd_coff_long_section_names (abfd)
291
4.85k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.85k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
266
1.57k
{
267
  /* Some x86 code followed by an ascii string.  */
268
1.57k
  static const char default_dos_message[64] = {
269
1.57k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
1.57k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
1.57k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
1.57k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
1.57k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
1.57k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
1.57k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
1.57k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
1.57k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
1.57k
  abfd->tdata.pe_obj_data = pe;
280
1.57k
  if (pe == NULL)
281
0
    return false;
282
283
1.57k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
1.57k
  pe->in_reloc_p = in_reloc_p;
287
288
1.57k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
1.57k
  bfd_coff_long_section_names (abfd)
291
1.57k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
1.57k
}
pe-arm.c:pe_mkobject
Line
Count
Source
266
1.57k
{
267
  /* Some x86 code followed by an ascii string.  */
268
1.57k
  static const char default_dos_message[64] = {
269
1.57k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
1.57k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
1.57k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
1.57k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
1.57k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
1.57k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
1.57k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
1.57k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
1.57k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
1.57k
  abfd->tdata.pe_obj_data = pe;
280
1.57k
  if (pe == NULL)
281
0
    return false;
282
283
1.57k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
1.57k
  pe->in_reloc_p = in_reloc_p;
287
288
1.57k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
1.57k
  bfd_coff_long_section_names (abfd)
291
1.57k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
1.57k
}
pe-i386.c:pe_mkobject
Line
Count
Source
266
5.72k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.72k
  static const char default_dos_message[64] = {
269
5.72k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.72k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.72k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.72k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.72k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.72k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.72k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.72k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.72k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.72k
  abfd->tdata.pe_obj_data = pe;
280
5.72k
  if (pe == NULL)
281
0
    return false;
282
283
5.72k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.72k
  pe->in_reloc_p = in_reloc_p;
287
288
5.72k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.72k
  bfd_coff_long_section_names (abfd)
291
5.72k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.72k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
266
1.95k
{
267
  /* Some x86 code followed by an ascii string.  */
268
1.95k
  static const char default_dos_message[64] = {
269
1.95k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
1.95k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
1.95k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
1.95k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
1.95k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
1.95k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
1.95k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
1.95k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
1.95k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
1.95k
  abfd->tdata.pe_obj_data = pe;
280
1.95k
  if (pe == NULL)
281
0
    return false;
282
283
1.95k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
1.95k
  pe->in_reloc_p = in_reloc_p;
287
288
1.95k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
1.95k
  bfd_coff_long_section_names (abfd)
291
1.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
1.95k
}
pe-sh.c:pe_mkobject
Line
Count
Source
266
2.98k
{
267
  /* Some x86 code followed by an ascii string.  */
268
2.98k
  static const char default_dos_message[64] = {
269
2.98k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
2.98k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
2.98k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
2.98k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
2.98k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
2.98k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
2.98k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
2.98k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
2.98k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
2.98k
  abfd->tdata.pe_obj_data = pe;
280
2.98k
  if (pe == NULL)
281
0
    return false;
282
283
2.98k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
2.98k
  pe->in_reloc_p = in_reloc_p;
287
288
2.98k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
2.98k
  bfd_coff_long_section_names (abfd)
291
2.98k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
2.98k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
266
4.22k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.22k
  static const char default_dos_message[64] = {
269
4.22k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.22k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.22k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.22k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.22k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.22k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.22k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.22k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.22k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.22k
  abfd->tdata.pe_obj_data = pe;
280
4.22k
  if (pe == NULL)
281
0
    return false;
282
283
4.22k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.22k
  pe->in_reloc_p = in_reloc_p;
287
288
4.22k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.22k
  bfd_coff_long_section_names (abfd)
291
4.22k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.22k
}
pei-arm.c:pe_mkobject
Line
Count
Source
266
5.21k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.21k
  static const char default_dos_message[64] = {
269
5.21k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.21k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.21k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.21k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.21k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.21k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.21k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.21k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.21k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.21k
  abfd->tdata.pe_obj_data = pe;
280
5.21k
  if (pe == NULL)
281
0
    return false;
282
283
5.21k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.21k
  pe->in_reloc_p = in_reloc_p;
287
288
5.21k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.21k
  bfd_coff_long_section_names (abfd)
291
5.21k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.21k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
266
3.77k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.77k
  static const char default_dos_message[64] = {
269
3.77k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.77k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.77k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.77k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.77k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.77k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.77k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.77k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.77k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.77k
  abfd->tdata.pe_obj_data = pe;
280
3.77k
  if (pe == NULL)
281
0
    return false;
282
283
3.77k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.77k
  pe->in_reloc_p = in_reloc_p;
287
288
3.77k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.77k
  bfd_coff_long_section_names (abfd)
291
3.77k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.77k
}
pei-sh.c:pe_mkobject
Line
Count
Source
266
3.85k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.85k
  static const char default_dos_message[64] = {
269
3.85k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.85k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.85k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.85k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.85k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.85k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.85k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.85k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.85k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.85k
  abfd->tdata.pe_obj_data = pe;
280
3.85k
  if (pe == NULL)
281
0
    return false;
282
283
3.85k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.85k
  pe->in_reloc_p = in_reloc_p;
287
288
3.85k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.85k
  bfd_coff_long_section_names (abfd)
291
3.85k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.85k
}
295
296
/* Create the COFF backend specific information.  */
297
298
static void *
299
pe_mkobject_hook (bfd *abfd,
300
      void *filehdr,
301
      void *aouthdr ATTRIBUTE_UNUSED)
302
71.2k
{
303
71.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
71.2k
  pe_data_type *pe;
305
306
71.2k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
71.2k
  pe = pe_data (abfd);
310
71.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
71.2k
  pe->coff.local_n_btmask = N_BTMASK;
315
71.2k
  pe->coff.local_n_btshft = N_BTSHFT;
316
71.2k
  pe->coff.local_n_tmask = N_TMASK;
317
71.2k
  pe->coff.local_n_tshift = N_TSHIFT;
318
71.2k
  pe->coff.local_symesz = SYMESZ;
319
71.2k
  pe->coff.local_auxesz = AUXESZ;
320
71.2k
  pe->coff.local_linesz = LINESZ;
321
322
71.2k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
71.2k
  obj_raw_syment_count (abfd) =
325
71.2k
    obj_conv_table_size (abfd) =
326
71.2k
      internal_f->f_nsyms;
327
328
71.2k
  pe->real_flags = internal_f->f_flags;
329
330
71.2k
  if ((internal_f->f_flags & F_DLL) != 0)
331
21.9k
    pe->dll = 1;
332
333
71.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
51.2k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
50.6k
  if (aouthdr)
338
29.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
12.5k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
71.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
71.2k
    sizeof (pe->dos_message));
348
349
71.2k
  return (void *) pe;
350
71.2k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
302
8.26k
{
303
8.26k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
8.26k
  pe_data_type *pe;
305
306
8.26k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
8.26k
  pe = pe_data (abfd);
310
8.26k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
8.26k
  pe->coff.local_n_btmask = N_BTMASK;
315
8.26k
  pe->coff.local_n_btshft = N_BTSHFT;
316
8.26k
  pe->coff.local_n_tmask = N_TMASK;
317
8.26k
  pe->coff.local_n_tshift = N_TSHIFT;
318
8.26k
  pe->coff.local_symesz = SYMESZ;
319
8.26k
  pe->coff.local_auxesz = AUXESZ;
320
8.26k
  pe->coff.local_linesz = LINESZ;
321
322
8.26k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
8.26k
  obj_raw_syment_count (abfd) =
325
8.26k
    obj_conv_table_size (abfd) =
326
8.26k
      internal_f->f_nsyms;
327
328
8.26k
  pe->real_flags = internal_f->f_flags;
329
330
8.26k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.07k
    pe->dll = 1;
332
333
8.26k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
6.73k
    abfd->flags |= HAS_DEBUG;
335
336
8.26k
#ifdef COFF_IMAGE_WITH_PE
337
8.26k
  if (aouthdr)
338
4.04k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
8.26k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
8.26k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
8.26k
    sizeof (pe->dos_message));
348
349
8.26k
  return (void *) pe;
350
8.26k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
4.44k
{
303
4.44k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.44k
  pe_data_type *pe;
305
306
4.44k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.44k
  pe = pe_data (abfd);
310
4.44k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.44k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.44k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.44k
  pe->coff.local_n_tmask = N_TMASK;
317
4.44k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.44k
  pe->coff.local_symesz = SYMESZ;
319
4.44k
  pe->coff.local_auxesz = AUXESZ;
320
4.44k
  pe->coff.local_linesz = LINESZ;
321
322
4.44k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.44k
  obj_raw_syment_count (abfd) =
325
4.44k
    obj_conv_table_size (abfd) =
326
4.44k
      internal_f->f_nsyms;
327
328
4.44k
  pe->real_flags = internal_f->f_flags;
329
330
4.44k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.07k
    pe->dll = 1;
332
333
4.44k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.36k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.44k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.44k
    sizeof (pe->dos_message));
348
349
4.44k
  return (void *) pe;
350
4.44k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
6.13k
{
303
6.13k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.13k
  pe_data_type *pe;
305
306
6.13k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.13k
  pe = pe_data (abfd);
310
6.13k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.13k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.13k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.13k
  pe->coff.local_n_tmask = N_TMASK;
317
6.13k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.13k
  pe->coff.local_symesz = SYMESZ;
319
6.13k
  pe->coff.local_auxesz = AUXESZ;
320
6.13k
  pe->coff.local_linesz = LINESZ;
321
322
6.13k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.13k
  obj_raw_syment_count (abfd) =
325
6.13k
    obj_conv_table_size (abfd) =
326
6.13k
      internal_f->f_nsyms;
327
328
6.13k
  pe->real_flags = internal_f->f_flags;
329
330
6.13k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.28k
    pe->dll = 1;
332
333
6.13k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.20k
    abfd->flags |= HAS_DEBUG;
335
336
6.13k
#ifdef COFF_IMAGE_WITH_PE
337
6.13k
  if (aouthdr)
338
3.85k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.13k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.13k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.13k
    sizeof (pe->dos_message));
348
349
6.13k
  return (void *) pe;
350
6.13k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
2.46k
{
303
2.46k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
2.46k
  pe_data_type *pe;
305
306
2.46k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
2.46k
  pe = pe_data (abfd);
310
2.46k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
2.46k
  pe->coff.local_n_btmask = N_BTMASK;
315
2.46k
  pe->coff.local_n_btshft = N_BTSHFT;
316
2.46k
  pe->coff.local_n_tmask = N_TMASK;
317
2.46k
  pe->coff.local_n_tshift = N_TSHIFT;
318
2.46k
  pe->coff.local_symesz = SYMESZ;
319
2.46k
  pe->coff.local_auxesz = AUXESZ;
320
2.46k
  pe->coff.local_linesz = LINESZ;
321
322
2.46k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
2.46k
  obj_raw_syment_count (abfd) =
325
2.46k
    obj_conv_table_size (abfd) =
326
2.46k
      internal_f->f_nsyms;
327
328
2.46k
  pe->real_flags = internal_f->f_flags;
329
330
2.46k
  if ((internal_f->f_flags & F_DLL) != 0)
331
537
    pe->dll = 1;
332
333
2.46k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.90k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
2.46k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
2.46k
    sizeof (pe->dos_message));
348
349
2.46k
  return (void *) pe;
350
2.46k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
6.23k
{
303
6.23k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.23k
  pe_data_type *pe;
305
306
6.23k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.23k
  pe = pe_data (abfd);
310
6.23k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.23k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.23k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.23k
  pe->coff.local_n_tmask = N_TMASK;
317
6.23k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.23k
  pe->coff.local_symesz = SYMESZ;
319
6.23k
  pe->coff.local_auxesz = AUXESZ;
320
6.23k
  pe->coff.local_linesz = LINESZ;
321
322
6.23k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.23k
  obj_raw_syment_count (abfd) =
325
6.23k
    obj_conv_table_size (abfd) =
326
6.23k
      internal_f->f_nsyms;
327
328
6.23k
  pe->real_flags = internal_f->f_flags;
329
330
6.23k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.34k
    pe->dll = 1;
332
333
6.23k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
5.03k
    abfd->flags |= HAS_DEBUG;
335
336
6.23k
#ifdef COFF_IMAGE_WITH_PE
337
6.23k
  if (aouthdr)
338
4.86k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.23k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.23k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.23k
    sizeof (pe->dos_message));
348
349
6.23k
  return (void *) pe;
350
6.23k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
302
4.18k
{
303
4.18k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.18k
  pe_data_type *pe;
305
306
4.18k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.18k
  pe = pe_data (abfd);
310
4.18k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.18k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.18k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.18k
  pe->coff.local_n_tmask = N_TMASK;
317
4.18k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.18k
  pe->coff.local_symesz = SYMESZ;
319
4.18k
  pe->coff.local_auxesz = AUXESZ;
320
4.18k
  pe->coff.local_linesz = LINESZ;
321
322
4.18k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.18k
  obj_raw_syment_count (abfd) =
325
4.18k
    obj_conv_table_size (abfd) =
326
4.18k
      internal_f->f_nsyms;
327
328
4.18k
  pe->real_flags = internal_f->f_flags;
329
330
4.18k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.35k
    pe->dll = 1;
332
333
4.18k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.77k
    abfd->flags |= HAS_DEBUG;
335
336
4.18k
#ifdef COFF_IMAGE_WITH_PE
337
4.18k
  if (aouthdr)
338
1.89k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.18k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.18k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.18k
    sizeof (pe->dos_message));
348
349
4.18k
  return (void *) pe;
350
4.18k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
302
4.15k
{
303
4.15k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.15k
  pe_data_type *pe;
305
306
4.15k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.15k
  pe = pe_data (abfd);
310
4.15k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.15k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.15k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.15k
  pe->coff.local_n_tmask = N_TMASK;
317
4.15k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.15k
  pe->coff.local_symesz = SYMESZ;
319
4.15k
  pe->coff.local_auxesz = AUXESZ;
320
4.15k
  pe->coff.local_linesz = LINESZ;
321
322
4.15k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.15k
  obj_raw_syment_count (abfd) =
325
4.15k
    obj_conv_table_size (abfd) =
326
4.15k
      internal_f->f_nsyms;
327
328
4.15k
  pe->real_flags = internal_f->f_flags;
329
330
4.15k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.32k
    pe->dll = 1;
332
333
4.15k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.76k
    abfd->flags |= HAS_DEBUG;
335
336
4.15k
#ifdef COFF_IMAGE_WITH_PE
337
4.15k
  if (aouthdr)
338
2.61k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.15k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.15k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.15k
    sizeof (pe->dos_message));
348
349
4.15k
  return (void *) pe;
350
4.15k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
302
4.75k
{
303
4.75k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.75k
  pe_data_type *pe;
305
306
4.75k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.75k
  pe = pe_data (abfd);
310
4.75k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.75k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.75k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.75k
  pe->coff.local_n_tmask = N_TMASK;
317
4.75k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.75k
  pe->coff.local_symesz = SYMESZ;
319
4.75k
  pe->coff.local_auxesz = AUXESZ;
320
4.75k
  pe->coff.local_linesz = LINESZ;
321
322
4.75k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.75k
  obj_raw_syment_count (abfd) =
325
4.75k
    obj_conv_table_size (abfd) =
326
4.75k
      internal_f->f_nsyms;
327
328
4.75k
  pe->real_flags = internal_f->f_flags;
329
330
4.75k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.42k
    pe->dll = 1;
332
333
4.75k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.41k
    abfd->flags |= HAS_DEBUG;
335
336
4.75k
#ifdef COFF_IMAGE_WITH_PE
337
4.75k
  if (aouthdr)
338
3.56k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.75k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.75k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.75k
    sizeof (pe->dos_message));
348
349
4.75k
  return (void *) pe;
350
4.75k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
1.57k
{
303
1.57k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
1.57k
  pe_data_type *pe;
305
306
1.57k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
1.57k
  pe = pe_data (abfd);
310
1.57k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
1.57k
  pe->coff.local_n_btmask = N_BTMASK;
315
1.57k
  pe->coff.local_n_btshft = N_BTSHFT;
316
1.57k
  pe->coff.local_n_tmask = N_TMASK;
317
1.57k
  pe->coff.local_n_tshift = N_TSHIFT;
318
1.57k
  pe->coff.local_symesz = SYMESZ;
319
1.57k
  pe->coff.local_auxesz = AUXESZ;
320
1.57k
  pe->coff.local_linesz = LINESZ;
321
322
1.57k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
1.57k
  obj_raw_syment_count (abfd) =
325
1.57k
    obj_conv_table_size (abfd) =
326
1.57k
      internal_f->f_nsyms;
327
328
1.57k
  pe->real_flags = internal_f->f_flags;
329
330
1.57k
  if ((internal_f->f_flags & F_DLL) != 0)
331
434
    pe->dll = 1;
332
333
1.57k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.18k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
1.57k
#ifdef ARM
342
1.57k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
1.57k
#endif
345
346
1.57k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
1.57k
    sizeof (pe->dos_message));
348
349
1.57k
  return (void *) pe;
350
1.57k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
302
1.57k
{
303
1.57k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
1.57k
  pe_data_type *pe;
305
306
1.57k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
1.57k
  pe = pe_data (abfd);
310
1.57k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
1.57k
  pe->coff.local_n_btmask = N_BTMASK;
315
1.57k
  pe->coff.local_n_btshft = N_BTSHFT;
316
1.57k
  pe->coff.local_n_tmask = N_TMASK;
317
1.57k
  pe->coff.local_n_tshift = N_TSHIFT;
318
1.57k
  pe->coff.local_symesz = SYMESZ;
319
1.57k
  pe->coff.local_auxesz = AUXESZ;
320
1.57k
  pe->coff.local_linesz = LINESZ;
321
322
1.57k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
1.57k
  obj_raw_syment_count (abfd) =
325
1.57k
    obj_conv_table_size (abfd) =
326
1.57k
      internal_f->f_nsyms;
327
328
1.57k
  pe->real_flags = internal_f->f_flags;
329
330
1.57k
  if ((internal_f->f_flags & F_DLL) != 0)
331
434
    pe->dll = 1;
332
333
1.57k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.18k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
1.57k
#ifdef ARM
342
1.57k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
1.57k
#endif
345
346
1.57k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
1.57k
    sizeof (pe->dos_message));
348
349
1.57k
  return (void *) pe;
350
1.57k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
302
5.70k
{
303
5.70k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.70k
  pe_data_type *pe;
305
306
5.70k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.70k
  pe = pe_data (abfd);
310
5.70k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.70k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.70k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.70k
  pe->coff.local_n_tmask = N_TMASK;
317
5.70k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.70k
  pe->coff.local_symesz = SYMESZ;
319
5.70k
  pe->coff.local_auxesz = AUXESZ;
320
5.70k
  pe->coff.local_linesz = LINESZ;
321
322
5.70k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.70k
  obj_raw_syment_count (abfd) =
325
5.70k
    obj_conv_table_size (abfd) =
326
5.70k
      internal_f->f_nsyms;
327
328
5.70k
  pe->real_flags = internal_f->f_flags;
329
330
5.70k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.53k
    pe->dll = 1;
332
333
5.70k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.95k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.70k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.70k
    sizeof (pe->dos_message));
348
349
5.70k
  return (void *) pe;
350
5.70k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
302
1.92k
{
303
1.92k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
1.92k
  pe_data_type *pe;
305
306
1.92k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
1.92k
  pe = pe_data (abfd);
310
1.92k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
1.92k
  pe->coff.local_n_btmask = N_BTMASK;
315
1.92k
  pe->coff.local_n_btshft = N_BTSHFT;
316
1.92k
  pe->coff.local_n_tmask = N_TMASK;
317
1.92k
  pe->coff.local_n_tshift = N_TSHIFT;
318
1.92k
  pe->coff.local_symesz = SYMESZ;
319
1.92k
  pe->coff.local_auxesz = AUXESZ;
320
1.92k
  pe->coff.local_linesz = LINESZ;
321
322
1.92k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
1.92k
  obj_raw_syment_count (abfd) =
325
1.92k
    obj_conv_table_size (abfd) =
326
1.92k
      internal_f->f_nsyms;
327
328
1.92k
  pe->real_flags = internal_f->f_flags;
329
330
1.92k
  if ((internal_f->f_flags & F_DLL) != 0)
331
601
    pe->dll = 1;
332
333
1.92k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.58k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
1.92k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
1.92k
    sizeof (pe->dos_message));
348
349
1.92k
  return (void *) pe;
350
1.92k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
302
2.95k
{
303
2.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
2.95k
  pe_data_type *pe;
305
306
2.95k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
2.95k
  pe = pe_data (abfd);
310
2.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
2.95k
  pe->coff.local_n_btmask = N_BTMASK;
315
2.95k
  pe->coff.local_n_btshft = N_BTSHFT;
316
2.95k
  pe->coff.local_n_tmask = N_TMASK;
317
2.95k
  pe->coff.local_n_tshift = N_TSHIFT;
318
2.95k
  pe->coff.local_symesz = SYMESZ;
319
2.95k
  pe->coff.local_auxesz = AUXESZ;
320
2.95k
  pe->coff.local_linesz = LINESZ;
321
322
2.95k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
2.95k
  obj_raw_syment_count (abfd) =
325
2.95k
    obj_conv_table_size (abfd) =
326
2.95k
      internal_f->f_nsyms;
327
328
2.95k
  pe->real_flags = internal_f->f_flags;
329
330
2.95k
  if ((internal_f->f_flags & F_DLL) != 0)
331
909
    pe->dll = 1;
332
333
2.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.40k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
2.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
2.95k
    sizeof (pe->dos_message));
348
349
2.95k
  return (void *) pe;
350
2.95k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
4.20k
{
303
4.20k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.20k
  pe_data_type *pe;
305
306
4.20k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.20k
  pe = pe_data (abfd);
310
4.20k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.20k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.20k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.20k
  pe->coff.local_n_tmask = N_TMASK;
317
4.20k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.20k
  pe->coff.local_symesz = SYMESZ;
319
4.20k
  pe->coff.local_auxesz = AUXESZ;
320
4.20k
  pe->coff.local_linesz = LINESZ;
321
322
4.20k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.20k
  obj_raw_syment_count (abfd) =
325
4.20k
    obj_conv_table_size (abfd) =
326
4.20k
      internal_f->f_nsyms;
327
328
4.20k
  pe->real_flags = internal_f->f_flags;
329
330
4.20k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.55k
    pe->dll = 1;
332
333
4.20k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.71k
    abfd->flags |= HAS_DEBUG;
335
336
4.20k
#ifdef COFF_IMAGE_WITH_PE
337
4.20k
  if (aouthdr)
338
1.63k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.20k
#endif
340
341
4.20k
#ifdef ARM
342
4.20k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
4.20k
#endif
345
346
4.20k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.20k
    sizeof (pe->dos_message));
348
349
4.20k
  return (void *) pe;
350
4.20k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
302
5.15k
{
303
5.15k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.15k
  pe_data_type *pe;
305
306
5.15k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.15k
  pe = pe_data (abfd);
310
5.15k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.15k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.15k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.15k
  pe->coff.local_n_tmask = N_TMASK;
317
5.15k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.15k
  pe->coff.local_symesz = SYMESZ;
319
5.15k
  pe->coff.local_auxesz = AUXESZ;
320
5.15k
  pe->coff.local_linesz = LINESZ;
321
322
5.15k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.15k
  obj_raw_syment_count (abfd) =
325
5.15k
    obj_conv_table_size (abfd) =
326
5.15k
      internal_f->f_nsyms;
327
328
5.15k
  pe->real_flags = internal_f->f_flags;
329
330
5.15k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.91k
    pe->dll = 1;
332
333
5.15k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.44k
    abfd->flags |= HAS_DEBUG;
335
336
5.15k
#ifdef COFF_IMAGE_WITH_PE
337
5.15k
  if (aouthdr)
338
2.58k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.15k
#endif
340
341
5.15k
#ifdef ARM
342
5.15k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
5.15k
#endif
345
346
5.15k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.15k
    sizeof (pe->dos_message));
348
349
5.15k
  return (void *) pe;
350
5.15k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
302
3.73k
{
303
3.73k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.73k
  pe_data_type *pe;
305
306
3.73k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.73k
  pe = pe_data (abfd);
310
3.73k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.73k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.73k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.73k
  pe->coff.local_n_tmask = N_TMASK;
317
3.73k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.73k
  pe->coff.local_symesz = SYMESZ;
319
3.73k
  pe->coff.local_auxesz = AUXESZ;
320
3.73k
  pe->coff.local_linesz = LINESZ;
321
322
3.73k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.73k
  obj_raw_syment_count (abfd) =
325
3.73k
    obj_conv_table_size (abfd) =
326
3.73k
      internal_f->f_nsyms;
327
328
3.73k
  pe->real_flags = internal_f->f_flags;
329
330
3.73k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.54k
    pe->dll = 1;
332
333
3.73k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.30k
    abfd->flags |= HAS_DEBUG;
335
336
3.73k
#ifdef COFF_IMAGE_WITH_PE
337
3.73k
  if (aouthdr)
338
2.18k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
3.73k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
3.73k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.73k
    sizeof (pe->dos_message));
348
349
3.73k
  return (void *) pe;
350
3.73k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
302
3.80k
{
303
3.80k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.80k
  pe_data_type *pe;
305
306
3.80k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.80k
  pe = pe_data (abfd);
310
3.80k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.80k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.80k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.80k
  pe->coff.local_n_tmask = N_TMASK;
317
3.80k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.80k
  pe->coff.local_symesz = SYMESZ;
319
3.80k
  pe->coff.local_auxesz = AUXESZ;
320
3.80k
  pe->coff.local_linesz = LINESZ;
321
322
3.80k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.80k
  obj_raw_syment_count (abfd) =
325
3.80k
    obj_conv_table_size (abfd) =
326
3.80k
      internal_f->f_nsyms;
327
328
3.80k
  pe->real_flags = internal_f->f_flags;
329
330
3.80k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.64k
    pe->dll = 1;
332
333
3.80k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.32k
    abfd->flags |= HAS_DEBUG;
335
336
3.80k
#ifdef COFF_IMAGE_WITH_PE
337
3.80k
  if (aouthdr)
338
2.33k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
3.80k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
3.80k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.80k
    sizeof (pe->dos_message));
348
349
3.80k
  return (void *) pe;
350
3.80k
}
351
352
static bool
353
pe_print_private_bfd_data (bfd *abfd, void *vfile)
354
3.92k
{
355
3.92k
  FILE *file = (FILE *) vfile;
356
357
3.92k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
3.92k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
3.74k
    return true;
362
363
181
  fputc ('\n', file);
364
365
181
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
3.92k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
144
{
355
144
  FILE *file = (FILE *) vfile;
356
357
144
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
144
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
144
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
144
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
122
{
355
122
  FILE *file = (FILE *) vfile;
356
357
122
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
122
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
122
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
122
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
86
{
355
86
  FILE *file = (FILE *) vfile;
356
357
86
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
86
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
86
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
86
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
486
{
355
486
  FILE *file = (FILE *) vfile;
356
357
486
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
486
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
486
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
486
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
2.15k
{
355
2.15k
  FILE *file = (FILE *) vfile;
356
357
2.15k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
2.15k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
2.15k
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
2.15k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
354
216
{
355
216
  FILE *file = (FILE *) vfile;
356
357
216
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
216
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
216
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
216
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
104
{
355
104
  FILE *file = (FILE *) vfile;
356
357
104
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
104
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
104
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
104
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
354
195
{
355
195
  FILE *file = (FILE *) vfile;
356
357
195
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
195
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
195
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
195
}
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
354
40
{
355
40
  FILE *file = (FILE *) vfile;
356
357
40
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
40
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
40
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
40
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
26
{
355
26
  FILE *file = (FILE *) vfile;
356
357
26
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
26
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
26
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
26
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
55
{
355
55
  FILE *file = (FILE *) vfile;
356
357
55
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
55
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
55
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
55
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
354
7
{
355
7
  FILE *file = (FILE *) vfile;
356
357
7
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
7
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
7
  fputc ('\n', file);
364
365
7
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
7
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
354
174
{
355
174
  FILE *file = (FILE *) vfile;
356
357
174
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
174
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
174
  fputc ('\n', file);
364
365
174
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
174
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
56
{
355
56
  FILE *file = (FILE *) vfile;
356
357
56
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
56
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
56
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
56
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
52
{
355
52
  FILE *file = (FILE *) vfile;
356
357
52
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
52
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
52
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
52
}
367
368
/* Copy any private info we understand from the input bfd
369
   to the output bfd.  */
370
371
static bool
372
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
373
55
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
55
  if (pe_data (obfd) != NULL
378
55
      && pe_data (ibfd) != NULL
379
55
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
26
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
55
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
54
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
9
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
45
  return true;
389
54
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
5
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
5
  if (pe_data (obfd) != NULL
378
5
      && pe_data (ibfd) != NULL
379
5
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
5
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
5
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
5
  return true;
389
5
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
8
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
8
  if (pe_data (obfd) != NULL
378
8
      && pe_data (ibfd) != NULL
379
8
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
2
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
8
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
8
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
8
  return true;
389
8
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
9
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
9
  if (pe_data (obfd) != NULL
378
9
      && pe_data (ibfd) != NULL
379
9
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
9
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
9
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
9
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
9
  return true;
389
9
}
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_bfd_copy_private_bfd_data
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
4
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
4
  if (pe_data (obfd) != NULL
378
4
      && pe_data (ibfd) != NULL
379
4
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
4
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
4
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
3
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
3
  return true;
389
3
}
Unexecuted instantiation: pei-loongarch64.c:pe_bfd_copy_private_bfd_data
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
3
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
3
  if (pe_data (obfd) != NULL
378
3
      && pe_data (ibfd) != NULL
379
3
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
3
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
3
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
3
  return true;
389
3
}
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
373
1
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
1
  if (pe_data (obfd) != NULL
378
1
      && pe_data (ibfd) != NULL
379
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
1
  return true;
389
1
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
4
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
4
  if (pe_data (obfd) != NULL
378
4
      && pe_data (ibfd) != NULL
379
4
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
4
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
4
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
4
  return true;
389
4
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
10
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
10
  if (pe_data (obfd) != NULL
378
10
      && pe_data (ibfd) != NULL
379
10
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
10
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
10
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
10
  return true;
389
10
}
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
2
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
2
  if (pe_data (obfd) != NULL
378
2
      && pe_data (ibfd) != NULL
379
2
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
2
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
2
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
2
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
2
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
7
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
7
  if (pe_data (obfd) != NULL
378
7
      && pe_data (ibfd) != NULL
379
7
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
6
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
7
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
7
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
7
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
7
}
Unexecuted instantiation: pei-mcore.c:pe_bfd_copy_private_bfd_data
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
2
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
2
  if (pe_data (obfd) != NULL
378
2
      && pe_data (ibfd) != NULL
379
2
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
2
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
2
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
2
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
2
  return true;
389
2
}
390
391
#define coff_bfd_copy_private_section_data \
392
  _bfd_XX_bfd_copy_private_section_data
393
394
#define coff_get_symbol_info _bfd_XX_get_symbol_info
395
396
#ifdef COFF_IMAGE_WITH_PE
397

398
/* Code to handle Microsoft's Import Library Format.
399
   Also known as LINK6 format.
400
   Documentation about this format can be found at:
401
402
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
403
404
/* The following constants specify the sizes of the various data
405
   structures that we have to create in order to build a bfd describing
406
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
407
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
408
   need a padding byte in order to ensure 16 bit alignment for the section's
409
   contents.
410
411
   The value for SIZEOF_ILF_STRINGS is computed as follows:
412
413
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
414
      per symbol for their names (longest section name is .idata$x).
415
416
      There will be two symbols for the imported value, one the symbol name
417
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
418
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
419
420
      The strings in the string table must start STRING__SIZE_SIZE bytes into
421
      the table in order to for the string lookup code in coffgen/coffcode to
422
      work.  */
423
2.41k
#define NUM_ILF_RELOCS    8
424
8.04k
#define NUM_ILF_SECTIONS  6
425
6.03k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
426
427
1.20k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
428
1.20k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
429
1.20k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
430
1.20k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
431
1.20k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
432
1.20k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
433
1.20k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
434
1.20k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
435
1.20k
          + 21 + strlen (source_dll)   \
436
1.20k
          + NUM_ILF_SECTIONS * 9       \
437
1.20k
          + STRING_SIZE_SIZE)
438
804
#define SIZEOF_IDATA2   (5 * 4)
439
440
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
441
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
442
321
#define SIZEOF_IDATA4   (2 * 4)
443
321
#define SIZEOF_IDATA5   (2 * 4)
444
#else
445
885
#define SIZEOF_IDATA4   (1 * 4)
446
885
#define SIZEOF_IDATA5   (1 * 4)
447
#endif
448
449
1.10k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
450
804
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
451
804
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
452
804
         * sizeof (struct coff_section_tdata))
453
454
#define ILF_DATA_SIZE       \
455
804
    + SIZEOF_ILF_SYMS        \
456
804
    + SIZEOF_ILF_SYM_TABLE      \
457
804
    + SIZEOF_ILF_NATIVE_SYMS      \
458
804
    + SIZEOF_ILF_SYM_PTR_TABLE      \
459
804
    + SIZEOF_ILF_EXT_SYMS      \
460
804
    + SIZEOF_ILF_RELOCS        \
461
804
    + SIZEOF_ILF_INT_RELOCS      \
462
804
    + SIZEOF_ILF_STRINGS      \
463
804
    + SIZEOF_IDATA2        \
464
804
    + SIZEOF_IDATA4        \
465
804
    + SIZEOF_IDATA5        \
466
804
    + SIZEOF_IDATA6        \
467
804
    + SIZEOF_IDATA7        \
468
804
    + SIZEOF_ILF_SECTIONS      \
469
804
    + MAX_TEXT_SECTION_SIZE
470
471
/* Create an empty relocation against the given symbol.  */
472
473
static void
474
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
475
          bfd_vma     address,
476
          bfd_reloc_code_real_type  reloc,
477
          struct bfd_symbol **  sym,
478
          unsigned int    sym_index)
479
754
{
480
754
  arelent *entry;
481
754
  struct internal_reloc *internal;
482
483
754
  entry = vars->reltab + vars->relcount;
484
754
  internal = vars->int_reltab + vars->relcount;
485
486
754
  entry->address     = address;
487
754
  entry->addend      = 0;
488
754
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
754
  entry->sym_ptr_ptr = sym;
490
491
754
  internal->r_vaddr  = address;
492
754
  internal->r_symndx = sym_index;
493
754
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
754
  vars->relcount ++;
496
497
754
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
754
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
118
{
480
118
  arelent *entry;
481
118
  struct internal_reloc *internal;
482
483
118
  entry = vars->reltab + vars->relcount;
484
118
  internal = vars->int_reltab + vars->relcount;
485
486
118
  entry->address     = address;
487
118
  entry->addend      = 0;
488
118
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
118
  entry->sym_ptr_ptr = sym;
490
491
118
  internal->r_vaddr  = address;
492
118
  internal->r_symndx = sym_index;
493
118
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
118
  vars->relcount ++;
496
497
118
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
118
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
83
{
480
83
  arelent *entry;
481
83
  struct internal_reloc *internal;
482
483
83
  entry = vars->reltab + vars->relcount;
484
83
  internal = vars->int_reltab + vars->relcount;
485
486
83
  entry->address     = address;
487
83
  entry->addend      = 0;
488
83
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
83
  entry->sym_ptr_ptr = sym;
490
491
83
  internal->r_vaddr  = address;
492
83
  internal->r_symndx = sym_index;
493
83
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
83
  vars->relcount ++;
496
497
83
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
83
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
113
{
480
113
  arelent *entry;
481
113
  struct internal_reloc *internal;
482
483
113
  entry = vars->reltab + vars->relcount;
484
113
  internal = vars->int_reltab + vars->relcount;
485
486
113
  entry->address     = address;
487
113
  entry->addend      = 0;
488
113
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
113
  entry->sym_ptr_ptr = sym;
490
491
113
  internal->r_vaddr  = address;
492
113
  internal->r_symndx = sym_index;
493
113
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
113
  vars->relcount ++;
496
497
113
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
113
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
104
{
480
104
  arelent *entry;
481
104
  struct internal_reloc *internal;
482
483
104
  entry = vars->reltab + vars->relcount;
484
104
  internal = vars->int_reltab + vars->relcount;
485
486
104
  entry->address     = address;
487
104
  entry->addend      = 0;
488
104
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
104
  entry->sym_ptr_ptr = sym;
490
491
104
  internal->r_vaddr  = address;
492
104
  internal->r_symndx = sym_index;
493
104
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
104
  vars->relcount ++;
496
497
104
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
104
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
111
{
480
111
  arelent *entry;
481
111
  struct internal_reloc *internal;
482
483
111
  entry = vars->reltab + vars->relcount;
484
111
  internal = vars->int_reltab + vars->relcount;
485
486
111
  entry->address     = address;
487
111
  entry->addend      = 0;
488
111
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
111
  entry->sym_ptr_ptr = sym;
490
491
111
  internal->r_vaddr  = address;
492
111
  internal->r_symndx = sym_index;
493
111
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
111
  vars->relcount ++;
496
497
111
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
111
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
69
{
480
69
  arelent *entry;
481
69
  struct internal_reloc *internal;
482
483
69
  entry = vars->reltab + vars->relcount;
484
69
  internal = vars->int_reltab + vars->relcount;
485
486
69
  entry->address     = address;
487
69
  entry->addend      = 0;
488
69
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
69
  entry->sym_ptr_ptr = sym;
490
491
69
  internal->r_vaddr  = address;
492
69
  internal->r_symndx = sym_index;
493
69
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
69
  vars->relcount ++;
496
497
69
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
69
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
69
{
480
69
  arelent *entry;
481
69
  struct internal_reloc *internal;
482
483
69
  entry = vars->reltab + vars->relcount;
484
69
  internal = vars->int_reltab + vars->relcount;
485
486
69
  entry->address     = address;
487
69
  entry->addend      = 0;
488
69
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
69
  entry->sym_ptr_ptr = sym;
490
491
69
  internal->r_vaddr  = address;
492
69
  internal->r_symndx = sym_index;
493
69
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
69
  vars->relcount ++;
496
497
69
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
69
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
87
{
480
87
  arelent *entry;
481
87
  struct internal_reloc *internal;
482
483
87
  entry = vars->reltab + vars->relcount;
484
87
  internal = vars->int_reltab + vars->relcount;
485
486
87
  entry->address     = address;
487
87
  entry->addend      = 0;
488
87
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
87
  entry->sym_ptr_ptr = sym;
490
491
87
  internal->r_vaddr  = address;
492
87
  internal->r_symndx = sym_index;
493
87
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
87
  vars->relcount ++;
496
497
87
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
87
}
499
500
/* Create an empty relocation against the given section.  */
501
502
static void
503
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
504
         bfd_vma           address,
505
         bfd_reloc_code_real_type  reloc,
506
         asection_ptr        sec)
507
602
{
508
602
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
602
            coff_section_data (vars->abfd, sec)->i);
510
602
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
507
92
{
508
92
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
92
            coff_section_data (vars->abfd, sec)->i);
510
92
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
66
{
508
66
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
66
            coff_section_data (vars->abfd, sec)->i);
510
66
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
88
{
508
88
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
88
            coff_section_data (vars->abfd, sec)->i);
510
88
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
86
{
508
86
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
86
            coff_section_data (vars->abfd, sec)->i);
510
86
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
88
{
508
88
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
88
            coff_section_data (vars->abfd, sec)->i);
510
88
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
507
54
{
508
54
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
54
            coff_section_data (vars->abfd, sec)->i);
510
54
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
507
54
{
508
54
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
54
            coff_section_data (vars->abfd, sec)->i);
510
54
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
507
74
{
508
74
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
74
            coff_section_data (vars->abfd, sec)->i);
510
74
}
511
512
/* Move the queued relocs into the given section.  */
513
514
static void
515
pe_ILF_save_relocs (pe_ILF_vars *vars,
516
        asection_ptr sec)
517
754
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
754
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
754
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
754
  sec->relocation  = vars->reltab;
526
754
  sec->reloc_count = vars->relcount;
527
754
  sec->flags      |= SEC_RELOC;
528
529
754
  vars->reltab     += vars->relcount;
530
754
  vars->int_reltab += vars->relcount;
531
754
  vars->relcount   = 0;
532
533
754
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
754
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
517
118
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
118
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
118
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
118
  sec->relocation  = vars->reltab;
526
118
  sec->reloc_count = vars->relcount;
527
118
  sec->flags      |= SEC_RELOC;
528
529
118
  vars->reltab     += vars->relcount;
530
118
  vars->int_reltab += vars->relcount;
531
118
  vars->relcount   = 0;
532
533
118
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
118
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
517
83
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
83
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
83
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
83
  sec->relocation  = vars->reltab;
526
83
  sec->reloc_count = vars->relcount;
527
83
  sec->flags      |= SEC_RELOC;
528
529
83
  vars->reltab     += vars->relcount;
530
83
  vars->int_reltab += vars->relcount;
531
83
  vars->relcount   = 0;
532
533
83
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
83
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
113
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
113
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
113
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
113
  sec->relocation  = vars->reltab;
526
113
  sec->reloc_count = vars->relcount;
527
113
  sec->flags      |= SEC_RELOC;
528
529
113
  vars->reltab     += vars->relcount;
530
113
  vars->int_reltab += vars->relcount;
531
113
  vars->relcount   = 0;
532
533
113
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
113
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
104
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
104
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
104
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
104
  sec->relocation  = vars->reltab;
526
104
  sec->reloc_count = vars->relcount;
527
104
  sec->flags      |= SEC_RELOC;
528
529
104
  vars->reltab     += vars->relcount;
530
104
  vars->int_reltab += vars->relcount;
531
104
  vars->relcount   = 0;
532
533
104
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
104
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
517
111
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
111
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
111
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
111
  sec->relocation  = vars->reltab;
526
111
  sec->reloc_count = vars->relcount;
527
111
  sec->flags      |= SEC_RELOC;
528
529
111
  vars->reltab     += vars->relcount;
530
111
  vars->int_reltab += vars->relcount;
531
111
  vars->relcount   = 0;
532
533
111
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
111
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
517
69
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
69
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
69
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
69
  sec->relocation  = vars->reltab;
526
69
  sec->reloc_count = vars->relcount;
527
69
  sec->flags      |= SEC_RELOC;
528
529
69
  vars->reltab     += vars->relcount;
530
69
  vars->int_reltab += vars->relcount;
531
69
  vars->relcount   = 0;
532
533
69
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
69
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
517
69
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
69
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
69
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
69
  sec->relocation  = vars->reltab;
526
69
  sec->reloc_count = vars->relcount;
527
69
  sec->flags      |= SEC_RELOC;
528
529
69
  vars->reltab     += vars->relcount;
530
69
  vars->int_reltab += vars->relcount;
531
69
  vars->relcount   = 0;
532
533
69
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
69
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
517
87
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
87
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
87
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
87
  sec->relocation  = vars->reltab;
526
87
  sec->reloc_count = vars->relcount;
527
87
  sec->flags      |= SEC_RELOC;
528
529
87
  vars->reltab     += vars->relcount;
530
87
  vars->int_reltab += vars->relcount;
531
87
  vars->relcount   = 0;
532
533
87
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
87
}
535
536
/* Create a global symbol and add it to the relevant tables.  */
537
538
static void
539
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
540
          const char *   prefix,
541
          const char *   symbol_name,
542
          asection_ptr   section,
543
          flagword       extra_flags)
544
2.29k
{
545
2.29k
  coff_symbol_type *sym;
546
2.29k
  combined_entry_type *ent;
547
2.29k
  SYMENT *esym;
548
2.29k
  unsigned short sclass;
549
550
2.29k
  if (extra_flags & BSF_LOCAL)
551
1.25k
    sclass = C_STAT;
552
1.03k
  else
553
1.03k
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
418
  if (vars->magic == THUMBPEMAGIC)
557
194
    {
558
194
      if (extra_flags & BSF_FUNCTION)
559
14
  sclass = C_THUMBEXTFUNC;
560
180
      else if (extra_flags & BSF_LOCAL)
561
106
  sclass = C_THUMBSTAT;
562
74
      else
563
74
  sclass = C_THUMBEXT;
564
194
    }
565
#endif
566
567
2.29k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
2.29k
  sym = vars->sym_ptr;
570
2.29k
  ent = vars->native_ptr;
571
2.29k
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
2.29k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
2.29k
  if (section == NULL)
577
382
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
2.29k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
2.29k
      esym->e.e.e_offset);
582
2.29k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
2.29k
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
2.29k
  ent->u.syment.n_sclass    = sclass;
590
2.29k
  ent->u.syment.n_scnum     = section->target_index;
591
2.29k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
2.29k
  ent->is_sym = true;
593
594
2.29k
  sym->symbol.the_bfd = vars->abfd;
595
2.29k
  sym->symbol.name    = vars->string_ptr;
596
2.29k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
2.29k
  sym->symbol.section = section;
598
2.29k
  sym->native       = ent;
599
600
2.29k
  *vars->table_ptr = vars->sym_index;
601
2.29k
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
2.29k
  vars->sym_index ++;
605
2.29k
  vars->sym_ptr ++;
606
2.29k
  vars->sym_ptr_ptr ++;
607
2.29k
  vars->table_ptr ++;
608
2.29k
  vars->native_ptr ++;
609
2.29k
  vars->esym_ptr ++;
610
2.29k
  vars->string_ptr += len + 1;
611
612
2.29k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
2.29k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
544
332
{
545
332
  coff_symbol_type *sym;
546
332
  combined_entry_type *ent;
547
332
  SYMENT *esym;
548
332
  unsigned short sclass;
549
550
332
  if (extra_flags & BSF_LOCAL)
551
184
    sclass = C_STAT;
552
148
  else
553
148
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
332
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
332
  sym = vars->sym_ptr;
570
332
  ent = vars->native_ptr;
571
332
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
332
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
332
  if (section == NULL)
577
54
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
332
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
332
      esym->e.e.e_offset);
582
332
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
332
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
332
  ent->u.syment.n_sclass    = sclass;
590
332
  ent->u.syment.n_scnum     = section->target_index;
591
332
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
332
  ent->is_sym = true;
593
594
332
  sym->symbol.the_bfd = vars->abfd;
595
332
  sym->symbol.name    = vars->string_ptr;
596
332
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
332
  sym->symbol.section = section;
598
332
  sym->native       = ent;
599
600
332
  *vars->table_ptr = vars->sym_index;
601
332
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
332
  vars->sym_index ++;
605
332
  vars->sym_ptr ++;
606
332
  vars->sym_ptr_ptr ++;
607
332
  vars->table_ptr ++;
608
332
  vars->native_ptr ++;
609
332
  vars->esym_ptr ++;
610
332
  vars->string_ptr += len + 1;
611
612
332
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
332
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
259
{
545
259
  coff_symbol_type *sym;
546
259
  combined_entry_type *ent;
547
259
  SYMENT *esym;
548
259
  unsigned short sclass;
549
550
259
  if (extra_flags & BSF_LOCAL)
551
142
    sclass = C_STAT;
552
117
  else
553
117
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
259
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
259
  sym = vars->sym_ptr;
570
259
  ent = vars->native_ptr;
571
259
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
259
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
259
  if (section == NULL)
577
43
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
259
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
259
      esym->e.e.e_offset);
582
259
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
259
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
259
  ent->u.syment.n_sclass    = sclass;
590
259
  ent->u.syment.n_scnum     = section->target_index;
591
259
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
259
  ent->is_sym = true;
593
594
259
  sym->symbol.the_bfd = vars->abfd;
595
259
  sym->symbol.name    = vars->string_ptr;
596
259
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
259
  sym->symbol.section = section;
598
259
  sym->native       = ent;
599
600
259
  *vars->table_ptr = vars->sym_index;
601
259
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
259
  vars->sym_index ++;
605
259
  vars->sym_ptr ++;
606
259
  vars->sym_ptr_ptr ++;
607
259
  vars->table_ptr ++;
608
259
  vars->native_ptr ++;
609
259
  vars->esym_ptr ++;
610
259
  vars->string_ptr += len + 1;
611
612
259
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
259
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
351
{
545
351
  coff_symbol_type *sym;
546
351
  combined_entry_type *ent;
547
351
  SYMENT *esym;
548
351
  unsigned short sclass;
549
550
351
  if (extra_flags & BSF_LOCAL)
551
191
    sclass = C_STAT;
552
160
  else
553
160
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
351
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
351
  sym = vars->sym_ptr;
570
351
  ent = vars->native_ptr;
571
351
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
351
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
351
  if (section == NULL)
577
59
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
351
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
351
      esym->e.e.e_offset);
582
351
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
351
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
351
  ent->u.syment.n_sclass    = sclass;
590
351
  ent->u.syment.n_scnum     = section->target_index;
591
351
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
351
  ent->is_sym = true;
593
594
351
  sym->symbol.the_bfd = vars->abfd;
595
351
  sym->symbol.name    = vars->string_ptr;
596
351
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
351
  sym->symbol.section = section;
598
351
  sym->native       = ent;
599
600
351
  *vars->table_ptr = vars->sym_index;
601
351
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
351
  vars->sym_index ++;
605
351
  vars->sym_ptr ++;
606
351
  vars->sym_ptr_ptr ++;
607
351
  vars->table_ptr ++;
608
351
  vars->native_ptr ++;
609
351
  vars->esym_ptr ++;
610
351
  vars->string_ptr += len + 1;
611
612
351
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
351
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
301
{
545
301
  coff_symbol_type *sym;
546
301
  combined_entry_type *ent;
547
301
  SYMENT *esym;
548
301
  unsigned short sclass;
549
550
301
  if (extra_flags & BSF_LOCAL)
551
167
    sclass = C_STAT;
552
134
  else
553
134
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
301
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
301
  sym = vars->sym_ptr;
570
301
  ent = vars->native_ptr;
571
301
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
301
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
301
  if (section == NULL)
577
51
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
301
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
301
      esym->e.e.e_offset);
582
301
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
301
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
301
  ent->u.syment.n_sclass    = sclass;
590
301
  ent->u.syment.n_scnum     = section->target_index;
591
301
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
301
  ent->is_sym = true;
593
594
301
  sym->symbol.the_bfd = vars->abfd;
595
301
  sym->symbol.name    = vars->string_ptr;
596
301
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
301
  sym->symbol.section = section;
598
301
  sym->native       = ent;
599
600
301
  *vars->table_ptr = vars->sym_index;
601
301
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
301
  vars->sym_index ++;
605
301
  vars->sym_ptr ++;
606
301
  vars->sym_ptr_ptr ++;
607
301
  vars->table_ptr ++;
608
301
  vars->native_ptr ++;
609
301
  vars->esym_ptr ++;
610
301
  vars->string_ptr += len + 1;
611
612
301
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
301
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
360
{
545
360
  coff_symbol_type *sym;
546
360
  combined_entry_type *ent;
547
360
  SYMENT *esym;
548
360
  unsigned short sclass;
549
550
360
  if (extra_flags & BSF_LOCAL)
551
193
    sclass = C_STAT;
552
167
  else
553
167
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
360
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
360
  sym = vars->sym_ptr;
570
360
  ent = vars->native_ptr;
571
360
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
360
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
360
  if (section == NULL)
577
60
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
360
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
360
      esym->e.e.e_offset);
582
360
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
360
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
360
  ent->u.syment.n_sclass    = sclass;
590
360
  ent->u.syment.n_scnum     = section->target_index;
591
360
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
360
  ent->is_sym = true;
593
594
360
  sym->symbol.the_bfd = vars->abfd;
595
360
  sym->symbol.name    = vars->string_ptr;
596
360
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
360
  sym->symbol.section = section;
598
360
  sym->native       = ent;
599
600
360
  *vars->table_ptr = vars->sym_index;
601
360
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
360
  vars->sym_index ++;
605
360
  vars->sym_ptr ++;
606
360
  vars->sym_ptr_ptr ++;
607
360
  vars->table_ptr ++;
608
360
  vars->native_ptr ++;
609
360
  vars->esym_ptr ++;
610
360
  vars->string_ptr += len + 1;
611
612
360
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
360
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
544
209
{
545
209
  coff_symbol_type *sym;
546
209
  combined_entry_type *ent;
547
209
  SYMENT *esym;
548
209
  unsigned short sclass;
549
550
209
  if (extra_flags & BSF_LOCAL)
551
116
    sclass = C_STAT;
552
93
  else
553
93
    sclass = C_EXT;
554
555
209
#ifdef THUMBPEMAGIC
556
209
  if (vars->magic == THUMBPEMAGIC)
557
97
    {
558
97
      if (extra_flags & BSF_FUNCTION)
559
7
  sclass = C_THUMBEXTFUNC;
560
90
      else if (extra_flags & BSF_LOCAL)
561
53
  sclass = C_THUMBSTAT;
562
37
      else
563
37
  sclass = C_THUMBEXT;
564
97
    }
565
209
#endif
566
567
209
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
209
  sym = vars->sym_ptr;
570
209
  ent = vars->native_ptr;
571
209
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
209
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
209
  if (section == NULL)
577
34
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
209
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
209
      esym->e.e.e_offset);
582
209
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
209
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
209
  ent->u.syment.n_sclass    = sclass;
590
209
  ent->u.syment.n_scnum     = section->target_index;
591
209
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
209
  ent->is_sym = true;
593
594
209
  sym->symbol.the_bfd = vars->abfd;
595
209
  sym->symbol.name    = vars->string_ptr;
596
209
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
209
  sym->symbol.section = section;
598
209
  sym->native       = ent;
599
600
209
  *vars->table_ptr = vars->sym_index;
601
209
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
209
  vars->sym_index ++;
605
209
  vars->sym_ptr ++;
606
209
  vars->sym_ptr_ptr ++;
607
209
  vars->table_ptr ++;
608
209
  vars->native_ptr ++;
609
209
  vars->esym_ptr ++;
610
209
  vars->string_ptr += len + 1;
611
612
209
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
209
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
544
209
{
545
209
  coff_symbol_type *sym;
546
209
  combined_entry_type *ent;
547
209
  SYMENT *esym;
548
209
  unsigned short sclass;
549
550
209
  if (extra_flags & BSF_LOCAL)
551
116
    sclass = C_STAT;
552
93
  else
553
93
    sclass = C_EXT;
554
555
209
#ifdef THUMBPEMAGIC
556
209
  if (vars->magic == THUMBPEMAGIC)
557
97
    {
558
97
      if (extra_flags & BSF_FUNCTION)
559
7
  sclass = C_THUMBEXTFUNC;
560
90
      else if (extra_flags & BSF_LOCAL)
561
53
  sclass = C_THUMBSTAT;
562
37
      else
563
37
  sclass = C_THUMBEXT;
564
97
    }
565
209
#endif
566
567
209
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
209
  sym = vars->sym_ptr;
570
209
  ent = vars->native_ptr;
571
209
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
209
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
209
  if (section == NULL)
577
34
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
209
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
209
      esym->e.e.e_offset);
582
209
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
209
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
209
  ent->u.syment.n_sclass    = sclass;
590
209
  ent->u.syment.n_scnum     = section->target_index;
591
209
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
209
  ent->is_sym = true;
593
594
209
  sym->symbol.the_bfd = vars->abfd;
595
209
  sym->symbol.name    = vars->string_ptr;
596
209
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
209
  sym->symbol.section = section;
598
209
  sym->native       = ent;
599
600
209
  *vars->table_ptr = vars->sym_index;
601
209
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
209
  vars->sym_index ++;
605
209
  vars->sym_ptr ++;
606
209
  vars->sym_ptr_ptr ++;
607
209
  vars->table_ptr ++;
608
209
  vars->native_ptr ++;
609
209
  vars->esym_ptr ++;
610
209
  vars->string_ptr += len + 1;
611
612
209
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
209
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
544
271
{
545
271
  coff_symbol_type *sym;
546
271
  combined_entry_type *ent;
547
271
  SYMENT *esym;
548
271
  unsigned short sclass;
549
550
271
  if (extra_flags & BSF_LOCAL)
551
148
    sclass = C_STAT;
552
123
  else
553
123
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
271
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
271
  sym = vars->sym_ptr;
570
271
  ent = vars->native_ptr;
571
271
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
271
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
271
  if (section == NULL)
577
47
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
271
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
271
      esym->e.e.e_offset);
582
271
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
271
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
271
  ent->u.syment.n_sclass    = sclass;
590
271
  ent->u.syment.n_scnum     = section->target_index;
591
271
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
271
  ent->is_sym = true;
593
594
271
  sym->symbol.the_bfd = vars->abfd;
595
271
  sym->symbol.name    = vars->string_ptr;
596
271
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
271
  sym->symbol.section = section;
598
271
  sym->native       = ent;
599
600
271
  *vars->table_ptr = vars->sym_index;
601
271
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
271
  vars->sym_index ++;
605
271
  vars->sym_ptr ++;
606
271
  vars->sym_ptr_ptr ++;
607
271
  vars->table_ptr ++;
608
271
  vars->native_ptr ++;
609
271
  vars->esym_ptr ++;
610
271
  vars->string_ptr += len + 1;
611
612
271
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
271
}
614
615
/* Create a section.  */
616
617
static asection_ptr
618
pe_ILF_make_a_section (pe_ILF_vars * vars,
619
           const char *  name,
620
           unsigned int  size,
621
           flagword      extra_flags)
622
1.25k
{
623
1.25k
  asection_ptr sec;
624
1.25k
  flagword     flags;
625
1.25k
  intptr_t alignment;
626
627
1.25k
  sec = bfd_make_section_old_way (vars->abfd, name);
628
1.25k
  if (sec == NULL)
629
0
    return NULL;
630
631
1.25k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
1.25k
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
1.25k
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
1.25k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
1.25k
  bfd_set_section_size (sec, (bfd_size_type) size);
643
1.25k
  sec->contents = vars->data;
644
1.25k
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
1.25k
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
1.25k
  if (size & 1)
654
137
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
1.25k
#if GCC_VERSION >= 3000
661
1.25k
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
1.25k
  vars->data
666
1.25k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
1.25k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
1.25k
  vars->data += sizeof (struct coff_section_tdata);
671
672
1.25k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
1.25k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
1.25k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
1.25k
  return sec;
681
1.25k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
622
184
{
623
184
  asection_ptr sec;
624
184
  flagword     flags;
625
184
  intptr_t alignment;
626
627
184
  sec = bfd_make_section_old_way (vars->abfd, name);
628
184
  if (sec == NULL)
629
0
    return NULL;
630
631
184
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
184
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
184
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
184
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
184
  bfd_set_section_size (sec, (bfd_size_type) size);
643
184
  sec->contents = vars->data;
644
184
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
184
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
184
  if (size & 1)
654
18
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
184
#if GCC_VERSION >= 3000
661
184
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
184
  vars->data
666
184
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
184
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
184
  vars->data += sizeof (struct coff_section_tdata);
671
672
184
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
184
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
184
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
184
  return sec;
681
184
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
622
142
{
623
142
  asection_ptr sec;
624
142
  flagword     flags;
625
142
  intptr_t alignment;
626
627
142
  sec = bfd_make_section_old_way (vars->abfd, name);
628
142
  if (sec == NULL)
629
0
    return NULL;
630
631
142
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
142
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
142
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
142
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
142
  bfd_set_section_size (sec, (bfd_size_type) size);
643
142
  sec->contents = vars->data;
644
142
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
142
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
142
  if (size & 1)
654
21
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
142
#if GCC_VERSION >= 3000
661
142
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
142
  vars->data
666
142
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
142
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
142
  vars->data += sizeof (struct coff_section_tdata);
671
672
142
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
142
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
142
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
142
  return sec;
681
142
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
191
{
623
191
  asection_ptr sec;
624
191
  flagword     flags;
625
191
  intptr_t alignment;
626
627
191
  sec = bfd_make_section_old_way (vars->abfd, name);
628
191
  if (sec == NULL)
629
0
    return NULL;
630
631
191
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
191
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
191
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
191
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
191
  bfd_set_section_size (sec, (bfd_size_type) size);
643
191
  sec->contents = vars->data;
644
191
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
191
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
191
  if (size & 1)
654
26
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
191
#if GCC_VERSION >= 3000
661
191
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
191
  vars->data
666
191
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
191
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
191
  vars->data += sizeof (struct coff_section_tdata);
671
672
191
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
191
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
191
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
191
  return sec;
681
191
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
167
{
623
167
  asection_ptr sec;
624
167
  flagword     flags;
625
167
  intptr_t alignment;
626
627
167
  sec = bfd_make_section_old_way (vars->abfd, name);
628
167
  if (sec == NULL)
629
0
    return NULL;
630
631
167
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
167
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
167
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
167
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
167
  bfd_set_section_size (sec, (bfd_size_type) size);
643
167
  sec->contents = vars->data;
644
167
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
167
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
167
  if (size & 1)
654
23
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
167
#if GCC_VERSION >= 3000
661
167
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
167
  vars->data
666
167
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
167
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
167
  vars->data += sizeof (struct coff_section_tdata);
671
672
167
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
167
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
167
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
167
  return sec;
681
167
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
622
193
{
623
193
  asection_ptr sec;
624
193
  flagword     flags;
625
193
  intptr_t alignment;
626
627
193
  sec = bfd_make_section_old_way (vars->abfd, name);
628
193
  if (sec == NULL)
629
0
    return NULL;
630
631
193
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
193
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
193
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
193
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
193
  bfd_set_section_size (sec, (bfd_size_type) size);
643
193
  sec->contents = vars->data;
644
193
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
193
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
193
  if (size & 1)
654
15
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
193
#if GCC_VERSION >= 3000
661
193
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
193
  vars->data
666
193
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
193
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
193
  vars->data += sizeof (struct coff_section_tdata);
671
672
193
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
193
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
193
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
193
  return sec;
681
193
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
622
116
{
623
116
  asection_ptr sec;
624
116
  flagword     flags;
625
116
  intptr_t alignment;
626
627
116
  sec = bfd_make_section_old_way (vars->abfd, name);
628
116
  if (sec == NULL)
629
0
    return NULL;
630
631
116
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
116
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
116
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
116
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
116
  bfd_set_section_size (sec, (bfd_size_type) size);
643
116
  sec->contents = vars->data;
644
116
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
116
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
116
  if (size & 1)
654
12
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
116
#if GCC_VERSION >= 3000
661
116
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
116
  vars->data
666
116
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
116
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
116
  vars->data += sizeof (struct coff_section_tdata);
671
672
116
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
116
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
116
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
116
  return sec;
681
116
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
622
116
{
623
116
  asection_ptr sec;
624
116
  flagword     flags;
625
116
  intptr_t alignment;
626
627
116
  sec = bfd_make_section_old_way (vars->abfd, name);
628
116
  if (sec == NULL)
629
0
    return NULL;
630
631
116
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
116
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
116
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
116
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
116
  bfd_set_section_size (sec, (bfd_size_type) size);
643
116
  sec->contents = vars->data;
644
116
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
116
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
116
  if (size & 1)
654
12
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
116
#if GCC_VERSION >= 3000
661
116
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
116
  vars->data
666
116
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
116
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
116
  vars->data += sizeof (struct coff_section_tdata);
671
672
116
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
116
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
116
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
116
  return sec;
681
116
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
622
148
{
623
148
  asection_ptr sec;
624
148
  flagword     flags;
625
148
  intptr_t alignment;
626
627
148
  sec = bfd_make_section_old_way (vars->abfd, name);
628
148
  if (sec == NULL)
629
0
    return NULL;
630
631
148
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
148
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
148
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
148
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
148
  bfd_set_section_size (sec, (bfd_size_type) size);
643
148
  sec->contents = vars->data;
644
148
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
148
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
148
  if (size & 1)
654
10
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
148
#if GCC_VERSION >= 3000
661
148
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
148
  vars->data
666
148
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
148
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
148
  vars->data += sizeof (struct coff_section_tdata);
671
672
148
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
148
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
148
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
148
  return sec;
681
148
}
682
683
/* This structure contains the code that goes into the .text section
684
   in order to perform a jump into the DLL lookup table.  The entries
685
   in the table are index by the magic number used to represent the
686
   machine type in the PE file.  The contents of the data[] arrays in
687
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
688
   The SIZE field says how many bytes in the DATA array are actually
689
   used.  The OFFSET field says where in the data array the address
690
   of the .idata$5 section should be placed.  */
691
804
#define MAX_TEXT_SECTION_SIZE 32
692
693
typedef struct
694
{
695
  unsigned short magic;
696
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
697
  unsigned int   size;
698
  unsigned int   offset;
699
}
700
jump_table;
701
702
static const jump_table jtab[] =
703
{
704
#ifdef I386MAGIC
705
  { I386MAGIC,
706
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
707
    8, 2
708
  },
709
#endif
710
711
#ifdef AMD64MAGIC
712
  { AMD64MAGIC,
713
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
714
    8, 2
715
  },
716
#endif
717
718
#ifdef  MC68MAGIC
719
  { MC68MAGIC,
720
    { /* XXX fill me in */ },
721
    0, 0
722
  },
723
#endif
724
725
#ifdef  MIPS_ARCH_MAGIC_WINCE
726
  { MIPS_ARCH_MAGIC_WINCE,
727
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
728
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
729
    16, 0
730
  },
731
#endif
732
733
#ifdef  SH_ARCH_MAGIC_WINCE
734
  { SH_ARCH_MAGIC_WINCE,
735
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
736
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
737
    12, 8
738
  },
739
#endif
740
741
#ifdef AARCH64MAGIC
742
/* We don't currently support jumping to DLLs, so if
743
   someone does try emit a runtime trap.  Through UDF #0.  */
744
  { AARCH64MAGIC,
745
    { 0x00, 0x00, 0x00, 0x00 },
746
    4, 0
747
  },
748
749
#endif
750
751
#ifdef  ARMPEMAGIC
752
  { ARMPEMAGIC,
753
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
754
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
755
    12, 8
756
  },
757
#endif
758
759
#ifdef  THUMBPEMAGIC
760
  { THUMBPEMAGIC,
761
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
762
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
763
    16, 12
764
  },
765
#endif
766
767
#ifdef LOONGARCH64MAGIC
768
/* We don't currently support jumping to DLLs, so if
769
   someone does try emit a runtime trap.  Through BREAK 0.  */
770
  { LOONGARCH64MAGIC,
771
    { 0x00, 0x00, 0x2a, 0x00 },
772
    4, 0
773
  },
774
775
#endif
776
777
#ifdef RISCV64MAGIC
778
  /* We don't currently support jumping to DLLs, so if
779
     someone does try emit a runtime trap.  Through EBREAK.  */
780
  { RISCV64MAGIC,
781
    { 0x73, 0x00, 0x10, 0x00 },
782
    4, 0
783
  },
784
785
#endif
786
787
  { 0, { 0 }, 0, 0 }
788
};
789
790
#ifndef NUM_ENTRIES
791
152
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
792
#endif
793
794
/* Build a full BFD from the information supplied in a ILF object.  */
795
796
static bool
797
pe_ILF_build_a_bfd (bfd *     abfd,
798
        unsigned int    magic,
799
        char *      symbol_name,
800
        char *      source_dll,
801
        unsigned int    ordinal,
802
        unsigned int    types,
803
        char *      import_name)
804
475
{
805
475
  bfd_byte *       ptr;
806
475
  pe_ILF_vars      vars;
807
475
  struct internal_filehdr  internal_f;
808
475
  unsigned int       import_type;
809
475
  unsigned int       import_name_type;
810
475
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
475
  coff_symbol_type **    imp_sym;
812
475
  unsigned int       imp_index;
813
475
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
475
  import_type = types & 0x3;
817
475
  import_name_type = (types & 0x1c) >> 2;
818
819
475
  switch (import_type)
820
475
    {
821
191
    case IMPORT_CODE:
822
314
    case IMPORT_DATA:
823
452
    case IMPORT_CONST:
824
452
      break;
825
826
23
    default:
827
      /* xgettext:c-format */
828
23
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
23
        abfd, import_type);
830
23
      return false;
831
475
    }
832
833
452
  switch (import_name_type)
834
452
    {
835
101
    case IMPORT_ORDINAL:
836
141
    case IMPORT_NAME:
837
224
    case IMPORT_NAME_NOPREFIX:
838
356
    case IMPORT_NAME_UNDECORATE:
839
356
      import_name = symbol_name;
840
356
      break;
841
842
78
    case IMPORT_NAME_EXPORTAS:
843
78
      if (!import_name || !import_name[0])
844
32
  {
845
32
    _bfd_error_handler (_("%pB: missing import name for "
846
32
        "IMPORT_NAME_EXPORTAS for %s"),
847
32
            abfd, symbol_name);
848
32
    return false;
849
32
  }
850
46
      break;
851
852
46
    default:
853
      /* xgettext:c-format */
854
18
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
18
        abfd, import_name_type);
856
18
      return false;
857
452
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
402
  vars.bim
867
402
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
402
  if (vars.bim == NULL)
869
0
    return false;
870
871
402
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
402
  vars.bim->buffer = ptr;
873
402
  vars.bim->size   = ILF_DATA_SIZE;
874
402
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
402
  vars.sym_cache = (coff_symbol_type *) ptr;
880
402
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
402
  vars.sym_index = 0;
882
402
  ptr += SIZEOF_ILF_SYMS;
883
884
402
  vars.sym_table = (unsigned int *) ptr;
885
402
  vars.table_ptr = (unsigned int *) ptr;
886
402
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
402
  vars.native_syms = (combined_entry_type *) ptr;
889
402
  vars.native_ptr  = (combined_entry_type *) ptr;
890
402
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
402
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
402
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
402
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
402
  vars.esym_table = (SYMENT *) ptr;
897
402
  vars.esym_ptr   = (SYMENT *) ptr;
898
402
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
402
  vars.reltab   = (arelent *) ptr;
901
402
  vars.relcount = 0;
902
402
  ptr += SIZEOF_ILF_RELOCS;
903
904
402
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
402
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
402
  vars.string_table = (char *) ptr;
908
402
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
402
  ptr += SIZEOF_ILF_STRINGS;
910
402
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
402
#if GCC_VERSION >= 3000
920
402
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
402
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
402
  vars.data = ptr;
927
402
  vars.abfd = abfd;
928
402
  vars.sec_index = 0;
929
402
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
402
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
402
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
402
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
402
  if (import_name_type == IMPORT_ORDINAL)
945
101
    {
946
101
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
20
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
49
      ((unsigned int *) id4->contents)[0] = ordinal;
953
49
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
49
      ((unsigned int *) id5->contents)[0] = ordinal;
955
49
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
32
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
32
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
32
#endif
960
32
    }
961
301
  else
962
301
    {
963
301
      char *symbol;
964
301
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
301
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
301
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
301
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
301
      if (import_name_type != IMPORT_NAME
982
261
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
215
  {
984
215
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
215
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
205
        || c == '@' || c == '?')
990
69
      symbol++;
991
215
  }
992
993
301
      len = strlen (symbol);
994
301
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
132
  {
996
    /* Truncate at the first '@'.  */
997
132
    char *at = strchr (symbol, '@');
998
999
132
    if (at != NULL)
1000
35
      len = at - symbol;
1001
132
  }
1002
1003
301
      id6->contents[0] = ordinal & 0xff;
1004
301
      id6->contents[1] = ordinal >> 8;
1005
1006
301
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
301
      id6->contents[len + 2] = '\0';
1008
301
    }
1009
1010
382
  if (import_name_type != IMPORT_ORDINAL)
1011
301
    {
1012
301
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
301
      pe_ILF_save_relocs (&vars, id4);
1014
1015
301
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
301
      pe_ILF_save_relocs (&vars, id5);
1017
301
    }
1018
1019
  /* Create an import symbol.  */
1020
382
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
382
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
382
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
382
  switch (import_type)
1027
382
    {
1028
0
      int i;
1029
1030
152
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
320
      for (i = NUM_ENTRIES (jtab); i--;)
1035
320
  {
1036
320
    if (jtab[i].size == 0)
1037
152
      continue;
1038
168
    if (jtab[i].magic == magic)
1039
152
      break;
1040
168
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
152
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
152
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
152
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
152
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
17
      if (magic == AMD64MAGIC)
1069
17
  {
1070
17
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
17
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
17
              imp_index);
1073
17
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
152
      pe_ILF_save_relocs (&vars, text);
1081
152
      break;
1082
1083
111
    case IMPORT_DATA:
1084
230
    case IMPORT_CONST:
1085
230
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
382
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
382
  switch (import_type)
1094
382
    {
1095
152
    case IMPORT_CODE:
1096
152
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
152
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
152
      break;
1100
1101
111
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
111
      break;
1104
1105
119
    case IMPORT_CONST:
1106
119
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
119
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
382
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
382
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
382
  if (ptr)
1117
55
    *ptr = 0;
1118
382
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
382
  if (ptr)
1120
55
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
382
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
382
  internal_f.f_magic  = magic;
1126
382
  internal_f.f_symptr = 0;
1127
382
  internal_f.f_nsyms  = 0;
1128
382
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
382
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
382
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
382
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
382
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
68
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
32
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
382
  bfd_cache_close (abfd);
1147
1148
382
  abfd->iostream = (void *) vars.bim;
1149
382
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
382
  abfd->iovec = &_bfd_memory_iovec;
1151
382
  abfd->where = 0;
1152
382
  abfd->origin = 0;
1153
382
  abfd->size = 0;
1154
382
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
382
  obj_symbols (abfd) = vars.sym_cache;
1158
382
  abfd->symcount = vars.sym_index;
1159
1160
382
  obj_raw_syments (abfd) = vars.native_syms;
1161
382
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
382
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
382
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
382
  obj_coff_keep_syms (abfd) = true;
1166
1167
382
  obj_convert (abfd) = vars.sym_table;
1168
382
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
382
  obj_coff_strings (abfd) = vars.string_table;
1171
382
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
382
  obj_coff_keep_strings (abfd) = true;
1173
1174
382
  return true;
1175
1176
20
 error_return:
1177
20
  free (vars.bim->buffer);
1178
20
  free (vars.bim);
1179
20
  return false;
1180
382
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
804
65
{
805
65
  bfd_byte *       ptr;
806
65
  pe_ILF_vars      vars;
807
65
  struct internal_filehdr  internal_f;
808
65
  unsigned int       import_type;
809
65
  unsigned int       import_name_type;
810
65
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
65
  coff_symbol_type **    imp_sym;
812
65
  unsigned int       imp_index;
813
65
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
65
  import_type = types & 0x3;
817
65
  import_name_type = (types & 0x1c) >> 2;
818
819
65
  switch (import_type)
820
65
    {
821
28
    case IMPORT_CODE:
822
43
    case IMPORT_DATA:
823
63
    case IMPORT_CONST:
824
63
      break;
825
826
2
    default:
827
      /* xgettext:c-format */
828
2
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
2
        abfd, import_type);
830
2
      return false;
831
65
    }
832
833
63
  switch (import_name_type)
834
63
    {
835
10
    case IMPORT_ORDINAL:
836
14
    case IMPORT_NAME:
837
34
    case IMPORT_NAME_NOPREFIX:
838
44
    case IMPORT_NAME_UNDECORATE:
839
44
      import_name = symbol_name;
840
44
      break;
841
842
16
    case IMPORT_NAME_EXPORTAS:
843
16
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
12
      break;
851
852
12
    default:
853
      /* xgettext:c-format */
854
3
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
3
        abfd, import_name_type);
856
3
      return false;
857
63
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
56
  vars.bim
867
56
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
56
  if (vars.bim == NULL)
869
0
    return false;
870
871
56
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
56
  vars.bim->buffer = ptr;
873
56
  vars.bim->size   = ILF_DATA_SIZE;
874
56
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
56
  vars.sym_cache = (coff_symbol_type *) ptr;
880
56
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
56
  vars.sym_index = 0;
882
56
  ptr += SIZEOF_ILF_SYMS;
883
884
56
  vars.sym_table = (unsigned int *) ptr;
885
56
  vars.table_ptr = (unsigned int *) ptr;
886
56
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
56
  vars.native_syms = (combined_entry_type *) ptr;
889
56
  vars.native_ptr  = (combined_entry_type *) ptr;
890
56
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
56
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
56
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
56
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
56
  vars.esym_table = (SYMENT *) ptr;
897
56
  vars.esym_ptr   = (SYMENT *) ptr;
898
56
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
56
  vars.reltab   = (arelent *) ptr;
901
56
  vars.relcount = 0;
902
56
  ptr += SIZEOF_ILF_RELOCS;
903
904
56
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
56
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
56
  vars.string_table = (char *) ptr;
908
56
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
56
  ptr += SIZEOF_ILF_STRINGS;
910
56
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
56
#if GCC_VERSION >= 3000
920
56
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
56
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
56
  vars.data = ptr;
927
56
  vars.abfd = abfd;
928
56
  vars.sec_index = 0;
929
56
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
56
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
56
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
56
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
56
  if (import_name_type == IMPORT_ORDINAL)
945
10
    {
946
10
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
2
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
8
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
8
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
8
#endif
960
8
    }
961
46
  else
962
46
    {
963
46
      char *symbol;
964
46
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
46
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
46
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
46
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
46
      if (import_name_type != IMPORT_NAME
982
42
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
30
  {
984
30
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
30
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
26
        || c == '@' || c == '?')
990
12
      symbol++;
991
30
  }
992
993
46
      len = strlen (symbol);
994
46
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
10
  {
996
    /* Truncate at the first '@'.  */
997
10
    char *at = strchr (symbol, '@');
998
999
10
    if (at != NULL)
1000
4
      len = at - symbol;
1001
10
  }
1002
1003
46
      id6->contents[0] = ordinal & 0xff;
1004
46
      id6->contents[1] = ordinal >> 8;
1005
1006
46
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
46
      id6->contents[len + 2] = '\0';
1008
46
    }
1009
1010
54
  if (import_name_type != IMPORT_ORDINAL)
1011
46
    {
1012
46
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
46
      pe_ILF_save_relocs (&vars, id4);
1014
1015
46
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
46
      pe_ILF_save_relocs (&vars, id5);
1017
46
    }
1018
1019
  /* Create an import symbol.  */
1020
54
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
54
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
54
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
54
  switch (import_type)
1027
54
    {
1028
0
      int i;
1029
1030
26
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
52
      for (i = NUM_ENTRIES (jtab); i--;)
1035
52
  {
1036
52
    if (jtab[i].size == 0)
1037
26
      continue;
1038
26
    if (jtab[i].magic == magic)
1039
26
      break;
1040
26
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
26
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
26
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
26
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
26
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
26
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
26
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
26
            imp_index);
1079
1080
26
      pe_ILF_save_relocs (&vars, text);
1081
26
      break;
1082
1083
14
    case IMPORT_DATA:
1084
28
    case IMPORT_CONST:
1085
28
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
54
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
54
  switch (import_type)
1094
54
    {
1095
26
    case IMPORT_CODE:
1096
26
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
26
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
26
      break;
1100
1101
14
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
14
      break;
1104
1105
14
    case IMPORT_CONST:
1106
14
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
14
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
54
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
54
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
54
  if (ptr)
1117
10
    *ptr = 0;
1118
54
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
54
  if (ptr)
1120
10
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
54
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
54
  internal_f.f_magic  = magic;
1126
54
  internal_f.f_symptr = 0;
1127
54
  internal_f.f_nsyms  = 0;
1128
54
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
54
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
54
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
54
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
54
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
54
  bfd_cache_close (abfd);
1147
1148
54
  abfd->iostream = (void *) vars.bim;
1149
54
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
54
  abfd->iovec = &_bfd_memory_iovec;
1151
54
  abfd->where = 0;
1152
54
  abfd->origin = 0;
1153
54
  abfd->size = 0;
1154
54
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
54
  obj_symbols (abfd) = vars.sym_cache;
1158
54
  abfd->symcount = vars.sym_index;
1159
1160
54
  obj_raw_syments (abfd) = vars.native_syms;
1161
54
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
54
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
54
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
54
  obj_coff_keep_syms (abfd) = true;
1166
1167
54
  obj_convert (abfd) = vars.sym_table;
1168
54
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
54
  obj_coff_strings (abfd) = vars.string_table;
1171
54
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
54
  obj_coff_keep_strings (abfd) = true;
1173
1174
54
  return true;
1175
1176
2
 error_return:
1177
2
  free (vars.bim->buffer);
1178
2
  free (vars.bim);
1179
  return false;
1180
54
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
54
{
805
54
  bfd_byte *       ptr;
806
54
  pe_ILF_vars      vars;
807
54
  struct internal_filehdr  internal_f;
808
54
  unsigned int       import_type;
809
54
  unsigned int       import_name_type;
810
54
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
54
  coff_symbol_type **    imp_sym;
812
54
  unsigned int       imp_index;
813
54
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
54
  import_type = types & 0x3;
817
54
  import_name_type = (types & 0x1c) >> 2;
818
819
54
  switch (import_type)
820
54
    {
821
22
    case IMPORT_CODE:
822
35
    case IMPORT_DATA:
823
52
    case IMPORT_CONST:
824
52
      break;
825
826
2
    default:
827
      /* xgettext:c-format */
828
2
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
2
        abfd, import_type);
830
2
      return false;
831
54
    }
832
833
52
  switch (import_name_type)
834
52
    {
835
13
    case IMPORT_ORDINAL:
836
19
    case IMPORT_NAME:
837
26
    case IMPORT_NAME_NOPREFIX:
838
42
    case IMPORT_NAME_UNDECORATE:
839
42
      import_name = symbol_name;
840
42
      break;
841
842
8
    case IMPORT_NAME_EXPORTAS:
843
8
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
4
      break;
851
852
4
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
52
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
46
  vars.bim
867
46
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
46
  if (vars.bim == NULL)
869
0
    return false;
870
871
46
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
46
  vars.bim->buffer = ptr;
873
46
  vars.bim->size   = ILF_DATA_SIZE;
874
46
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
46
  vars.sym_cache = (coff_symbol_type *) ptr;
880
46
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
46
  vars.sym_index = 0;
882
46
  ptr += SIZEOF_ILF_SYMS;
883
884
46
  vars.sym_table = (unsigned int *) ptr;
885
46
  vars.table_ptr = (unsigned int *) ptr;
886
46
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
46
  vars.native_syms = (combined_entry_type *) ptr;
889
46
  vars.native_ptr  = (combined_entry_type *) ptr;
890
46
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
46
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
46
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
46
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
46
  vars.esym_table = (SYMENT *) ptr;
897
46
  vars.esym_ptr   = (SYMENT *) ptr;
898
46
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
46
  vars.reltab   = (arelent *) ptr;
901
46
  vars.relcount = 0;
902
46
  ptr += SIZEOF_ILF_RELOCS;
903
904
46
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
46
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
46
  vars.string_table = (char *) ptr;
908
46
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
46
  ptr += SIZEOF_ILF_STRINGS;
910
46
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
46
#if GCC_VERSION >= 3000
920
46
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
46
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
46
  vars.data = ptr;
927
46
  vars.abfd = abfd;
928
46
  vars.sec_index = 0;
929
46
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
46
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
46
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
46
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
46
  if (import_name_type == IMPORT_ORDINAL)
945
13
    {
946
13
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
3
  goto error_return;
949
950
10
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
10
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
10
      ((unsigned int *) id4->contents)[0] = ordinal;
953
10
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
10
      ((unsigned int *) id5->contents)[0] = ordinal;
955
10
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
10
    }
961
33
  else
962
33
    {
963
33
      char *symbol;
964
33
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
33
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
33
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
33
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
33
      if (import_name_type != IMPORT_NAME
982
27
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
23
  {
984
23
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
23
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
23
        || c == '@' || c == '?')
990
8
      symbol++;
991
23
  }
992
993
33
      len = strlen (symbol);
994
33
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
16
  {
996
    /* Truncate at the first '@'.  */
997
16
    char *at = strchr (symbol, '@');
998
999
16
    if (at != NULL)
1000
8
      len = at - symbol;
1001
16
  }
1002
1003
33
      id6->contents[0] = ordinal & 0xff;
1004
33
      id6->contents[1] = ordinal >> 8;
1005
1006
33
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
33
      id6->contents[len + 2] = '\0';
1008
33
    }
1009
1010
43
  if (import_name_type != IMPORT_ORDINAL)
1011
33
    {
1012
33
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
33
      pe_ILF_save_relocs (&vars, id4);
1014
1015
33
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
33
      pe_ILF_save_relocs (&vars, id5);
1017
33
    }
1018
1019
  /* Create an import symbol.  */
1020
43
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
43
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
43
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
43
  switch (import_type)
1027
43
    {
1028
0
      int i;
1029
1030
17
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
34
      for (i = NUM_ENTRIES (jtab); i--;)
1035
34
  {
1036
34
    if (jtab[i].size == 0)
1037
17
      continue;
1038
17
    if (jtab[i].magic == magic)
1039
17
      break;
1040
17
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
17
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
17
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
17
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
17
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
17
#ifdef AMD64MAGIC
1068
17
      if (magic == AMD64MAGIC)
1069
17
  {
1070
17
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
17
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
17
              imp_index);
1073
17
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
17
      pe_ILF_save_relocs (&vars, text);
1081
17
      break;
1082
1083
12
    case IMPORT_DATA:
1084
26
    case IMPORT_CONST:
1085
26
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
43
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
43
  switch (import_type)
1094
43
    {
1095
17
    case IMPORT_CODE:
1096
17
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
17
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
17
      break;
1100
1101
12
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
12
      break;
1104
1105
14
    case IMPORT_CONST:
1106
14
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
14
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
43
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
43
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
43
  if (ptr)
1117
6
    *ptr = 0;
1118
43
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
43
  if (ptr)
1120
6
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
43
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
43
  internal_f.f_magic  = magic;
1126
43
  internal_f.f_symptr = 0;
1127
43
  internal_f.f_nsyms  = 0;
1128
43
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
43
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
43
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
43
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
43
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
43
  bfd_cache_close (abfd);
1147
1148
43
  abfd->iostream = (void *) vars.bim;
1149
43
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
43
  abfd->iovec = &_bfd_memory_iovec;
1151
43
  abfd->where = 0;
1152
43
  abfd->origin = 0;
1153
43
  abfd->size = 0;
1154
43
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
43
  obj_symbols (abfd) = vars.sym_cache;
1158
43
  abfd->symcount = vars.sym_index;
1159
1160
43
  obj_raw_syments (abfd) = vars.native_syms;
1161
43
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
43
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
43
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
43
  obj_coff_keep_syms (abfd) = true;
1166
1167
43
  obj_convert (abfd) = vars.sym_table;
1168
43
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
43
  obj_coff_strings (abfd) = vars.string_table;
1171
43
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
43
  obj_coff_keep_strings (abfd) = true;
1173
1174
43
  return true;
1175
1176
3
 error_return:
1177
3
  free (vars.bim->buffer);
1178
3
  free (vars.bim);
1179
  return false;
1180
43
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
69
{
805
69
  bfd_byte *       ptr;
806
69
  pe_ILF_vars      vars;
807
69
  struct internal_filehdr  internal_f;
808
69
  unsigned int       import_type;
809
69
  unsigned int       import_name_type;
810
69
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
69
  coff_symbol_type **    imp_sym;
812
69
  unsigned int       imp_index;
813
69
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
69
  import_type = types & 0x3;
817
69
  import_name_type = (types & 0x1c) >> 2;
818
819
69
  switch (import_type)
820
69
    {
821
31
    case IMPORT_CODE:
822
49
    case IMPORT_DATA:
823
67
    case IMPORT_CONST:
824
67
      break;
825
826
2
    default:
827
      /* xgettext:c-format */
828
2
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
2
        abfd, import_type);
830
2
      return false;
831
69
    }
832
833
67
  switch (import_name_type)
834
67
    {
835
17
    case IMPORT_ORDINAL:
836
21
    case IMPORT_NAME:
837
31
    case IMPORT_NAME_NOPREFIX:
838
55
    case IMPORT_NAME_UNDECORATE:
839
55
      import_name = symbol_name;
840
55
      break;
841
842
10
    case IMPORT_NAME_EXPORTAS:
843
10
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
6
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
67
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
61
  vars.bim
867
61
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
61
  if (vars.bim == NULL)
869
0
    return false;
870
871
61
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
61
  vars.bim->buffer = ptr;
873
61
  vars.bim->size   = ILF_DATA_SIZE;
874
61
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
61
  vars.sym_cache = (coff_symbol_type *) ptr;
880
61
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
61
  vars.sym_index = 0;
882
61
  ptr += SIZEOF_ILF_SYMS;
883
884
61
  vars.sym_table = (unsigned int *) ptr;
885
61
  vars.table_ptr = (unsigned int *) ptr;
886
61
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
61
  vars.native_syms = (combined_entry_type *) ptr;
889
61
  vars.native_ptr  = (combined_entry_type *) ptr;
890
61
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
61
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
61
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
61
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
61
  vars.esym_table = (SYMENT *) ptr;
897
61
  vars.esym_ptr   = (SYMENT *) ptr;
898
61
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
61
  vars.reltab   = (arelent *) ptr;
901
61
  vars.relcount = 0;
902
61
  ptr += SIZEOF_ILF_RELOCS;
903
904
61
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
61
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
61
  vars.string_table = (char *) ptr;
908
61
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
61
  ptr += SIZEOF_ILF_STRINGS;
910
61
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
61
#if GCC_VERSION >= 3000
920
61
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
61
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
61
  vars.data = ptr;
927
61
  vars.abfd = abfd;
928
61
  vars.sec_index = 0;
929
61
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
61
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
61
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
61
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
61
  if (import_name_type == IMPORT_ORDINAL)
945
17
    {
946
17
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
2
  goto error_return;
949
950
15
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
15
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
15
      ((unsigned int *) id4->contents)[0] = ordinal;
953
15
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
15
      ((unsigned int *) id5->contents)[0] = ordinal;
955
15
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
15
    }
961
44
  else
962
44
    {
963
44
      char *symbol;
964
44
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
44
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
44
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
44
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
44
      if (import_name_type != IMPORT_NAME
982
40
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
34
  {
984
34
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
34
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
34
        || c == '@' || c == '?')
990
9
      symbol++;
991
34
  }
992
993
44
      len = strlen (symbol);
994
44
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
24
  {
996
    /* Truncate at the first '@'.  */
997
24
    char *at = strchr (symbol, '@');
998
999
24
    if (at != NULL)
1000
7
      len = at - symbol;
1001
24
  }
1002
1003
44
      id6->contents[0] = ordinal & 0xff;
1004
44
      id6->contents[1] = ordinal >> 8;
1005
1006
44
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
44
      id6->contents[len + 2] = '\0';
1008
44
    }
1009
1010
59
  if (import_name_type != IMPORT_ORDINAL)
1011
44
    {
1012
44
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
44
      pe_ILF_save_relocs (&vars, id4);
1014
1015
44
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
44
      pe_ILF_save_relocs (&vars, id5);
1017
44
    }
1018
1019
  /* Create an import symbol.  */
1020
59
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
59
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
59
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
59
  switch (import_type)
1027
59
    {
1028
0
      int i;
1029
1030
25
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
50
      for (i = NUM_ENTRIES (jtab); i--;)
1035
50
  {
1036
50
    if (jtab[i].size == 0)
1037
25
      continue;
1038
25
    if (jtab[i].magic == magic)
1039
25
      break;
1040
25
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
25
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
25
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
25
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
25
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
25
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
25
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
25
            imp_index);
1079
1080
25
      pe_ILF_save_relocs (&vars, text);
1081
25
      break;
1082
1083
17
    case IMPORT_DATA:
1084
34
    case IMPORT_CONST:
1085
34
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
59
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
59
  switch (import_type)
1094
59
    {
1095
25
    case IMPORT_CODE:
1096
25
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
25
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
25
      break;
1100
1101
17
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
17
      break;
1104
1105
17
    case IMPORT_CONST:
1106
17
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
17
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
59
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
59
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
59
  if (ptr)
1117
9
    *ptr = 0;
1118
59
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
59
  if (ptr)
1120
9
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
59
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
59
  internal_f.f_magic  = magic;
1126
59
  internal_f.f_symptr = 0;
1127
59
  internal_f.f_nsyms  = 0;
1128
59
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
59
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
59
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
59
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
59
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
59
  bfd_cache_close (abfd);
1147
1148
59
  abfd->iostream = (void *) vars.bim;
1149
59
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
59
  abfd->iovec = &_bfd_memory_iovec;
1151
59
  abfd->where = 0;
1152
59
  abfd->origin = 0;
1153
59
  abfd->size = 0;
1154
59
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
59
  obj_symbols (abfd) = vars.sym_cache;
1158
59
  abfd->symcount = vars.sym_index;
1159
1160
59
  obj_raw_syments (abfd) = vars.native_syms;
1161
59
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
59
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
59
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
59
  obj_coff_keep_syms (abfd) = true;
1166
1167
59
  obj_convert (abfd) = vars.sym_table;
1168
59
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
59
  obj_coff_strings (abfd) = vars.string_table;
1171
59
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
59
  obj_coff_keep_strings (abfd) = true;
1173
1174
59
  return true;
1175
1176
2
 error_return:
1177
2
  free (vars.bim->buffer);
1178
2
  free (vars.bim);
1179
  return false;
1180
59
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
61
{
805
61
  bfd_byte *       ptr;
806
61
  pe_ILF_vars      vars;
807
61
  struct internal_filehdr  internal_f;
808
61
  unsigned int       import_type;
809
61
  unsigned int       import_name_type;
810
61
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
61
  coff_symbol_type **    imp_sym;
812
61
  unsigned int       imp_index;
813
61
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
61
  import_type = types & 0x3;
817
61
  import_name_type = (types & 0x1c) >> 2;
818
819
61
  switch (import_type)
820
61
    {
821
22
    case IMPORT_CODE:
822
43
    case IMPORT_DATA:
823
59
    case IMPORT_CONST:
824
59
      break;
825
826
2
    default:
827
      /* xgettext:c-format */
828
2
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
2
        abfd, import_type);
830
2
      return false;
831
61
    }
832
833
59
  switch (import_name_type)
834
59
    {
835
10
    case IMPORT_ORDINAL:
836
16
    case IMPORT_NAME:
837
28
    case IMPORT_NAME_NOPREFIX:
838
47
    case IMPORT_NAME_UNDECORATE:
839
47
      import_name = symbol_name;
840
47
      break;
841
842
10
    case IMPORT_NAME_EXPORTAS:
843
10
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
6
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
59
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
53
  vars.bim
867
53
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
53
  if (vars.bim == NULL)
869
0
    return false;
870
871
53
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
53
  vars.bim->buffer = ptr;
873
53
  vars.bim->size   = ILF_DATA_SIZE;
874
53
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
53
  vars.sym_cache = (coff_symbol_type *) ptr;
880
53
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
53
  vars.sym_index = 0;
882
53
  ptr += SIZEOF_ILF_SYMS;
883
884
53
  vars.sym_table = (unsigned int *) ptr;
885
53
  vars.table_ptr = (unsigned int *) ptr;
886
53
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
53
  vars.native_syms = (combined_entry_type *) ptr;
889
53
  vars.native_ptr  = (combined_entry_type *) ptr;
890
53
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
53
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
53
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
53
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
53
  vars.esym_table = (SYMENT *) ptr;
897
53
  vars.esym_ptr   = (SYMENT *) ptr;
898
53
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
53
  vars.reltab   = (arelent *) ptr;
901
53
  vars.relcount = 0;
902
53
  ptr += SIZEOF_ILF_RELOCS;
903
904
53
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
53
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
53
  vars.string_table = (char *) ptr;
908
53
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
53
  ptr += SIZEOF_ILF_STRINGS;
910
53
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
53
#if GCC_VERSION >= 3000
920
53
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
53
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
53
  vars.data = ptr;
927
53
  vars.abfd = abfd;
928
53
  vars.sec_index = 0;
929
53
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
53
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
53
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
53
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
53
  if (import_name_type == IMPORT_ORDINAL)
945
10
    {
946
10
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
2
  goto error_return;
949
950
8
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
8
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
8
      ((unsigned int *) id4->contents)[0] = ordinal;
953
8
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
8
      ((unsigned int *) id5->contents)[0] = ordinal;
955
8
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
8
    }
961
43
  else
962
43
    {
963
43
      char *symbol;
964
43
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
43
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
43
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
43
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
43
      if (import_name_type != IMPORT_NAME
982
37
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
31
  {
984
31
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
31
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
31
        || c == '@' || c == '?')
990
9
      symbol++;
991
31
  }
992
993
43
      len = strlen (symbol);
994
43
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
19
  {
996
    /* Truncate at the first '@'.  */
997
19
    char *at = strchr (symbol, '@');
998
999
19
    if (at != NULL)
1000
4
      len = at - symbol;
1001
19
  }
1002
1003
43
      id6->contents[0] = ordinal & 0xff;
1004
43
      id6->contents[1] = ordinal >> 8;
1005
1006
43
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
43
      id6->contents[len + 2] = '\0';
1008
43
    }
1009
1010
51
  if (import_name_type != IMPORT_ORDINAL)
1011
43
    {
1012
43
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
43
      pe_ILF_save_relocs (&vars, id4);
1014
1015
43
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
43
      pe_ILF_save_relocs (&vars, id5);
1017
43
    }
1018
1019
  /* Create an import symbol.  */
1020
51
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
51
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
51
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
51
  switch (import_type)
1027
51
    {
1028
0
      int i;
1029
1030
18
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
36
      for (i = NUM_ENTRIES (jtab); i--;)
1035
36
  {
1036
36
    if (jtab[i].size == 0)
1037
18
      continue;
1038
18
    if (jtab[i].magic == magic)
1039
18
      break;
1040
18
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
18
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
18
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
18
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
18
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
18
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
18
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
18
            imp_index);
1079
1080
18
      pe_ILF_save_relocs (&vars, text);
1081
18
      break;
1082
1083
19
    case IMPORT_DATA:
1084
33
    case IMPORT_CONST:
1085
33
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
51
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
51
  switch (import_type)
1094
51
    {
1095
18
    case IMPORT_CODE:
1096
18
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
18
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
18
      break;
1100
1101
19
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
19
      break;
1104
1105
14
    case IMPORT_CONST:
1106
14
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
14
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
51
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
51
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
51
  if (ptr)
1117
6
    *ptr = 0;
1118
51
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
51
  if (ptr)
1120
6
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
51
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
51
  internal_f.f_magic  = magic;
1126
51
  internal_f.f_symptr = 0;
1127
51
  internal_f.f_nsyms  = 0;
1128
51
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
51
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
51
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
51
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
51
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
51
  bfd_cache_close (abfd);
1147
1148
51
  abfd->iostream = (void *) vars.bim;
1149
51
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
51
  abfd->iovec = &_bfd_memory_iovec;
1151
51
  abfd->where = 0;
1152
51
  abfd->origin = 0;
1153
51
  abfd->size = 0;
1154
51
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
51
  obj_symbols (abfd) = vars.sym_cache;
1158
51
  abfd->symcount = vars.sym_index;
1159
1160
51
  obj_raw_syments (abfd) = vars.native_syms;
1161
51
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
51
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
51
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
51
  obj_coff_keep_syms (abfd) = true;
1166
1167
51
  obj_convert (abfd) = vars.sym_table;
1168
51
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
51
  obj_coff_strings (abfd) = vars.string_table;
1171
51
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
51
  obj_coff_keep_strings (abfd) = true;
1173
1174
51
  return true;
1175
1176
2
 error_return:
1177
2
  free (vars.bim->buffer);
1178
2
  free (vars.bim);
1179
  return false;
1180
51
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
72
{
805
72
  bfd_byte *       ptr;
806
72
  pe_ILF_vars      vars;
807
72
  struct internal_filehdr  internal_f;
808
72
  unsigned int       import_type;
809
72
  unsigned int       import_name_type;
810
72
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
72
  coff_symbol_type **    imp_sym;
812
72
  unsigned int       imp_index;
813
72
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
72
  import_type = types & 0x3;
817
72
  import_name_type = (types & 0x1c) >> 2;
818
819
72
  switch (import_type)
820
72
    {
821
28
    case IMPORT_CODE:
822
43
    case IMPORT_DATA:
823
70
    case IMPORT_CONST:
824
70
      break;
825
826
2
    default:
827
      /* xgettext:c-format */
828
2
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
2
        abfd, import_type);
830
2
      return false;
831
72
    }
832
833
70
  switch (import_name_type)
834
70
    {
835
19
    case IMPORT_ORDINAL:
836
27
    case IMPORT_NAME:
837
33
    case IMPORT_NAME_NOPREFIX:
838
57
    case IMPORT_NAME_UNDECORATE:
839
57
      import_name = symbol_name;
840
57
      break;
841
842
10
    case IMPORT_NAME_EXPORTAS:
843
10
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
6
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
3
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
3
        abfd, import_name_type);
856
3
      return false;
857
70
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
63
  vars.bim
867
63
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
63
  if (vars.bim == NULL)
869
0
    return false;
870
871
63
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
63
  vars.bim->buffer = ptr;
873
63
  vars.bim->size   = ILF_DATA_SIZE;
874
63
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
63
  vars.sym_cache = (coff_symbol_type *) ptr;
880
63
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
63
  vars.sym_index = 0;
882
63
  ptr += SIZEOF_ILF_SYMS;
883
884
63
  vars.sym_table = (unsigned int *) ptr;
885
63
  vars.table_ptr = (unsigned int *) ptr;
886
63
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
63
  vars.native_syms = (combined_entry_type *) ptr;
889
63
  vars.native_ptr  = (combined_entry_type *) ptr;
890
63
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
63
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
63
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
63
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
63
  vars.esym_table = (SYMENT *) ptr;
897
63
  vars.esym_ptr   = (SYMENT *) ptr;
898
63
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
63
  vars.reltab   = (arelent *) ptr;
901
63
  vars.relcount = 0;
902
63
  ptr += SIZEOF_ILF_RELOCS;
903
904
63
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
63
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
63
  vars.string_table = (char *) ptr;
908
63
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
63
  ptr += SIZEOF_ILF_STRINGS;
910
63
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
63
#if GCC_VERSION >= 3000
920
63
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
63
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
63
  vars.data = ptr;
927
63
  vars.abfd = abfd;
928
63
  vars.sec_index = 0;
929
63
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
63
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
63
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
63
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
63
  if (import_name_type == IMPORT_ORDINAL)
945
19
    {
946
19
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
3
  goto error_return;
949
950
16
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
16
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
16
      ((unsigned int *) id4->contents)[0] = ordinal;
953
16
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
16
      ((unsigned int *) id5->contents)[0] = ordinal;
955
16
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
16
    }
961
44
  else
962
44
    {
963
44
      char *symbol;
964
44
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
44
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
44
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
44
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
44
      if (import_name_type != IMPORT_NAME
982
36
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
30
  {
984
30
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
30
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
30
        || c == '@' || c == '?')
990
9
      symbol++;
991
30
  }
992
993
44
      len = strlen (symbol);
994
44
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
24
  {
996
    /* Truncate at the first '@'.  */
997
24
    char *at = strchr (symbol, '@');
998
999
24
    if (at != NULL)
1000
6
      len = at - symbol;
1001
24
  }
1002
1003
44
      id6->contents[0] = ordinal & 0xff;
1004
44
      id6->contents[1] = ordinal >> 8;
1005
1006
44
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
44
      id6->contents[len + 2] = '\0';
1008
44
    }
1009
1010
60
  if (import_name_type != IMPORT_ORDINAL)
1011
44
    {
1012
44
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
44
      pe_ILF_save_relocs (&vars, id4);
1014
1015
44
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
44
      pe_ILF_save_relocs (&vars, id5);
1017
44
    }
1018
1019
  /* Create an import symbol.  */
1020
60
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
60
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
60
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
60
  switch (import_type)
1027
60
    {
1028
0
      int i;
1029
1030
23
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
46
      for (i = NUM_ENTRIES (jtab); i--;)
1035
46
  {
1036
46
    if (jtab[i].size == 0)
1037
23
      continue;
1038
23
    if (jtab[i].magic == magic)
1039
23
      break;
1040
23
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
23
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
23
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
23
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
23
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
23
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
23
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
23
            imp_index);
1079
1080
23
      pe_ILF_save_relocs (&vars, text);
1081
23
      break;
1082
1083
13
    case IMPORT_DATA:
1084
37
    case IMPORT_CONST:
1085
37
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
60
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
60
  switch (import_type)
1094
60
    {
1095
23
    case IMPORT_CODE:
1096
23
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
23
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
23
      break;
1100
1101
13
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
13
      break;
1104
1105
24
    case IMPORT_CONST:
1106
24
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
24
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
60
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
60
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
60
  if (ptr)
1117
12
    *ptr = 0;
1118
60
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
60
  if (ptr)
1120
12
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
60
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
60
  internal_f.f_magic  = magic;
1126
60
  internal_f.f_symptr = 0;
1127
60
  internal_f.f_nsyms  = 0;
1128
60
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
60
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
60
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
60
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
60
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
60
  bfd_cache_close (abfd);
1147
1148
60
  abfd->iostream = (void *) vars.bim;
1149
60
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
60
  abfd->iovec = &_bfd_memory_iovec;
1151
60
  abfd->where = 0;
1152
60
  abfd->origin = 0;
1153
60
  abfd->size = 0;
1154
60
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
60
  obj_symbols (abfd) = vars.sym_cache;
1158
60
  abfd->symcount = vars.sym_index;
1159
1160
60
  obj_raw_syments (abfd) = vars.native_syms;
1161
60
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
60
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
60
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
60
  obj_coff_keep_syms (abfd) = true;
1166
1167
60
  obj_convert (abfd) = vars.sym_table;
1168
60
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
60
  obj_coff_strings (abfd) = vars.string_table;
1171
60
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
60
  obj_coff_keep_strings (abfd) = true;
1173
1174
60
  return true;
1175
1176
3
 error_return:
1177
3
  free (vars.bim->buffer);
1178
3
  free (vars.bim);
1179
  return false;
1180
60
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
804
46
{
805
46
  bfd_byte *       ptr;
806
46
  pe_ILF_vars      vars;
807
46
  struct internal_filehdr  internal_f;
808
46
  unsigned int       import_type;
809
46
  unsigned int       import_name_type;
810
46
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
46
  coff_symbol_type **    imp_sym;
812
46
  unsigned int       imp_index;
813
46
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
46
  import_type = types & 0x3;
817
46
  import_name_type = (types & 0x1c) >> 2;
818
819
46
  switch (import_type)
820
46
    {
821
21
    case IMPORT_CODE:
822
32
    case IMPORT_DATA:
823
43
    case IMPORT_CONST:
824
43
      break;
825
826
3
    default:
827
      /* xgettext:c-format */
828
3
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
3
        abfd, import_type);
830
3
      return false;
831
46
    }
832
833
43
  switch (import_name_type)
834
43
    {
835
10
    case IMPORT_ORDINAL:
836
14
    case IMPORT_NAME:
837
21
    case IMPORT_NAME_NOPREFIX:
838
34
    case IMPORT_NAME_UNDECORATE:
839
34
      import_name = symbol_name;
840
34
      break;
841
842
7
    case IMPORT_NAME_EXPORTAS:
843
7
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
3
      break;
851
852
3
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
43
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
37
  vars.bim
867
37
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
37
  if (vars.bim == NULL)
869
0
    return false;
870
871
37
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
37
  vars.bim->buffer = ptr;
873
37
  vars.bim->size   = ILF_DATA_SIZE;
874
37
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
37
  vars.sym_cache = (coff_symbol_type *) ptr;
880
37
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
37
  vars.sym_index = 0;
882
37
  ptr += SIZEOF_ILF_SYMS;
883
884
37
  vars.sym_table = (unsigned int *) ptr;
885
37
  vars.table_ptr = (unsigned int *) ptr;
886
37
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
37
  vars.native_syms = (combined_entry_type *) ptr;
889
37
  vars.native_ptr  = (combined_entry_type *) ptr;
890
37
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
37
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
37
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
37
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
37
  vars.esym_table = (SYMENT *) ptr;
897
37
  vars.esym_ptr   = (SYMENT *) ptr;
898
37
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
37
  vars.reltab   = (arelent *) ptr;
901
37
  vars.relcount = 0;
902
37
  ptr += SIZEOF_ILF_RELOCS;
903
904
37
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
37
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
37
  vars.string_table = (char *) ptr;
908
37
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
37
  ptr += SIZEOF_ILF_STRINGS;
910
37
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
37
#if GCC_VERSION >= 3000
920
37
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
37
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
37
  vars.data = ptr;
927
37
  vars.abfd = abfd;
928
37
  vars.sec_index = 0;
929
37
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
37
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
37
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
37
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
37
  if (import_name_type == IMPORT_ORDINAL)
945
10
    {
946
10
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
3
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
7
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
7
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
7
#endif
960
7
    }
961
27
  else
962
27
    {
963
27
      char *symbol;
964
27
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
27
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
27
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
27
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
27
      if (import_name_type != IMPORT_NAME
982
23
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
20
  {
984
20
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
20
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
20
        || c == '@' || c == '?')
990
4
      symbol++;
991
20
  }
992
993
27
      len = strlen (symbol);
994
27
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
13
  {
996
    /* Truncate at the first '@'.  */
997
13
    char *at = strchr (symbol, '@');
998
999
13
    if (at != NULL)
1000
2
      len = at - symbol;
1001
13
  }
1002
1003
27
      id6->contents[0] = ordinal & 0xff;
1004
27
      id6->contents[1] = ordinal >> 8;
1005
1006
27
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
27
      id6->contents[len + 2] = '\0';
1008
27
    }
1009
1010
34
  if (import_name_type != IMPORT_ORDINAL)
1011
27
    {
1012
27
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
27
      pe_ILF_save_relocs (&vars, id4);
1014
1015
27
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
27
      pe_ILF_save_relocs (&vars, id5);
1017
27
    }
1018
1019
  /* Create an import symbol.  */
1020
34
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
34
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
34
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
34
  switch (import_type)
1027
34
    {
1028
0
      int i;
1029
1030
15
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
38
      for (i = NUM_ENTRIES (jtab); i--;)
1035
38
  {
1036
38
    if (jtab[i].size == 0)
1037
15
      continue;
1038
23
    if (jtab[i].magic == magic)
1039
15
      break;
1040
23
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
15
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
15
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
15
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
15
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
15
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
15
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
15
            imp_index);
1079
1080
15
      pe_ILF_save_relocs (&vars, text);
1081
15
      break;
1082
1083
9
    case IMPORT_DATA:
1084
19
    case IMPORT_CONST:
1085
19
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
34
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
34
  switch (import_type)
1094
34
    {
1095
15
    case IMPORT_CODE:
1096
15
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
15
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
15
      break;
1100
1101
9
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
9
      break;
1104
1105
10
    case IMPORT_CONST:
1106
10
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
10
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
34
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
34
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
34
  if (ptr)
1117
2
    *ptr = 0;
1118
34
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
34
  if (ptr)
1120
2
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
34
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
34
  internal_f.f_magic  = magic;
1126
34
  internal_f.f_symptr = 0;
1127
34
  internal_f.f_nsyms  = 0;
1128
34
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
34
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
34
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
34
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
34
  obj_pe (abfd) = true;
1138
34
#ifdef THUMBPEMAGIC
1139
34
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
16
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
34
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
34
  bfd_cache_close (abfd);
1147
1148
34
  abfd->iostream = (void *) vars.bim;
1149
34
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
34
  abfd->iovec = &_bfd_memory_iovec;
1151
34
  abfd->where = 0;
1152
34
  abfd->origin = 0;
1153
34
  abfd->size = 0;
1154
34
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
34
  obj_symbols (abfd) = vars.sym_cache;
1158
34
  abfd->symcount = vars.sym_index;
1159
1160
34
  obj_raw_syments (abfd) = vars.native_syms;
1161
34
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
34
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
34
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
34
  obj_coff_keep_syms (abfd) = true;
1166
1167
34
  obj_convert (abfd) = vars.sym_table;
1168
34
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
34
  obj_coff_strings (abfd) = vars.string_table;
1171
34
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
34
  obj_coff_keep_strings (abfd) = true;
1173
1174
34
  return true;
1175
1176
3
 error_return:
1177
3
  free (vars.bim->buffer);
1178
3
  free (vars.bim);
1179
  return false;
1180
34
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
804
46
{
805
46
  bfd_byte *       ptr;
806
46
  pe_ILF_vars      vars;
807
46
  struct internal_filehdr  internal_f;
808
46
  unsigned int       import_type;
809
46
  unsigned int       import_name_type;
810
46
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
46
  coff_symbol_type **    imp_sym;
812
46
  unsigned int       imp_index;
813
46
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
46
  import_type = types & 0x3;
817
46
  import_name_type = (types & 0x1c) >> 2;
818
819
46
  switch (import_type)
820
46
    {
821
21
    case IMPORT_CODE:
822
32
    case IMPORT_DATA:
823
43
    case IMPORT_CONST:
824
43
      break;
825
826
3
    default:
827
      /* xgettext:c-format */
828
3
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
3
        abfd, import_type);
830
3
      return false;
831
46
    }
832
833
43
  switch (import_name_type)
834
43
    {
835
10
    case IMPORT_ORDINAL:
836
14
    case IMPORT_NAME:
837
21
    case IMPORT_NAME_NOPREFIX:
838
34
    case IMPORT_NAME_UNDECORATE:
839
34
      import_name = symbol_name;
840
34
      break;
841
842
7
    case IMPORT_NAME_EXPORTAS:
843
7
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
3
      break;
851
852
3
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
43
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
37
  vars.bim
867
37
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
37
  if (vars.bim == NULL)
869
0
    return false;
870
871
37
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
37
  vars.bim->buffer = ptr;
873
37
  vars.bim->size   = ILF_DATA_SIZE;
874
37
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
37
  vars.sym_cache = (coff_symbol_type *) ptr;
880
37
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
37
  vars.sym_index = 0;
882
37
  ptr += SIZEOF_ILF_SYMS;
883
884
37
  vars.sym_table = (unsigned int *) ptr;
885
37
  vars.table_ptr = (unsigned int *) ptr;
886
37
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
37
  vars.native_syms = (combined_entry_type *) ptr;
889
37
  vars.native_ptr  = (combined_entry_type *) ptr;
890
37
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
37
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
37
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
37
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
37
  vars.esym_table = (SYMENT *) ptr;
897
37
  vars.esym_ptr   = (SYMENT *) ptr;
898
37
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
37
  vars.reltab   = (arelent *) ptr;
901
37
  vars.relcount = 0;
902
37
  ptr += SIZEOF_ILF_RELOCS;
903
904
37
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
37
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
37
  vars.string_table = (char *) ptr;
908
37
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
37
  ptr += SIZEOF_ILF_STRINGS;
910
37
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
37
#if GCC_VERSION >= 3000
920
37
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
37
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
37
  vars.data = ptr;
927
37
  vars.abfd = abfd;
928
37
  vars.sec_index = 0;
929
37
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
37
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
37
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
37
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
37
  if (import_name_type == IMPORT_ORDINAL)
945
10
    {
946
10
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
3
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
7
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
7
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
7
#endif
960
7
    }
961
27
  else
962
27
    {
963
27
      char *symbol;
964
27
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
27
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
27
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
27
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
27
      if (import_name_type != IMPORT_NAME
982
23
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
20
  {
984
20
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
20
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
18
        || c == '@' || c == '?')
990
6
      symbol++;
991
20
  }
992
993
27
      len = strlen (symbol);
994
27
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
13
  {
996
    /* Truncate at the first '@'.  */
997
13
    char *at = strchr (symbol, '@');
998
999
13
    if (at != NULL)
1000
2
      len = at - symbol;
1001
13
  }
1002
1003
27
      id6->contents[0] = ordinal & 0xff;
1004
27
      id6->contents[1] = ordinal >> 8;
1005
1006
27
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
27
      id6->contents[len + 2] = '\0';
1008
27
    }
1009
1010
34
  if (import_name_type != IMPORT_ORDINAL)
1011
27
    {
1012
27
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
27
      pe_ILF_save_relocs (&vars, id4);
1014
1015
27
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
27
      pe_ILF_save_relocs (&vars, id5);
1017
27
    }
1018
1019
  /* Create an import symbol.  */
1020
34
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
34
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
34
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
34
  switch (import_type)
1027
34
    {
1028
0
      int i;
1029
1030
15
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
38
      for (i = NUM_ENTRIES (jtab); i--;)
1035
38
  {
1036
38
    if (jtab[i].size == 0)
1037
15
      continue;
1038
23
    if (jtab[i].magic == magic)
1039
15
      break;
1040
23
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
15
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
15
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
15
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
15
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
15
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
15
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
15
            imp_index);
1079
1080
15
      pe_ILF_save_relocs (&vars, text);
1081
15
      break;
1082
1083
9
    case IMPORT_DATA:
1084
19
    case IMPORT_CONST:
1085
19
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
34
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
34
  switch (import_type)
1094
34
    {
1095
15
    case IMPORT_CODE:
1096
15
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
15
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
15
      break;
1100
1101
9
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
9
      break;
1104
1105
10
    case IMPORT_CONST:
1106
10
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
10
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
34
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
34
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
34
  if (ptr)
1117
2
    *ptr = 0;
1118
34
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
34
  if (ptr)
1120
2
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
34
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
34
  internal_f.f_magic  = magic;
1126
34
  internal_f.f_symptr = 0;
1127
34
  internal_f.f_nsyms  = 0;
1128
34
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
34
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
34
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
34
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
34
  obj_pe (abfd) = true;
1138
34
#ifdef THUMBPEMAGIC
1139
34
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
16
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
34
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
34
  bfd_cache_close (abfd);
1147
1148
34
  abfd->iostream = (void *) vars.bim;
1149
34
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
34
  abfd->iovec = &_bfd_memory_iovec;
1151
34
  abfd->where = 0;
1152
34
  abfd->origin = 0;
1153
34
  abfd->size = 0;
1154
34
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
34
  obj_symbols (abfd) = vars.sym_cache;
1158
34
  abfd->symcount = vars.sym_index;
1159
1160
34
  obj_raw_syments (abfd) = vars.native_syms;
1161
34
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
34
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
34
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
34
  obj_coff_keep_syms (abfd) = true;
1166
1167
34
  obj_convert (abfd) = vars.sym_table;
1168
34
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
34
  obj_coff_strings (abfd) = vars.string_table;
1171
34
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
34
  obj_coff_keep_strings (abfd) = true;
1173
1174
34
  return true;
1175
1176
3
 error_return:
1177
3
  free (vars.bim->buffer);
1178
3
  free (vars.bim);
1179
  return false;
1180
34
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
804
62
{
805
62
  bfd_byte *       ptr;
806
62
  pe_ILF_vars      vars;
807
62
  struct internal_filehdr  internal_f;
808
62
  unsigned int       import_type;
809
62
  unsigned int       import_name_type;
810
62
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
62
  coff_symbol_type **    imp_sym;
812
62
  unsigned int       imp_index;
813
62
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
62
  import_type = types & 0x3;
817
62
  import_name_type = (types & 0x1c) >> 2;
818
819
62
  switch (import_type)
820
62
    {
821
18
    case IMPORT_CODE:
822
37
    case IMPORT_DATA:
823
55
    case IMPORT_CONST:
824
55
      break;
825
826
7
    default:
827
      /* xgettext:c-format */
828
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
7
        abfd, import_type);
830
7
      return false;
831
62
    }
832
833
55
  switch (import_name_type)
834
55
    {
835
12
    case IMPORT_ORDINAL:
836
16
    case IMPORT_NAME:
837
30
    case IMPORT_NAME_NOPREFIX:
838
43
    case IMPORT_NAME_UNDECORATE:
839
43
      import_name = symbol_name;
840
43
      break;
841
842
10
    case IMPORT_NAME_EXPORTAS:
843
10
      if (!import_name || !import_name[0])
844
4
  {
845
4
    _bfd_error_handler (_("%pB: missing import name for "
846
4
        "IMPORT_NAME_EXPORTAS for %s"),
847
4
            abfd, symbol_name);
848
4
    return false;
849
4
  }
850
6
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
2
        abfd, import_name_type);
856
2
      return false;
857
55
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
49
  vars.bim
867
49
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
49
  if (vars.bim == NULL)
869
0
    return false;
870
871
49
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
49
  vars.bim->buffer = ptr;
873
49
  vars.bim->size   = ILF_DATA_SIZE;
874
49
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
49
  vars.sym_cache = (coff_symbol_type *) ptr;
880
49
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
49
  vars.sym_index = 0;
882
49
  ptr += SIZEOF_ILF_SYMS;
883
884
49
  vars.sym_table = (unsigned int *) ptr;
885
49
  vars.table_ptr = (unsigned int *) ptr;
886
49
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
49
  vars.native_syms = (combined_entry_type *) ptr;
889
49
  vars.native_ptr  = (combined_entry_type *) ptr;
890
49
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
49
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
49
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
49
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
49
  vars.esym_table = (SYMENT *) ptr;
897
49
  vars.esym_ptr   = (SYMENT *) ptr;
898
49
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
49
  vars.reltab   = (arelent *) ptr;
901
49
  vars.relcount = 0;
902
49
  ptr += SIZEOF_ILF_RELOCS;
903
904
49
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
49
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
49
  vars.string_table = (char *) ptr;
908
49
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
49
  ptr += SIZEOF_ILF_STRINGS;
910
49
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
49
#if GCC_VERSION >= 3000
920
49
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
49
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
49
  vars.data = ptr;
927
49
  vars.abfd = abfd;
928
49
  vars.sec_index = 0;
929
49
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
49
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
49
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
49
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
49
  if (import_name_type == IMPORT_ORDINAL)
945
12
    {
946
12
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
2
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
10
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
10
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
10
#endif
960
10
    }
961
37
  else
962
37
    {
963
37
      char *symbol;
964
37
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
37
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
37
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
37
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
37
      if (import_name_type != IMPORT_NAME
982
33
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
27
  {
984
27
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
27
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
23
        || c == '@' || c == '?')
990
12
      symbol++;
991
27
  }
992
993
37
      len = strlen (symbol);
994
37
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
13
  {
996
    /* Truncate at the first '@'.  */
997
13
    char *at = strchr (symbol, '@');
998
999
13
    if (at != NULL)
1000
2
      len = at - symbol;
1001
13
  }
1002
1003
37
      id6->contents[0] = ordinal & 0xff;
1004
37
      id6->contents[1] = ordinal >> 8;
1005
1006
37
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
37
      id6->contents[len + 2] = '\0';
1008
37
    }
1009
1010
47
  if (import_name_type != IMPORT_ORDINAL)
1011
37
    {
1012
37
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
37
      pe_ILF_save_relocs (&vars, id4);
1014
1015
37
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
37
      pe_ILF_save_relocs (&vars, id5);
1017
37
    }
1018
1019
  /* Create an import symbol.  */
1020
47
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
47
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
47
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
47
  switch (import_type)
1027
47
    {
1028
0
      int i;
1029
1030
13
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
26
      for (i = NUM_ENTRIES (jtab); i--;)
1035
26
  {
1036
26
    if (jtab[i].size == 0)
1037
13
      continue;
1038
13
    if (jtab[i].magic == magic)
1039
13
      break;
1040
13
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
13
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
13
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
13
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
13
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
13
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
13
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
13
            imp_index);
1079
1080
13
      pe_ILF_save_relocs (&vars, text);
1081
13
      break;
1082
1083
18
    case IMPORT_DATA:
1084
34
    case IMPORT_CONST:
1085
34
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
47
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
47
  switch (import_type)
1094
47
    {
1095
13
    case IMPORT_CODE:
1096
13
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
13
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
13
      break;
1100
1101
18
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
18
      break;
1104
1105
16
    case IMPORT_CONST:
1106
16
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
16
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
47
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
47
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
47
  if (ptr)
1117
8
    *ptr = 0;
1118
47
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
47
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
47
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
47
  internal_f.f_magic  = magic;
1126
47
  internal_f.f_symptr = 0;
1127
47
  internal_f.f_nsyms  = 0;
1128
47
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
47
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
47
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
47
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
47
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
47
  bfd_cache_close (abfd);
1147
1148
47
  abfd->iostream = (void *) vars.bim;
1149
47
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
47
  abfd->iovec = &_bfd_memory_iovec;
1151
47
  abfd->where = 0;
1152
47
  abfd->origin = 0;
1153
47
  abfd->size = 0;
1154
47
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
47
  obj_symbols (abfd) = vars.sym_cache;
1158
47
  abfd->symcount = vars.sym_index;
1159
1160
47
  obj_raw_syments (abfd) = vars.native_syms;
1161
47
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
47
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
47
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
47
  obj_coff_keep_syms (abfd) = true;
1166
1167
47
  obj_convert (abfd) = vars.sym_table;
1168
47
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
47
  obj_coff_strings (abfd) = vars.string_table;
1171
47
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
47
  obj_coff_keep_strings (abfd) = true;
1173
1174
47
  return true;
1175
1176
2
 error_return:
1177
2
  free (vars.bim->buffer);
1178
2
  free (vars.bim);
1179
  return false;
1180
47
}
1181
1182
/* Cleanup function, returned from check_format hook.  */
1183
1184
static void
1185
pe_ILF_cleanup (bfd *abfd)
1186
2
{
1187
2
  coff_object_cleanup (abfd);
1188
1189
2
  struct bfd_in_memory *bim = abfd->iostream;
1190
2
  free (bim->buffer);
1191
2
  free (bim);
1192
2
  abfd->iostream = NULL;
1193
2
}
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
1186
1
{
1187
1
  coff_object_cleanup (abfd);
1188
1189
1
  struct bfd_in_memory *bim = abfd->iostream;
1190
1
  free (bim->buffer);
1191
1
  free (bim);
1192
  abfd->iostream = NULL;
1193
1
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1186
1
{
1187
1
  coff_object_cleanup (abfd);
1188
1189
1
  struct bfd_in_memory *bim = abfd->iostream;
1190
1
  free (bim->buffer);
1191
1
  free (bim);
1192
  abfd->iostream = NULL;
1193
1
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1194
1195
/* We have detected an Import Library Format archive element.
1196
   Decode the element and return the appropriate target.  */
1197
1198
static bfd_cleanup
1199
pe_ILF_object_p (bfd *abfd)
1200
10.3k
{
1201
10.3k
  bfd_byte    buffer[14];
1202
10.3k
  bfd_byte *    ptr;
1203
10.3k
  char *    symbol_name;
1204
10.3k
  char *    source_dll;
1205
10.3k
  char *    import_name;
1206
10.3k
  unsigned int    machine;
1207
10.3k
  bfd_size_type   size;
1208
10.3k
  unsigned int    ordinal;
1209
10.3k
  unsigned int    types;
1210
10.3k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
10.3k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
171
    return NULL;
1216
1217
10.2k
  ptr = buffer;
1218
1219
10.2k
  machine = H_GET_16 (abfd, ptr);
1220
10.2k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
10.2k
  magic = 0;
1224
1225
10.2k
  switch (machine)
1226
10.2k
    {
1227
27
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
45
    case IMAGE_FILE_MACHINE_ALPHA:
1229
63
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
81
    case IMAGE_FILE_MACHINE_IA64:
1231
81
      break;
1232
1233
1.03k
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
139
      magic = I386MAGIC;
1236
#endif
1237
1.03k
      break;
1238
1239
930
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
122
      magic = AMD64MAGIC;
1242
#endif
1243
930
      break;
1244
1245
18
    case IMAGE_FILE_MACHINE_R3000:
1246
36
    case IMAGE_FILE_MACHINE_R4000:
1247
54
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
72
    case IMAGE_FILE_MACHINE_MIPS16:
1250
90
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
108
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
108
      break;
1256
1257
495
    case IMAGE_FILE_MACHINE_SH3:
1258
1.12k
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
145
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
1.12k
      break;
1263
1264
660
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
148
      magic = ARMPEMAGIC;
1267
#endif
1268
660
      break;
1269
1270
1.09k
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
146
      magic = AARCH64MAGIC;
1273
#endif
1274
1.09k
      break;
1275
1276
966
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
130
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
966
      break;
1281
1282
956
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
132
      magic = RISCV64MAGIC;
1285
#endif
1286
956
      break;
1287
1288
594
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
132
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
132
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
594
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
2.66k
    default:
1302
2.66k
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
2.66k
  (_("%pB: unrecognised machine type (0x%x)"
1305
2.66k
     " in Import Library Format archive"),
1306
2.66k
   abfd, machine);
1307
2.66k
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
2.66k
      return NULL;
1310
0
      break;
1311
10.2k
    }
1312
1313
7.54k
  if (magic == 0)
1314
6.44k
    {
1315
6.44k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
6.44k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
6.44k
     " in Import Library Format archive"),
1319
6.44k
   abfd, machine);
1320
6.44k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
6.44k
      return NULL;
1323
6.44k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
1.09k
  ptr += 4;
1328
1329
1.09k
  size = H_GET_32 (abfd, ptr);
1330
1.09k
  ptr += 4;
1331
1332
1.09k
  if (size == 0)
1333
18
    {
1334
18
      _bfd_error_handler
1335
18
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
18
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
18
      return NULL;
1339
18
    }
1340
1341
1.07k
  ordinal = H_GET_16 (abfd, ptr);
1342
1.07k
  ptr += 2;
1343
1344
1.07k
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
1.07k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
1.07k
  if (ptr == NULL)
1350
541
    return NULL;
1351
1352
535
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
535
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
535
  if (ptr[size - 1] != 0
1358
491
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
60
    {
1360
60
      _bfd_error_handler
1361
60
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
60
      bfd_set_error (bfd_error_malformed_archive);
1363
60
      bfd_release (abfd, ptr);
1364
60
      return NULL;
1365
60
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
475
  import_name = source_dll + strlen (source_dll) + 1;
1374
475
  if ((bfd_byte *) import_name >= ptr + size)
1375
110
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
110
      import_name = NULL;
1379
110
    }
1380
1381
  /* Now construct the bfd.  */
1382
475
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
475
          source_dll, ordinal, types,
1384
475
          import_name))
1385
93
    {
1386
93
      bfd_release (abfd, ptr);
1387
93
      return NULL;
1388
93
    }
1389
1390
382
  return pe_ILF_cleanup;
1391
475
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1200
1.15k
{
1201
1.15k
  bfd_byte    buffer[14];
1202
1.15k
  bfd_byte *    ptr;
1203
1.15k
  char *    symbol_name;
1204
1.15k
  char *    source_dll;
1205
1.15k
  char *    import_name;
1206
1.15k
  unsigned int    machine;
1207
1.15k
  bfd_size_type   size;
1208
1.15k
  unsigned int    ordinal;
1209
1.15k
  unsigned int    types;
1210
1.15k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.15k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.14k
  ptr = buffer;
1218
1219
1.14k
  machine = H_GET_16 (abfd, ptr);
1220
1.14k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.14k
  magic = 0;
1224
1225
1.14k
  switch (machine)
1226
1.14k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
139
    case IMAGE_FILE_MACHINE_I386:
1234
139
#ifdef I386MAGIC
1235
139
      magic = I386MAGIC;
1236
139
#endif
1237
139
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
105
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
105
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.14k
    }
1312
1313
847
  if (magic == 0)
1314
708
    {
1315
708
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
708
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
708
     " in Import Library Format archive"),
1319
708
   abfd, machine);
1320
708
      bfd_set_error (bfd_error_wrong_format);
1321
1322
708
      return NULL;
1323
708
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
139
  ptr += 4;
1328
1329
139
  size = H_GET_32 (abfd, ptr);
1330
139
  ptr += 4;
1331
1332
139
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
137
  ordinal = H_GET_16 (abfd, ptr);
1342
137
  ptr += 2;
1343
1344
137
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
137
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
137
  if (ptr == NULL)
1350
65
    return NULL;
1351
1352
72
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
72
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
72
  if (ptr[size - 1] != 0
1358
67
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
7
    {
1360
7
      _bfd_error_handler
1361
7
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
7
      bfd_set_error (bfd_error_malformed_archive);
1363
7
      bfd_release (abfd, ptr);
1364
7
      return NULL;
1365
7
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
65
  import_name = source_dll + strlen (source_dll) + 1;
1374
65
  if ((bfd_byte *) import_name >= ptr + size)
1375
12
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
12
      import_name = NULL;
1379
12
    }
1380
1381
  /* Now construct the bfd.  */
1382
65
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
65
          source_dll, ordinal, types,
1384
65
          import_name))
1385
11
    {
1386
11
      bfd_release (abfd, ptr);
1387
11
      return NULL;
1388
11
    }
1389
1390
54
  return pe_ILF_cleanup;
1391
65
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1200
1.15k
{
1201
1.15k
  bfd_byte    buffer[14];
1202
1.15k
  bfd_byte *    ptr;
1203
1.15k
  char *    symbol_name;
1204
1.15k
  char *    source_dll;
1205
1.15k
  char *    import_name;
1206
1.15k
  unsigned int    machine;
1207
1.15k
  bfd_size_type   size;
1208
1.15k
  unsigned int    ordinal;
1209
1.15k
  unsigned int    types;
1210
1.15k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.15k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.13k
  ptr = buffer;
1218
1219
1.13k
  machine = H_GET_16 (abfd, ptr);
1220
1.13k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.13k
  magic = 0;
1224
1225
1.13k
  switch (machine)
1226
1.13k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
122
    case IMAGE_FILE_MACHINE_AMD64:
1240
122
#ifdef AMD64MAGIC
1241
122
      magic = AMD64MAGIC;
1242
122
#endif
1243
122
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
105
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
105
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.13k
    }
1312
1313
841
  if (magic == 0)
1314
719
    {
1315
719
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
719
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
719
     " in Import Library Format archive"),
1319
719
   abfd, machine);
1320
719
      bfd_set_error (bfd_error_wrong_format);
1321
1322
719
      return NULL;
1323
719
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
122
  ptr += 4;
1328
1329
122
  size = H_GET_32 (abfd, ptr);
1330
122
  ptr += 4;
1331
1332
122
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
120
  ordinal = H_GET_16 (abfd, ptr);
1342
120
  ptr += 2;
1343
1344
120
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
120
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
120
  if (ptr == NULL)
1350
61
    return NULL;
1351
1352
59
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
59
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
59
  if (ptr[size - 1] != 0
1358
56
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
5
    {
1360
5
      _bfd_error_handler
1361
5
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
5
      bfd_set_error (bfd_error_malformed_archive);
1363
5
      bfd_release (abfd, ptr);
1364
5
      return NULL;
1365
5
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
54
  import_name = source_dll + strlen (source_dll) + 1;
1374
54
  if ((bfd_byte *) import_name >= ptr + size)
1375
11
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
11
      import_name = NULL;
1379
11
    }
1380
1381
  /* Now construct the bfd.  */
1382
54
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
54
          source_dll, ordinal, types,
1384
54
          import_name))
1385
11
    {
1386
11
      bfd_release (abfd, ptr);
1387
11
      return NULL;
1388
11
    }
1389
1390
43
  return pe_ILF_cleanup;
1391
54
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1200
1.15k
{
1201
1.15k
  bfd_byte    buffer[14];
1202
1.15k
  bfd_byte *    ptr;
1203
1.15k
  char *    symbol_name;
1204
1.15k
  char *    source_dll;
1205
1.15k
  char *    import_name;
1206
1.15k
  unsigned int    machine;
1207
1.15k
  bfd_size_type   size;
1208
1.15k
  unsigned int    ordinal;
1209
1.15k
  unsigned int    types;
1210
1.15k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.15k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.14k
  ptr = buffer;
1218
1219
1.14k
  machine = H_GET_16 (abfd, ptr);
1220
1.14k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.14k
  magic = 0;
1224
1225
1.14k
  switch (machine)
1226
1.14k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
146
    case IMAGE_FILE_MACHINE_ARM64:
1271
146
#ifdef AARCH64MAGIC
1272
146
      magic = AARCH64MAGIC;
1273
146
#endif
1274
146
      break;
1275
1276
105
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
105
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.14k
    }
1312
1313
848
  if (magic == 0)
1314
702
    {
1315
702
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
702
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
702
     " in Import Library Format archive"),
1319
702
   abfd, machine);
1320
702
      bfd_set_error (bfd_error_wrong_format);
1321
1322
702
      return NULL;
1323
702
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
146
  ptr += 4;
1328
1329
146
  size = H_GET_32 (abfd, ptr);
1330
146
  ptr += 4;
1331
1332
146
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
144
  ordinal = H_GET_16 (abfd, ptr);
1342
144
  ptr += 2;
1343
1344
144
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
144
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
144
  if (ptr == NULL)
1350
71
    return NULL;
1351
1352
73
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
73
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
73
  if (ptr[size - 1] != 0
1358
71
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
4
    {
1360
4
      _bfd_error_handler
1361
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
4
      bfd_set_error (bfd_error_malformed_archive);
1363
4
      bfd_release (abfd, ptr);
1364
4
      return NULL;
1365
4
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
69
  import_name = source_dll + strlen (source_dll) + 1;
1374
69
  if ((bfd_byte *) import_name >= ptr + size)
1375
14
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
14
      import_name = NULL;
1379
14
    }
1380
1381
  /* Now construct the bfd.  */
1382
69
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
69
          source_dll, ordinal, types,
1384
69
          import_name))
1385
10
    {
1386
10
      bfd_release (abfd, ptr);
1387
10
      return NULL;
1388
10
    }
1389
1390
59
  return pe_ILF_cleanup;
1391
69
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1200
1.15k
{
1201
1.15k
  bfd_byte    buffer[14];
1202
1.15k
  bfd_byte *    ptr;
1203
1.15k
  char *    symbol_name;
1204
1.15k
  char *    source_dll;
1205
1.15k
  char *    import_name;
1206
1.15k
  unsigned int    machine;
1207
1.15k
  bfd_size_type   size;
1208
1.15k
  unsigned int    ordinal;
1209
1.15k
  unsigned int    types;
1210
1.15k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.15k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.13k
  ptr = buffer;
1218
1219
1.13k
  machine = H_GET_16 (abfd, ptr);
1220
1.13k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.13k
  magic = 0;
1224
1225
1.13k
  switch (machine)
1226
1.13k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
130
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
130
#ifdef LOONGARCH64MAGIC
1278
130
      magic = LOONGARCH64MAGIC;
1279
130
#endif
1280
130
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.13k
    }
1312
1313
845
  if (magic == 0)
1314
715
    {
1315
715
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
715
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
715
     " in Import Library Format archive"),
1319
715
   abfd, machine);
1320
715
      bfd_set_error (bfd_error_wrong_format);
1321
1322
715
      return NULL;
1323
715
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
130
  ptr += 4;
1328
1329
130
  size = H_GET_32 (abfd, ptr);
1330
130
  ptr += 4;
1331
1332
130
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
128
  ordinal = H_GET_16 (abfd, ptr);
1342
128
  ptr += 2;
1343
1344
128
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
128
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
128
  if (ptr == NULL)
1350
63
    return NULL;
1351
1352
65
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
65
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
65
  if (ptr[size - 1] != 0
1358
63
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
4
    {
1360
4
      _bfd_error_handler
1361
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
4
      bfd_set_error (bfd_error_malformed_archive);
1363
4
      bfd_release (abfd, ptr);
1364
4
      return NULL;
1365
4
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
61
  import_name = source_dll + strlen (source_dll) + 1;
1374
61
  if ((bfd_byte *) import_name >= ptr + size)
1375
14
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
14
      import_name = NULL;
1379
14
    }
1380
1381
  /* Now construct the bfd.  */
1382
61
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
61
          source_dll, ordinal, types,
1384
61
          import_name))
1385
10
    {
1386
10
      bfd_release (abfd, ptr);
1387
10
      return NULL;
1388
10
    }
1389
1390
51
  return pe_ILF_cleanup;
1391
61
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1200
1.16k
{
1201
1.16k
  bfd_byte    buffer[14];
1202
1.16k
  bfd_byte *    ptr;
1203
1.16k
  char *    symbol_name;
1204
1.16k
  char *    source_dll;
1205
1.16k
  char *    import_name;
1206
1.16k
  unsigned int    machine;
1207
1.16k
  bfd_size_type   size;
1208
1.16k
  unsigned int    ordinal;
1209
1.16k
  unsigned int    types;
1210
1.16k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.16k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.14k
  ptr = buffer;
1218
1219
1.14k
  machine = H_GET_16 (abfd, ptr);
1220
1.14k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.14k
  magic = 0;
1224
1225
1.14k
  switch (machine)
1226
1.14k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
105
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
105
      break;
1281
1282
132
    case IMAGE_FILE_MACHINE_RISCV64:
1283
132
#ifdef RISCV64MAGIC
1284
132
      magic = RISCV64MAGIC;
1285
132
#endif
1286
132
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.14k
    }
1312
1313
849
  if (magic == 0)
1314
717
    {
1315
717
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
717
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
717
     " in Import Library Format archive"),
1319
717
   abfd, machine);
1320
717
      bfd_set_error (bfd_error_wrong_format);
1321
1322
717
      return NULL;
1323
717
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
132
  ptr += 4;
1328
1329
132
  size = H_GET_32 (abfd, ptr);
1330
132
  ptr += 4;
1331
1332
132
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
130
  ordinal = H_GET_16 (abfd, ptr);
1342
130
  ptr += 2;
1343
1344
130
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
130
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
130
  if (ptr == NULL)
1350
54
    return NULL;
1351
1352
76
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
76
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
76
  if (ptr[size - 1] != 0
1358
74
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
4
    {
1360
4
      _bfd_error_handler
1361
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
4
      bfd_set_error (bfd_error_malformed_archive);
1363
4
      bfd_release (abfd, ptr);
1364
4
      return NULL;
1365
4
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
72
  import_name = source_dll + strlen (source_dll) + 1;
1374
72
  if ((bfd_byte *) import_name >= ptr + size)
1375
17
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
17
      import_name = NULL;
1379
17
    }
1380
1381
  /* Now construct the bfd.  */
1382
72
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
72
          source_dll, ordinal, types,
1384
72
          import_name))
1385
12
    {
1386
12
      bfd_release (abfd, ptr);
1387
12
      return NULL;
1388
12
    }
1389
1390
60
  return pe_ILF_cleanup;
1391
72
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1200
1.14k
{
1201
1.14k
  bfd_byte    buffer[14];
1202
1.14k
  bfd_byte *    ptr;
1203
1.14k
  char *    symbol_name;
1204
1.14k
  char *    source_dll;
1205
1.14k
  char *    import_name;
1206
1.14k
  unsigned int    machine;
1207
1.14k
  bfd_size_type   size;
1208
1.14k
  unsigned int    ordinal;
1209
1.14k
  unsigned int    types;
1210
1.14k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.14k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
23
    return NULL;
1216
1217
1.12k
  ptr = buffer;
1218
1219
1.12k
  machine = H_GET_16 (abfd, ptr);
1220
1.12k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.12k
  magic = 0;
1224
1225
1.12k
  switch (machine)
1226
1.12k
    {
1227
5
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
7
    case IMAGE_FILE_MACHINE_ALPHA:
1229
9
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
11
    case IMAGE_FILE_MACHINE_IA64:
1231
11
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
74
    case IMAGE_FILE_MACHINE_ARM:
1265
74
#ifdef ARMPEMAGIC
1266
74
      magic = ARMPEMAGIC;
1267
74
#endif
1268
74
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
104
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
104
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
66
#ifdef THUMBPEMAGIC
1290
66
      {
1291
66
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
66
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
66
    magic = THUMBPEMAGIC;
1295
66
      }
1296
66
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
299
    default:
1302
299
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
299
  (_("%pB: unrecognised machine type (0x%x)"
1305
299
     " in Import Library Format archive"),
1306
299
   abfd, machine);
1307
299
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
299
      return NULL;
1310
0
      break;
1311
1.12k
    }
1312
1313
823
  if (magic == 0)
1314
683
    {
1315
683
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
683
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
683
     " in Import Library Format archive"),
1319
683
   abfd, machine);
1320
683
      bfd_set_error (bfd_error_wrong_format);
1321
1322
683
      return NULL;
1323
683
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
140
  ptr += 4;
1328
1329
140
  size = H_GET_32 (abfd, ptr);
1330
140
  ptr += 4;
1331
1332
140
  if (size == 0)
1333
3
    {
1334
3
      _bfd_error_handler
1335
3
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
3
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
3
      return NULL;
1339
3
    }
1340
1341
137
  ordinal = H_GET_16 (abfd, ptr);
1342
137
  ptr += 2;
1343
1344
137
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
137
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
137
  if (ptr == NULL)
1350
79
    return NULL;
1351
1352
58
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
58
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
58
  if (ptr[size - 1] != 0
1358
48
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
12
    {
1360
12
      _bfd_error_handler
1361
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
12
      bfd_set_error (bfd_error_malformed_archive);
1363
12
      bfd_release (abfd, ptr);
1364
12
      return NULL;
1365
12
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
46
  import_name = source_dll + strlen (source_dll) + 1;
1374
46
  if ((bfd_byte *) import_name >= ptr + size)
1375
13
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
13
      import_name = NULL;
1379
13
    }
1380
1381
  /* Now construct the bfd.  */
1382
46
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
46
          source_dll, ordinal, types,
1384
46
          import_name))
1385
12
    {
1386
12
      bfd_release (abfd, ptr);
1387
12
      return NULL;
1388
12
    }
1389
1390
34
  return pe_ILF_cleanup;
1391
46
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1200
1.14k
{
1201
1.14k
  bfd_byte    buffer[14];
1202
1.14k
  bfd_byte *    ptr;
1203
1.14k
  char *    symbol_name;
1204
1.14k
  char *    source_dll;
1205
1.14k
  char *    import_name;
1206
1.14k
  unsigned int    machine;
1207
1.14k
  bfd_size_type   size;
1208
1.14k
  unsigned int    ordinal;
1209
1.14k
  unsigned int    types;
1210
1.14k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.14k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
23
    return NULL;
1216
1217
1.12k
  ptr = buffer;
1218
1219
1.12k
  machine = H_GET_16 (abfd, ptr);
1220
1.12k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.12k
  magic = 0;
1224
1225
1.12k
  switch (machine)
1226
1.12k
    {
1227
5
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
7
    case IMAGE_FILE_MACHINE_ALPHA:
1229
9
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
11
    case IMAGE_FILE_MACHINE_IA64:
1231
11
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
74
    case IMAGE_FILE_MACHINE_ARM:
1265
74
#ifdef ARMPEMAGIC
1266
74
      magic = ARMPEMAGIC;
1267
74
#endif
1268
74
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
104
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
104
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
66
#ifdef THUMBPEMAGIC
1290
66
      {
1291
66
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
66
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
66
    magic = THUMBPEMAGIC;
1295
66
      }
1296
66
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
299
    default:
1302
299
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
299
  (_("%pB: unrecognised machine type (0x%x)"
1305
299
     " in Import Library Format archive"),
1306
299
   abfd, machine);
1307
299
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
299
      return NULL;
1310
0
      break;
1311
1.12k
    }
1312
1313
823
  if (magic == 0)
1314
683
    {
1315
683
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
683
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
683
     " in Import Library Format archive"),
1319
683
   abfd, machine);
1320
683
      bfd_set_error (bfd_error_wrong_format);
1321
1322
683
      return NULL;
1323
683
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
140
  ptr += 4;
1328
1329
140
  size = H_GET_32 (abfd, ptr);
1330
140
  ptr += 4;
1331
1332
140
  if (size == 0)
1333
3
    {
1334
3
      _bfd_error_handler
1335
3
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
3
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
3
      return NULL;
1339
3
    }
1340
1341
137
  ordinal = H_GET_16 (abfd, ptr);
1342
137
  ptr += 2;
1343
1344
137
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
137
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
137
  if (ptr == NULL)
1350
79
    return NULL;
1351
1352
58
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
58
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
58
  if (ptr[size - 1] != 0
1358
48
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
12
    {
1360
12
      _bfd_error_handler
1361
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
12
      bfd_set_error (bfd_error_malformed_archive);
1363
12
      bfd_release (abfd, ptr);
1364
12
      return NULL;
1365
12
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
46
  import_name = source_dll + strlen (source_dll) + 1;
1374
46
  if ((bfd_byte *) import_name >= ptr + size)
1375
13
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
13
      import_name = NULL;
1379
13
    }
1380
1381
  /* Now construct the bfd.  */
1382
46
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
46
          source_dll, ordinal, types,
1384
46
          import_name))
1385
12
    {
1386
12
      bfd_release (abfd, ptr);
1387
12
      return NULL;
1388
12
    }
1389
1390
34
  return pe_ILF_cleanup;
1391
46
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1200
1.14k
{
1201
1.14k
  bfd_byte    buffer[14];
1202
1.14k
  bfd_byte *    ptr;
1203
1.14k
  char *    symbol_name;
1204
1.14k
  char *    source_dll;
1205
1.14k
  char *    import_name;
1206
1.14k
  unsigned int    machine;
1207
1.14k
  bfd_size_type   size;
1208
1.14k
  unsigned int    ordinal;
1209
1.14k
  unsigned int    types;
1210
1.14k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.14k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
23
    return NULL;
1216
1217
1.12k
  ptr = buffer;
1218
1219
1.12k
  machine = H_GET_16 (abfd, ptr);
1220
1.12k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.12k
  magic = 0;
1224
1225
1.12k
  switch (machine)
1226
1.12k
    {
1227
5
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
7
    case IMAGE_FILE_MACHINE_ALPHA:
1229
9
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
11
    case IMAGE_FILE_MACHINE_IA64:
1231
11
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
54
    case IMAGE_FILE_MACHINE_SH3:
1258
122
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
122
      break;
1263
1264
74
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
74
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
104
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
104
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
299
    default:
1302
299
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
299
  (_("%pB: unrecognised machine type (0x%x)"
1305
299
     " in Import Library Format archive"),
1306
299
   abfd, machine);
1307
299
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
299
      return NULL;
1310
0
      break;
1311
1.12k
    }
1312
1313
823
  if (magic == 0)
1314
823
    {
1315
823
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
823
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
823
     " in Import Library Format archive"),
1319
823
   abfd, machine);
1320
823
      bfd_set_error (bfd_error_wrong_format);
1321
1322
823
      return NULL;
1323
823
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
0
  ptr += 4;
1328
1329
0
  size = H_GET_32 (abfd, ptr);
1330
0
  ptr += 4;
1331
1332
0
  if (size == 0)
1333
0
    {
1334
0
      _bfd_error_handler
1335
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
0
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
0
      return NULL;
1339
0
    }
1340
1341
0
  ordinal = H_GET_16 (abfd, ptr);
1342
0
  ptr += 2;
1343
1344
0
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
0
  if (ptr == NULL)
1350
0
    return NULL;
1351
1352
0
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
0
  if (ptr[size - 1] != 0
1358
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
0
    {
1360
0
      _bfd_error_handler
1361
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
0
      bfd_set_error (bfd_error_malformed_archive);
1363
0
      bfd_release (abfd, ptr);
1364
0
      return NULL;
1365
0
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
0
  import_name = source_dll + strlen (source_dll) + 1;
1374
0
  if ((bfd_byte *) import_name >= ptr + size)
1375
0
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
0
      import_name = NULL;
1379
0
    }
1380
1381
  /* Now construct the bfd.  */
1382
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
0
          source_dll, ordinal, types,
1384
0
          import_name))
1385
0
    {
1386
0
      bfd_release (abfd, ptr);
1387
0
      return NULL;
1388
0
    }
1389
1390
0
  return pe_ILF_cleanup;
1391
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1200
1.15k
{
1201
1.15k
  bfd_byte    buffer[14];
1202
1.15k
  bfd_byte *    ptr;
1203
1.15k
  char *    symbol_name;
1204
1.15k
  char *    source_dll;
1205
1.15k
  char *    import_name;
1206
1.15k
  unsigned int    machine;
1207
1.15k
  bfd_size_type   size;
1208
1.15k
  unsigned int    ordinal;
1209
1.15k
  unsigned int    types;
1210
1.15k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.15k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
17
    return NULL;
1216
1217
1.13k
  ptr = buffer;
1218
1219
1.13k
  machine = H_GET_16 (abfd, ptr);
1220
1.13k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.13k
  magic = 0;
1224
1225
1.13k
  switch (machine)
1226
1.13k
    {
1227
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
4
    case IMAGE_FILE_MACHINE_ALPHA:
1229
6
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
8
    case IMAGE_FILE_MACHINE_IA64:
1231
8
      break;
1232
1233
112
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
112
      break;
1238
1239
101
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
101
      break;
1244
1245
2
    case IMAGE_FILE_MACHINE_R3000:
1246
4
    case IMAGE_FILE_MACHINE_R4000:
1247
6
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
8
    case IMAGE_FILE_MACHINE_MIPS16:
1250
10
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
12
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
12
      break;
1256
1257
63
    case IMAGE_FILE_MACHINE_SH3:
1258
145
    case IMAGE_FILE_MACHINE_SH4:
1259
145
#ifdef SH_ARCH_MAGIC_WINCE
1260
145
      magic = SH_ARCH_MAGIC_WINCE;
1261
145
#endif
1262
145
      break;
1263
1264
73
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
73
      break;
1269
1270
118
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
118
      break;
1275
1276
104
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
104
      break;
1281
1282
103
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
103
      break;
1287
1288
66
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
66
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
294
    default:
1302
294
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
294
  (_("%pB: unrecognised machine type (0x%x)"
1305
294
     " in Import Library Format archive"),
1306
294
   abfd, machine);
1307
294
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
294
      return NULL;
1310
0
      break;
1311
1.13k
    }
1312
1313
842
  if (magic == 0)
1314
697
    {
1315
697
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
697
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
697
     " in Import Library Format archive"),
1319
697
   abfd, machine);
1320
697
      bfd_set_error (bfd_error_wrong_format);
1321
1322
697
      return NULL;
1323
697
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
145
  ptr += 4;
1328
1329
145
  size = H_GET_32 (abfd, ptr);
1330
145
  ptr += 4;
1331
1332
145
  if (size == 0)
1333
2
    {
1334
2
      _bfd_error_handler
1335
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
2
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
2
      return NULL;
1339
2
    }
1340
1341
143
  ordinal = H_GET_16 (abfd, ptr);
1342
143
  ptr += 2;
1343
1344
143
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
143
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
143
  if (ptr == NULL)
1350
69
    return NULL;
1351
1352
74
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
74
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
74
  if (ptr[size - 1] != 0
1358
64
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
12
    {
1360
12
      _bfd_error_handler
1361
12
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
12
      bfd_set_error (bfd_error_malformed_archive);
1363
12
      bfd_release (abfd, ptr);
1364
12
      return NULL;
1365
12
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
62
  import_name = source_dll + strlen (source_dll) + 1;
1374
62
  if ((bfd_byte *) import_name >= ptr + size)
1375
16
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
16
      import_name = NULL;
1379
16
    }
1380
1381
  /* Now construct the bfd.  */
1382
62
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
62
          source_dll, ordinal, types,
1384
62
          import_name))
1385
15
    {
1386
15
      bfd_release (abfd, ptr);
1387
15
      return NULL;
1388
15
    }
1389
1390
47
  return pe_ILF_cleanup;
1391
62
}
1392
1393
static void
1394
pe_bfd_read_buildid (bfd *abfd)
1395
33.6k
{
1396
33.6k
  pe_data_type *pe = pe_data (abfd);
1397
33.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
33.6k
  asection *section;
1399
33.6k
  bfd_byte *data = 0;
1400
33.6k
  bfd_size_type dataoff;
1401
33.6k
  unsigned int i;
1402
33.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
33.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
33.6k
  if (size == 0)
1406
18.5k
    return;
1407
1408
15.0k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
101k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
94.1k
    {
1413
94.1k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
7.57k
  break;
1415
94.1k
    }
1416
1417
15.0k
  if (section == NULL)
1418
7.51k
    return;
1419
1420
7.57k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
270
    return;
1422
1423
7.30k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
7.30k
  if (dataoff >= section->size
1429
7.30k
      || size > section->size - dataoff)
1430
2.52k
    {
1431
2.52k
      _bfd_error_handler
1432
2.52k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
2.52k
   abfd);
1434
2.52k
      return;
1435
2.52k
    }
1436
1437
  /* Read the whole section. */
1438
4.78k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
1.38k
    {
1440
1.38k
      free (data);
1441
1.38k
      return;
1442
1.38k
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
233k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
231k
    {
1447
231k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
231k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
231k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
231k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
231k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
1.47k
  {
1455
1.47k
    char buffer[256 + 1];
1456
1.47k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
1.47k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
1.47k
                (file_ptr) idd.PointerToRawData,
1464
1.47k
                idd.SizeOfData, cvinfo, NULL))
1465
111
      {
1466
111
        struct bfd_build_id *build_id;
1467
111
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
111
        build_id = bfd_alloc (abfd, bidlen);
1470
111
        if (build_id)
1471
111
    {
1472
111
      build_id->size = cvinfo->SignatureLength;
1473
111
      memcpy(build_id->data, cvinfo->Signature,
1474
111
       cvinfo->SignatureLength);
1475
111
      abfd->build_id = build_id;
1476
111
    }
1477
111
      }
1478
1.47k
    break;
1479
1.47k
  }
1480
231k
    }
1481
1482
3.39k
  free (data);
1483
3.39k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1395
7.12k
{
1396
7.12k
  pe_data_type *pe = pe_data (abfd);
1397
7.12k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
7.12k
  asection *section;
1399
7.12k
  bfd_byte *data = 0;
1400
7.12k
  bfd_size_type dataoff;
1401
7.12k
  unsigned int i;
1402
7.12k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
7.12k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
7.12k
  if (size == 0)
1406
5.37k
    return;
1407
1408
1.75k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
13.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
12.4k
    {
1413
12.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
860
  break;
1415
12.4k
    }
1416
1417
1.75k
  if (section == NULL)
1418
890
    return;
1419
1420
860
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
53
    return;
1422
1423
807
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
807
  if (dataoff >= section->size
1429
807
      || size > section->size - dataoff)
1430
340
    {
1431
340
      _bfd_error_handler
1432
340
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
340
   abfd);
1434
340
      return;
1435
340
    }
1436
1437
  /* Read the whole section. */
1438
467
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
155
    {
1440
155
      free (data);
1441
155
      return;
1442
155
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.50k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.38k
    {
1447
5.38k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.38k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.38k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.38k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.38k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
188
  {
1455
188
    char buffer[256 + 1];
1456
188
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
188
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
188
                (file_ptr) idd.PointerToRawData,
1464
188
                idd.SizeOfData, cvinfo, NULL))
1465
15
      {
1466
15
        struct bfd_build_id *build_id;
1467
15
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
15
        build_id = bfd_alloc (abfd, bidlen);
1470
15
        if (build_id)
1471
15
    {
1472
15
      build_id->size = cvinfo->SignatureLength;
1473
15
      memcpy(build_id->data, cvinfo->Signature,
1474
15
       cvinfo->SignatureLength);
1475
15
      abfd->build_id = build_id;
1476
15
    }
1477
15
      }
1478
188
    break;
1479
188
  }
1480
5.38k
    }
1481
1482
312
  free (data);
1483
312
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1395
4.79k
{
1396
4.79k
  pe_data_type *pe = pe_data (abfd);
1397
4.79k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
4.79k
  asection *section;
1399
4.79k
  bfd_byte *data = 0;
1400
4.79k
  bfd_size_type dataoff;
1401
4.79k
  unsigned int i;
1402
4.79k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
4.79k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
4.79k
  if (size == 0)
1406
2.81k
    return;
1407
1408
1.97k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
17.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
16.7k
    {
1413
16.7k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
813
  break;
1415
16.7k
    }
1416
1417
1.97k
  if (section == NULL)
1418
1.16k
    return;
1419
1420
813
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
27
    return;
1422
1423
786
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
786
  if (dataoff >= section->size
1429
786
      || size > section->size - dataoff)
1430
307
    {
1431
307
      _bfd_error_handler
1432
307
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
307
   abfd);
1434
307
      return;
1435
307
    }
1436
1437
  /* Read the whole section. */
1438
479
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
183
    {
1440
183
      free (data);
1441
183
      return;
1442
183
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
12.5k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
12.4k
    {
1447
12.4k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
12.4k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
12.4k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
12.4k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
12.4k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
203
  {
1455
203
    char buffer[256 + 1];
1456
203
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
203
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
203
                (file_ptr) idd.PointerToRawData,
1464
203
                idd.SizeOfData, cvinfo, NULL))
1465
25
      {
1466
25
        struct bfd_build_id *build_id;
1467
25
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
25
        build_id = bfd_alloc (abfd, bidlen);
1470
25
        if (build_id)
1471
25
    {
1472
25
      build_id->size = cvinfo->SignatureLength;
1473
25
      memcpy(build_id->data, cvinfo->Signature,
1474
25
       cvinfo->SignatureLength);
1475
25
      abfd->build_id = build_id;
1476
25
    }
1477
25
      }
1478
203
    break;
1479
203
  }
1480
12.4k
    }
1481
1482
296
  free (data);
1483
296
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
4.66k
{
1396
4.66k
  pe_data_type *pe = pe_data (abfd);
1397
4.66k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
4.66k
  asection *section;
1399
4.66k
  bfd_byte *data = 0;
1400
4.66k
  bfd_size_type dataoff;
1401
4.66k
  unsigned int i;
1402
4.66k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
4.66k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
4.66k
  if (size == 0)
1406
1.37k
    return;
1407
1408
3.28k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
19.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
18.1k
    {
1413
18.1k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
2.21k
  break;
1415
18.1k
    }
1416
1417
3.28k
  if (section == NULL)
1418
1.07k
    return;
1419
1420
2.21k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
14
    return;
1422
1423
2.19k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
2.19k
  if (dataoff >= section->size
1429
2.19k
      || size > section->size - dataoff)
1430
281
    {
1431
281
      _bfd_error_handler
1432
281
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
281
   abfd);
1434
281
      return;
1435
281
    }
1436
1437
  /* Read the whole section. */
1438
1.91k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
287
    {
1440
287
      free (data);
1441
287
      return;
1442
287
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
186k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
185k
    {
1447
185k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
185k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
185k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
185k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
185k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
488
  {
1455
488
    char buffer[256 + 1];
1456
488
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
488
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
488
                (file_ptr) idd.PointerToRawData,
1464
488
                idd.SizeOfData, cvinfo, NULL))
1465
7
      {
1466
7
        struct bfd_build_id *build_id;
1467
7
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
7
        build_id = bfd_alloc (abfd, bidlen);
1470
7
        if (build_id)
1471
7
    {
1472
7
      build_id->size = cvinfo->SignatureLength;
1473
7
      memcpy(build_id->data, cvinfo->Signature,
1474
7
       cvinfo->SignatureLength);
1475
7
      abfd->build_id = build_id;
1476
7
    }
1477
7
      }
1478
488
    break;
1479
488
  }
1480
185k
    }
1481
1482
1.63k
  free (data);
1483
1.63k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.46k
{
1396
2.46k
  pe_data_type *pe = pe_data (abfd);
1397
2.46k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.46k
  asection *section;
1399
2.46k
  bfd_byte *data = 0;
1400
2.46k
  bfd_size_type dataoff;
1401
2.46k
  unsigned int i;
1402
2.46k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.46k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.46k
  if (size == 0)
1406
1.75k
    return;
1407
1408
715
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
3.97k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
3.52k
    {
1413
3.52k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
259
  break;
1415
3.52k
    }
1416
1417
715
  if (section == NULL)
1418
456
    return;
1419
1420
259
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
17
    return;
1422
1423
242
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
242
  if (dataoff >= section->size
1429
242
      || size > section->size - dataoff)
1430
94
    {
1431
94
      _bfd_error_handler
1432
94
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
94
   abfd);
1434
94
      return;
1435
94
    }
1436
1437
  /* Read the whole section. */
1438
148
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
28
    {
1440
28
      free (data);
1441
28
      return;
1442
28
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.12k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.08k
    {
1447
2.08k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.08k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.08k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.08k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.08k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
86
  {
1455
86
    char buffer[256 + 1];
1456
86
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
86
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
86
                (file_ptr) idd.PointerToRawData,
1464
86
                idd.SizeOfData, cvinfo, NULL))
1465
1
      {
1466
1
        struct bfd_build_id *build_id;
1467
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
1
        build_id = bfd_alloc (abfd, bidlen);
1470
1
        if (build_id)
1471
1
    {
1472
1
      build_id->size = cvinfo->SignatureLength;
1473
1
      memcpy(build_id->data, cvinfo->Signature,
1474
1
       cvinfo->SignatureLength);
1475
1
      abfd->build_id = build_id;
1476
1
    }
1477
1
      }
1478
86
    break;
1479
86
  }
1480
2.08k
    }
1481
1482
120
  free (data);
1483
120
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.53k
{
1396
2.53k
  pe_data_type *pe = pe_data (abfd);
1397
2.53k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.53k
  asection *section;
1399
2.53k
  bfd_byte *data = 0;
1400
2.53k
  bfd_size_type dataoff;
1401
2.53k
  unsigned int i;
1402
2.53k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.53k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.53k
  if (size == 0)
1406
1.52k
    return;
1407
1408
1.00k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
7.80k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.23k
    {
1413
7.23k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
439
  break;
1415
7.23k
    }
1416
1417
1.00k
  if (section == NULL)
1418
569
    return;
1419
1420
439
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
18
    return;
1422
1423
421
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
421
  if (dataoff >= section->size
1429
421
      || size > section->size - dataoff)
1430
131
    {
1431
131
      _bfd_error_handler
1432
131
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
131
   abfd);
1434
131
      return;
1435
131
    }
1436
1437
  /* Read the whole section. */
1438
290
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
71
    {
1440
71
      free (data);
1441
71
      return;
1442
71
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
7.97k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
7.89k
    {
1447
7.89k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
7.89k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
7.89k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
7.89k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
7.89k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
139
  {
1455
139
    char buffer[256 + 1];
1456
139
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
139
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
139
                (file_ptr) idd.PointerToRawData,
1464
139
                idd.SizeOfData, cvinfo, NULL))
1465
6
      {
1466
6
        struct bfd_build_id *build_id;
1467
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
6
        build_id = bfd_alloc (abfd, bidlen);
1470
6
        if (build_id)
1471
6
    {
1472
6
      build_id->size = cvinfo->SignatureLength;
1473
6
      memcpy(build_id->data, cvinfo->Signature,
1474
6
       cvinfo->SignatureLength);
1475
6
      abfd->build_id = build_id;
1476
6
    }
1477
6
      }
1478
139
    break;
1479
139
  }
1480
7.89k
    }
1481
1482
219
  free (data);
1483
219
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.98k
{
1396
2.98k
  pe_data_type *pe = pe_data (abfd);
1397
2.98k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.98k
  asection *section;
1399
2.98k
  bfd_byte *data = 0;
1400
2.98k
  bfd_size_type dataoff;
1401
2.98k
  unsigned int i;
1402
2.98k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.98k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.98k
  if (size == 0)
1406
1.36k
    return;
1407
1408
1.62k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
14.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
13.5k
    {
1413
13.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
516
  break;
1415
13.5k
    }
1416
1417
1.62k
  if (section == NULL)
1418
1.10k
    return;
1419
1420
516
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
28
    return;
1422
1423
488
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
488
  if (dataoff >= section->size
1429
488
      || size > section->size - dataoff)
1430
221
    {
1431
221
      _bfd_error_handler
1432
221
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
221
   abfd);
1434
221
      return;
1435
221
    }
1436
1437
  /* Read the whole section. */
1438
267
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
110
    {
1440
110
      free (data);
1441
110
      return;
1442
110
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
1.83k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
1.79k
    {
1447
1.79k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
1.79k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
1.79k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
1.79k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
1.79k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
116
  {
1455
116
    char buffer[256 + 1];
1456
116
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
116
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
116
                (file_ptr) idd.PointerToRawData,
1464
116
                idd.SizeOfData, cvinfo, NULL))
1465
7
      {
1466
7
        struct bfd_build_id *build_id;
1467
7
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
7
        build_id = bfd_alloc (abfd, bidlen);
1470
7
        if (build_id)
1471
7
    {
1472
7
      build_id->size = cvinfo->SignatureLength;
1473
7
      memcpy(build_id->data, cvinfo->Signature,
1474
7
       cvinfo->SignatureLength);
1475
7
      abfd->build_id = build_id;
1476
7
    }
1477
7
      }
1478
116
    break;
1479
116
  }
1480
1.79k
    }
1481
1482
157
  free (data);
1483
157
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1395
1.84k
{
1396
1.84k
  pe_data_type *pe = pe_data (abfd);
1397
1.84k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
1.84k
  asection *section;
1399
1.84k
  bfd_byte *data = 0;
1400
1.84k
  bfd_size_type dataoff;
1401
1.84k
  unsigned int i;
1402
1.84k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
1.84k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
1.84k
  if (size == 0)
1406
671
    return;
1407
1408
1.17k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
4.81k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
4.24k
    {
1413
4.24k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
603
  break;
1415
4.24k
    }
1416
1417
1.17k
  if (section == NULL)
1418
573
    return;
1419
1420
603
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
28
    return;
1422
1423
575
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
575
  if (dataoff >= section->size
1429
575
      || size > section->size - dataoff)
1430
306
    {
1431
306
      _bfd_error_handler
1432
306
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
306
   abfd);
1434
306
      return;
1435
306
    }
1436
1437
  /* Read the whole section. */
1438
269
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
126
    {
1440
126
      free (data);
1441
126
      return;
1442
126
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.67k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.58k
    {
1447
2.58k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.58k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.58k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.58k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.58k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
50
  {
1455
50
    char buffer[256 + 1];
1456
50
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
50
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
50
                (file_ptr) idd.PointerToRawData,
1464
50
                idd.SizeOfData, cvinfo, NULL))
1465
4
      {
1466
4
        struct bfd_build_id *build_id;
1467
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
4
        build_id = bfd_alloc (abfd, bidlen);
1470
4
        if (build_id)
1471
4
    {
1472
4
      build_id->size = cvinfo->SignatureLength;
1473
4
      memcpy(build_id->data, cvinfo->Signature,
1474
4
       cvinfo->SignatureLength);
1475
4
      abfd->build_id = build_id;
1476
4
    }
1477
4
      }
1478
50
    break;
1479
50
  }
1480
2.58k
    }
1481
1482
143
  free (data);
1483
143
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.53k
{
1396
2.53k
  pe_data_type *pe = pe_data (abfd);
1397
2.53k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.53k
  asection *section;
1399
2.53k
  bfd_byte *data = 0;
1400
2.53k
  bfd_size_type dataoff;
1401
2.53k
  unsigned int i;
1402
2.53k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.53k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.53k
  if (size == 0)
1406
1.17k
    return;
1407
1408
1.36k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
5.96k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
5.34k
    {
1413
5.34k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
747
  break;
1415
5.34k
    }
1416
1417
1.36k
  if (section == NULL)
1418
616
    return;
1419
1420
747
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
28
    return;
1422
1423
719
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
719
  if (dataoff >= section->size
1429
719
      || size > section->size - dataoff)
1430
310
    {
1431
310
      _bfd_error_handler
1432
310
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
310
   abfd);
1434
310
      return;
1435
310
    }
1436
1437
  /* Read the whole section. */
1438
409
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
157
    {
1440
157
      free (data);
1441
157
      return;
1442
157
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.17k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.01k
    {
1447
5.01k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.01k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.01k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.01k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.01k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
91
  {
1455
91
    char buffer[256 + 1];
1456
91
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
91
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
91
                (file_ptr) idd.PointerToRawData,
1464
91
                idd.SizeOfData, cvinfo, NULL))
1465
39
      {
1466
39
        struct bfd_build_id *build_id;
1467
39
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
39
        build_id = bfd_alloc (abfd, bidlen);
1470
39
        if (build_id)
1471
39
    {
1472
39
      build_id->size = cvinfo->SignatureLength;
1473
39
      memcpy(build_id->data, cvinfo->Signature,
1474
39
       cvinfo->SignatureLength);
1475
39
      abfd->build_id = build_id;
1476
39
    }
1477
39
      }
1478
91
    break;
1479
91
  }
1480
5.01k
    }
1481
1482
252
  free (data);
1483
252
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.29k
{
1396
2.29k
  pe_data_type *pe = pe_data (abfd);
1397
2.29k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.29k
  asection *section;
1399
2.29k
  bfd_byte *data = 0;
1400
2.29k
  bfd_size_type dataoff;
1401
2.29k
  unsigned int i;
1402
2.29k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.29k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.29k
  if (size == 0)
1406
1.28k
    return;
1407
1408
1.00k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
6.85k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
6.40k
    {
1413
6.40k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
554
  break;
1415
6.40k
    }
1416
1417
1.00k
  if (section == NULL)
1418
454
    return;
1419
1420
554
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
33
    return;
1422
1423
521
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
521
  if (dataoff >= section->size
1429
521
      || size > section->size - dataoff)
1430
265
    {
1431
265
      _bfd_error_handler
1432
265
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
265
   abfd);
1434
265
      return;
1435
265
    }
1436
1437
  /* Read the whole section. */
1438
256
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
123
    {
1440
123
      free (data);
1441
123
      return;
1442
123
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
4.65k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
4.57k
    {
1447
4.57k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
4.57k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
4.57k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
4.57k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
4.57k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
54
  {
1455
54
    char buffer[256 + 1];
1456
54
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
54
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
54
                (file_ptr) idd.PointerToRawData,
1464
54
                idd.SizeOfData, cvinfo, NULL))
1465
3
      {
1466
3
        struct bfd_build_id *build_id;
1467
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
3
        build_id = bfd_alloc (abfd, bidlen);
1470
3
        if (build_id)
1471
3
    {
1472
3
      build_id->size = cvinfo->SignatureLength;
1473
3
      memcpy(build_id->data, cvinfo->Signature,
1474
3
       cvinfo->SignatureLength);
1475
3
      abfd->build_id = build_id;
1476
3
    }
1477
3
      }
1478
54
    break;
1479
54
  }
1480
4.57k
    }
1481
1482
133
  free (data);
1483
133
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.41k
{
1396
2.41k
  pe_data_type *pe = pe_data (abfd);
1397
2.41k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.41k
  asection *section;
1399
2.41k
  bfd_byte *data = 0;
1400
2.41k
  bfd_size_type dataoff;
1401
2.41k
  unsigned int i;
1402
2.41k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.41k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.41k
  if (size == 0)
1406
1.23k
    return;
1407
1408
1.18k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
6.99k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
6.38k
    {
1413
6.38k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
573
  break;
1415
6.38k
    }
1416
1417
1.18k
  if (section == NULL)
1418
614
    return;
1419
1420
573
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
24
    return;
1422
1423
549
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
549
  if (dataoff >= section->size
1429
549
      || size > section->size - dataoff)
1430
268
    {
1431
268
      _bfd_error_handler
1432
268
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
268
   abfd);
1434
268
      return;
1435
268
    }
1436
1437
  /* Read the whole section. */
1438
281
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
146
    {
1440
146
      free (data);
1441
146
      return;
1442
146
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
4.76k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
4.69k
    {
1447
4.69k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
4.69k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
4.69k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
4.69k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
4.69k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
59
  {
1455
59
    char buffer[256 + 1];
1456
59
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
59
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
59
                (file_ptr) idd.PointerToRawData,
1464
59
                idd.SizeOfData, cvinfo, NULL))
1465
4
      {
1466
4
        struct bfd_build_id *build_id;
1467
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
4
        build_id = bfd_alloc (abfd, bidlen);
1470
4
        if (build_id)
1471
4
    {
1472
4
      build_id->size = cvinfo->SignatureLength;
1473
4
      memcpy(build_id->data, cvinfo->Signature,
1474
4
       cvinfo->SignatureLength);
1475
4
      abfd->build_id = build_id;
1476
4
    }
1477
4
      }
1478
59
    break;
1479
59
  }
1480
4.69k
    }
1481
1482
135
  free (data);
1483
135
}
1484
1485
static bfd_cleanup
1486
pe_bfd_object_p (bfd *abfd)
1487
1.40M
{
1488
1.40M
  bfd_byte buffer[6];
1489
1.40M
  struct external_DOS_hdr dos_hdr;
1490
1.40M
  struct external_PEI_IMAGE_hdr image_hdr;
1491
1.40M
  struct internal_filehdr internal_f;
1492
1.40M
  struct internal_aouthdr internal_a;
1493
1.40M
  bfd_size_type opt_hdr_size;
1494
1.40M
  file_ptr offset;
1495
1.40M
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
1.40M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
1.40M
      || bfd_read (buffer, 6, abfd) != 6)
1501
5.62k
    {
1502
5.62k
      if (bfd_get_error () != bfd_error_system_call)
1503
5.60k
  bfd_set_error (bfd_error_wrong_format);
1504
5.62k
      return NULL;
1505
5.62k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
1.39M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
12.3k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
10.3k
    return pe_ILF_object_p (abfd);
1511
1512
1.38M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
1.38M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
244k
    {
1515
244k
      if (bfd_get_error () != bfd_error_system_call)
1516
244k
  bfd_set_error (bfd_error_wrong_format);
1517
244k
      return NULL;
1518
244k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
1.14M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
772k
    {
1532
772k
      bfd_set_error (bfd_error_wrong_format);
1533
772k
      return NULL;
1534
772k
    }
1535
1536
370k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
370k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
370k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
2.33k
    {
1540
2.33k
      if (bfd_get_error () != bfd_error_system_call)
1541
2.33k
  bfd_set_error (bfd_error_wrong_format);
1542
2.33k
      return NULL;
1543
2.33k
    }
1544
1545
367k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
3.20k
    {
1547
3.20k
      bfd_set_error (bfd_error_wrong_format);
1548
3.20k
      return NULL;
1549
3.20k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
364k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
364k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
53.8k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
310k
    {
1558
310k
      bfd_set_error (bfd_error_wrong_format);
1559
310k
      return NULL;
1560
310k
    }
1561
1562
53.7k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
53.7k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
53.7k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
53.7k
  if (opt_hdr_size != 0)
1569
33.0k
    {
1570
33.0k
      bfd_size_type amt = opt_hdr_size;
1571
33.0k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
33.0k
      if (amt < sizeof (PEAOUTHDR))
1575
29.5k
  amt = sizeof (PEAOUTHDR);
1576
1577
33.0k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
33.0k
      if (opthdr == NULL)
1579
212
  return NULL;
1580
32.8k
      if (amt > opt_hdr_size)
1581
29.3k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
32.8k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
32.8k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
3.66k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
3.82k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.24k
#endif
1595
3.27k
  {
1596
3.27k
    bfd_set_error (bfd_error_wrong_format);
1597
3.27k
    return NULL;
1598
3.27k
  }
1599
4.21k
#endif
1600
1601
29.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
13.4k
    || a->SectionAlignment >= 0x80000000)
1603
16.3k
  {
1604
16.3k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
16.3k
            abfd);
1606
16.3k
    a->SectionAlignment &= -a->SectionAlignment;
1607
16.3k
    if (a->SectionAlignment >= 0x80000000)
1608
259
      a->SectionAlignment = 0x40000000;
1609
16.3k
  }
1610
1611
29.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
14.3k
    || a->FileAlignment > a->SectionAlignment)
1613
20.0k
  {
1614
20.0k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
20.0k
            abfd);
1616
20.0k
    a->FileAlignment &= -a->FileAlignment;
1617
20.0k
    if (a->FileAlignment > a->SectionAlignment)
1618
13.7k
      a->FileAlignment = a->SectionAlignment;
1619
20.0k
  }
1620
1621
29.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
16.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.21k
    }
1624
1625
50.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
50.2k
             (opt_hdr_size != 0
1627
50.2k
        ? &internal_a
1628
50.2k
        : (struct internal_aouthdr *) NULL));
1629
1630
50.2k
  if (result)
1631
33.6k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
33.6k
      pe_bfd_read_buildid(abfd);
1634
33.6k
    }
1635
1636
50.2k
  return result;
1637
53.7k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1487
125k
{
1488
125k
  bfd_byte buffer[6];
1489
125k
  struct external_DOS_hdr dos_hdr;
1490
125k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
125k
  struct internal_filehdr internal_f;
1492
125k
  struct internal_aouthdr internal_a;
1493
125k
  bfd_size_type opt_hdr_size;
1494
125k
  file_ptr offset;
1495
125k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
125k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
125k
      || bfd_read (buffer, 6, abfd) != 6)
1501
476
    {
1502
476
      if (bfd_get_error () != bfd_error_system_call)
1503
474
  bfd_set_error (bfd_error_wrong_format);
1504
476
      return NULL;
1505
476
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
124k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.38k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.15k
    return pe_ILF_object_p (abfd);
1511
1512
123k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
123k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
22.0k
    {
1515
22.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
22.0k
  bfd_set_error (bfd_error_wrong_format);
1517
22.0k
      return NULL;
1518
22.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
101k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
60.3k
    {
1532
60.3k
      bfd_set_error (bfd_error_wrong_format);
1533
60.3k
      return NULL;
1534
60.3k
    }
1535
1536
41.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
41.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
41.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
93
    {
1540
93
      if (bfd_get_error () != bfd_error_system_call)
1541
93
  bfd_set_error (bfd_error_wrong_format);
1542
93
      return NULL;
1543
93
    }
1544
1545
41.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
169
    {
1547
169
      bfd_set_error (bfd_error_wrong_format);
1548
169
      return NULL;
1549
169
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
41.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
41.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.24k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
32.8k
    {
1558
32.8k
      bfd_set_error (bfd_error_wrong_format);
1559
32.8k
      return NULL;
1560
32.8k
    }
1561
1562
8.22k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
8.22k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
8.22k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
8.22k
  if (opt_hdr_size != 0)
1569
4.05k
    {
1570
4.05k
      bfd_size_type amt = opt_hdr_size;
1571
4.05k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.05k
      if (amt < sizeof (PEAOUTHDR))
1575
3.13k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.05k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.05k
      if (opthdr == NULL)
1579
17
  return NULL;
1580
4.04k
      if (amt > opt_hdr_size)
1581
3.11k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.04k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.04k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.04k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.86k
    || a->SectionAlignment >= 0x80000000)
1603
2.22k
  {
1604
2.22k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.22k
            abfd);
1606
2.22k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.22k
    if (a->SectionAlignment >= 0x80000000)
1608
48
      a->SectionAlignment = 0x40000000;
1609
2.22k
  }
1610
1611
4.04k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.91k
    || a->FileAlignment > a->SectionAlignment)
1613
2.69k
  {
1614
2.69k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.69k
            abfd);
1616
2.69k
    a->FileAlignment &= -a->FileAlignment;
1617
2.69k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.74k
      a->FileAlignment = a->SectionAlignment;
1619
2.69k
  }
1620
1621
4.04k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.24k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.04k
    }
1624
1625
8.21k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
8.21k
             (opt_hdr_size != 0
1627
8.21k
        ? &internal_a
1628
8.21k
        : (struct internal_aouthdr *) NULL));
1629
1630
8.21k
  if (result)
1631
7.12k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
7.12k
      pe_bfd_read_buildid(abfd);
1634
7.12k
    }
1635
1636
8.21k
  return result;
1637
8.22k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1487
124k
{
1488
124k
  bfd_byte buffer[6];
1489
124k
  struct external_DOS_hdr dos_hdr;
1490
124k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
124k
  struct internal_filehdr internal_f;
1492
124k
  struct internal_aouthdr internal_a;
1493
124k
  bfd_size_type opt_hdr_size;
1494
124k
  file_ptr offset;
1495
124k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
124k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
124k
      || bfd_read (buffer, 6, abfd) != 6)
1501
476
    {
1502
476
      if (bfd_get_error () != bfd_error_system_call)
1503
474
  bfd_set_error (bfd_error_wrong_format);
1504
476
      return NULL;
1505
476
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
123k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.37k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.15k
    return pe_ILF_object_p (abfd);
1511
1512
122k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
122k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
22.0k
    {
1515
22.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
22.0k
  bfd_set_error (bfd_error_wrong_format);
1517
22.0k
      return NULL;
1518
22.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
100k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
60.3k
    {
1532
60.3k
      bfd_set_error (bfd_error_wrong_format);
1533
60.3k
      return NULL;
1534
60.3k
    }
1535
1536
40.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
40.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
40.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
93
    {
1540
93
      if (bfd_get_error () != bfd_error_system_call)
1541
93
  bfd_set_error (bfd_error_wrong_format);
1542
93
      return NULL;
1543
93
    }
1544
1545
40.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
169
    {
1547
169
      bfd_set_error (bfd_error_wrong_format);
1548
169
      return NULL;
1549
169
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
39.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
39.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.11k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
33.8k
    {
1558
33.8k
      bfd_set_error (bfd_error_wrong_format);
1559
33.8k
      return NULL;
1560
33.8k
    }
1561
1562
6.11k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.11k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.11k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.11k
  if (opt_hdr_size != 0)
1569
3.88k
    {
1570
3.88k
      bfd_size_type amt = opt_hdr_size;
1571
3.88k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.88k
      if (amt < sizeof (PEAOUTHDR))
1575
3.57k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.88k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.88k
      if (opthdr == NULL)
1579
26
  return NULL;
1580
3.85k
      if (amt > opt_hdr_size)
1581
3.55k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.85k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.85k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.85k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.14k
    || a->SectionAlignment >= 0x80000000)
1603
1.73k
  {
1604
1.73k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.73k
            abfd);
1606
1.73k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.73k
    if (a->SectionAlignment >= 0x80000000)
1608
26
      a->SectionAlignment = 0x40000000;
1609
1.73k
  }
1610
1611
3.85k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.74k
    || a->FileAlignment > a->SectionAlignment)
1613
2.59k
  {
1614
2.59k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.59k
            abfd);
1616
2.59k
    a->FileAlignment &= -a->FileAlignment;
1617
2.59k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.28k
      a->FileAlignment = a->SectionAlignment;
1619
2.59k
  }
1620
1621
3.85k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.13k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.85k
    }
1624
1625
6.08k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.08k
             (opt_hdr_size != 0
1627
6.08k
        ? &internal_a
1628
6.08k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.08k
  if (result)
1631
4.79k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
4.79k
      pe_bfd_read_buildid(abfd);
1634
4.79k
    }
1635
1636
6.08k
  return result;
1637
6.11k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1487
122k
{
1488
122k
  bfd_byte buffer[6];
1489
122k
  struct external_DOS_hdr dos_hdr;
1490
122k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
122k
  struct internal_filehdr internal_f;
1492
122k
  struct internal_aouthdr internal_a;
1493
122k
  bfd_size_type opt_hdr_size;
1494
122k
  file_ptr offset;
1495
122k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
122k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
122k
      || bfd_read (buffer, 6, abfd) != 6)
1501
476
    {
1502
476
      if (bfd_get_error () != bfd_error_system_call)
1503
474
  bfd_set_error (bfd_error_wrong_format);
1504
476
      return NULL;
1505
476
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
122k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.38k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.15k
    return pe_ILF_object_p (abfd);
1511
1512
121k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
121k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
22.0k
    {
1515
22.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
22.0k
  bfd_set_error (bfd_error_wrong_format);
1517
22.0k
      return NULL;
1518
22.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
99.0k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
58.9k
    {
1532
58.9k
      bfd_set_error (bfd_error_wrong_format);
1533
58.9k
      return NULL;
1534
58.9k
    }
1535
1536
40.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
40.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
40.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
596
    {
1540
596
      if (bfd_get_error () != bfd_error_system_call)
1541
596
  bfd_set_error (bfd_error_wrong_format);
1542
596
      return NULL;
1543
596
    }
1544
1545
39.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
730
    {
1547
730
      bfd_set_error (bfd_error_wrong_format);
1548
730
      return NULL;
1549
730
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.19k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
32.6k
    {
1558
32.6k
      bfd_set_error (bfd_error_wrong_format);
1559
32.6k
      return NULL;
1560
32.6k
    }
1561
1562
6.18k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.18k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.18k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.18k
  if (opt_hdr_size != 0)
1569
4.87k
    {
1570
4.87k
      bfd_size_type amt = opt_hdr_size;
1571
4.87k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.87k
      if (amt < sizeof (PEAOUTHDR))
1575
4.48k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.87k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.87k
      if (opthdr == NULL)
1579
11
  return NULL;
1580
4.86k
      if (amt > opt_hdr_size)
1581
4.47k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.86k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.86k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.86k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.56k
    || a->SectionAlignment >= 0x80000000)
1603
3.31k
  {
1604
3.31k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
3.31k
            abfd);
1606
3.31k
    a->SectionAlignment &= -a->SectionAlignment;
1607
3.31k
    if (a->SectionAlignment >= 0x80000000)
1608
14
      a->SectionAlignment = 0x40000000;
1609
3.31k
  }
1610
1611
4.86k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
3.07k
    || a->FileAlignment > a->SectionAlignment)
1613
3.84k
  {
1614
3.84k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
3.84k
            abfd);
1616
3.84k
    a->FileAlignment &= -a->FileAlignment;
1617
3.84k
    if (a->FileAlignment > a->SectionAlignment)
1618
2.87k
      a->FileAlignment = a->SectionAlignment;
1619
3.84k
  }
1620
1621
4.86k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.43k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.86k
    }
1624
1625
6.17k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.17k
             (opt_hdr_size != 0
1627
6.17k
        ? &internal_a
1628
6.17k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.17k
  if (result)
1631
4.66k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
4.66k
      pe_bfd_read_buildid(abfd);
1634
4.66k
    }
1635
1636
6.17k
  return result;
1637
6.18k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1487
14.9k
{
1488
14.9k
  bfd_byte buffer[6];
1489
14.9k
  struct external_DOS_hdr dos_hdr;
1490
14.9k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
14.9k
  struct internal_filehdr internal_f;
1492
14.9k
  struct internal_aouthdr internal_a;
1493
14.9k
  bfd_size_type opt_hdr_size;
1494
14.9k
  file_ptr offset;
1495
14.9k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
14.9k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
14.9k
      || bfd_read (buffer, 6, abfd) != 6)
1501
0
    {
1502
0
      if (bfd_get_error () != bfd_error_system_call)
1503
0
  bfd_set_error (bfd_error_wrong_format);
1504
0
      return NULL;
1505
0
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
14.9k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
0
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
0
    return pe_ILF_object_p (abfd);
1511
1512
14.9k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
14.9k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
0
    {
1515
0
      if (bfd_get_error () != bfd_error_system_call)
1516
0
  bfd_set_error (bfd_error_wrong_format);
1517
0
      return NULL;
1518
0
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
14.9k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
0
    {
1532
0
      bfd_set_error (bfd_error_wrong_format);
1533
0
      return NULL;
1534
0
    }
1535
1536
14.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
14.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
14.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
0
    {
1540
0
      if (bfd_get_error () != bfd_error_system_call)
1541
0
  bfd_set_error (bfd_error_wrong_format);
1542
0
      return NULL;
1543
0
    }
1544
1545
14.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
0
    {
1547
0
      bfd_set_error (bfd_error_wrong_format);
1548
0
      return NULL;
1549
0
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
14.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
14.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.21k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
10.7k
    {
1558
10.7k
      bfd_set_error (bfd_error_wrong_format);
1559
10.7k
      return NULL;
1560
10.7k
    }
1561
1562
4.20k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.20k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.20k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.20k
  if (opt_hdr_size != 0)
1569
1.91k
    {
1570
1.91k
      bfd_size_type amt = opt_hdr_size;
1571
1.91k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
1.91k
      if (amt < sizeof (PEAOUTHDR))
1575
1.83k
  amt = sizeof (PEAOUTHDR);
1576
1577
1.91k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
1.91k
      if (opthdr == NULL)
1579
20
  return NULL;
1580
1.89k
      if (amt > opt_hdr_size)
1581
1.81k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
1.89k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
1.89k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
1.89k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
849
    || a->SectionAlignment >= 0x80000000)
1603
1.06k
  {
1604
1.06k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.06k
            abfd);
1606
1.06k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.06k
    if (a->SectionAlignment >= 0x80000000)
1608
15
      a->SectionAlignment = 0x40000000;
1609
1.06k
  }
1610
1611
1.89k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
822
    || a->FileAlignment > a->SectionAlignment)
1613
1.36k
  {
1614
1.36k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.36k
            abfd);
1616
1.36k
    a->FileAlignment &= -a->FileAlignment;
1617
1.36k
    if (a->FileAlignment > a->SectionAlignment)
1618
834
      a->FileAlignment = a->SectionAlignment;
1619
1.36k
  }
1620
1621
1.89k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.17k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
1.89k
    }
1624
1625
4.18k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.18k
             (opt_hdr_size != 0
1627
4.18k
        ? &internal_a
1628
4.18k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.18k
  if (result)
1631
2.46k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.46k
      pe_bfd_read_buildid(abfd);
1634
2.46k
    }
1635
1636
4.18k
  return result;
1637
4.20k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1487
122k
{
1488
122k
  bfd_byte buffer[6];
1489
122k
  struct external_DOS_hdr dos_hdr;
1490
122k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
122k
  struct internal_filehdr internal_f;
1492
122k
  struct internal_aouthdr internal_a;
1493
122k
  bfd_size_type opt_hdr_size;
1494
122k
  file_ptr offset;
1495
122k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
122k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
122k
      || bfd_read (buffer, 6, abfd) != 6)
1501
476
    {
1502
476
      if (bfd_get_error () != bfd_error_system_call)
1503
474
  bfd_set_error (bfd_error_wrong_format);
1504
476
      return NULL;
1505
476
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
122k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.38k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.15k
    return pe_ILF_object_p (abfd);
1511
1512
121k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
121k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
22.0k
    {
1515
22.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
22.0k
  bfd_set_error (bfd_error_wrong_format);
1517
22.0k
      return NULL;
1518
22.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
98.9k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
60.3k
    {
1532
60.3k
      bfd_set_error (bfd_error_wrong_format);
1533
60.3k
      return NULL;
1534
60.3k
    }
1535
1536
38.6k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
38.6k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
38.6k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
93
    {
1540
93
      if (bfd_get_error () != bfd_error_system_call)
1541
93
  bfd_set_error (bfd_error_wrong_format);
1542
93
      return NULL;
1543
93
    }
1544
1545
38.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
169
    {
1547
169
      bfd_set_error (bfd_error_wrong_format);
1548
169
      return NULL;
1549
169
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.13k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
34.2k
    {
1558
34.2k
      bfd_set_error (bfd_error_wrong_format);
1559
34.2k
      return NULL;
1560
34.2k
    }
1561
1562
4.12k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.12k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.12k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.12k
  if (opt_hdr_size != 0)
1569
2.63k
    {
1570
2.63k
      bfd_size_type amt = opt_hdr_size;
1571
2.63k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.63k
      if (amt < sizeof (PEAOUTHDR))
1575
2.38k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.63k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.63k
      if (opthdr == NULL)
1579
19
  return NULL;
1580
2.61k
      if (amt > opt_hdr_size)
1581
2.37k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.61k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.61k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.61k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.64k
    || a->SectionAlignment >= 0x80000000)
1603
990
  {
1604
990
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
990
            abfd);
1606
990
    a->SectionAlignment &= -a->SectionAlignment;
1607
990
    if (a->SectionAlignment >= 0x80000000)
1608
18
      a->SectionAlignment = 0x40000000;
1609
990
  }
1610
1611
2.61k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.33k
    || a->FileAlignment > a->SectionAlignment)
1613
1.54k
  {
1614
1.54k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.54k
            abfd);
1616
1.54k
    a->FileAlignment &= -a->FileAlignment;
1617
1.54k
    if (a->FileAlignment > a->SectionAlignment)
1618
916
      a->FileAlignment = a->SectionAlignment;
1619
1.54k
  }
1620
1621
2.61k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.43k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.61k
    }
1624
1625
4.10k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.10k
             (opt_hdr_size != 0
1627
4.10k
        ? &internal_a
1628
4.10k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.10k
  if (result)
1631
2.53k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.53k
      pe_bfd_read_buildid(abfd);
1634
2.53k
    }
1635
1636
4.10k
  return result;
1637
4.12k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1487
122k
{
1488
122k
  bfd_byte buffer[6];
1489
122k
  struct external_DOS_hdr dos_hdr;
1490
122k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
122k
  struct internal_filehdr internal_f;
1492
122k
  struct internal_aouthdr internal_a;
1493
122k
  bfd_size_type opt_hdr_size;
1494
122k
  file_ptr offset;
1495
122k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
122k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
122k
      || bfd_read (buffer, 6, abfd) != 6)
1501
476
    {
1502
476
      if (bfd_get_error () != bfd_error_system_call)
1503
474
  bfd_set_error (bfd_error_wrong_format);
1504
476
      return NULL;
1505
476
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
122k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.38k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.16k
    return pe_ILF_object_p (abfd);
1511
1512
121k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
121k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
22.0k
    {
1515
22.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
22.0k
  bfd_set_error (bfd_error_wrong_format);
1517
22.0k
      return NULL;
1518
22.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
99.1k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
60.3k
    {
1532
60.3k
      bfd_set_error (bfd_error_wrong_format);
1533
60.3k
      return NULL;
1534
60.3k
    }
1535
1536
38.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
38.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
38.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
93
    {
1540
93
      if (bfd_get_error () != bfd_error_system_call)
1541
93
  bfd_set_error (bfd_error_wrong_format);
1542
93
      return NULL;
1543
93
    }
1544
1545
38.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
169
    {
1547
169
      bfd_set_error (bfd_error_wrong_format);
1548
169
      return NULL;
1549
169
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.5k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.5k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.72k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
33.8k
    {
1558
33.8k
      bfd_set_error (bfd_error_wrong_format);
1559
33.8k
      return NULL;
1560
33.8k
    }
1561
1562
4.70k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.70k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.70k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.70k
  if (opt_hdr_size != 0)
1569
3.58k
    {
1570
3.58k
      bfd_size_type amt = opt_hdr_size;
1571
3.58k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.58k
      if (amt < sizeof (PEAOUTHDR))
1575
3.06k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.58k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.58k
      if (opthdr == NULL)
1579
18
  return NULL;
1580
3.56k
      if (amt > opt_hdr_size)
1581
3.04k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.56k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.56k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.56k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.92k
    || a->SectionAlignment >= 0x80000000)
1603
1.67k
  {
1604
1.67k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.67k
            abfd);
1606
1.67k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.67k
    if (a->SectionAlignment >= 0x80000000)
1608
26
      a->SectionAlignment = 0x40000000;
1609
1.67k
  }
1610
1611
3.56k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.52k
    || a->FileAlignment > a->SectionAlignment)
1613
2.30k
  {
1614
2.30k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.30k
            abfd);
1616
2.30k
    a->FileAlignment &= -a->FileAlignment;
1617
2.30k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.46k
      a->FileAlignment = a->SectionAlignment;
1619
2.30k
  }
1620
1621
3.56k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.16k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.56k
    }
1624
1625
4.69k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.69k
             (opt_hdr_size != 0
1627
4.69k
        ? &internal_a
1628
4.69k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.69k
  if (result)
1631
2.98k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.98k
      pe_bfd_read_buildid(abfd);
1634
2.98k
    }
1635
1636
4.69k
  return result;
1637
4.70k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1487
219k
{
1488
219k
  bfd_byte buffer[6];
1489
219k
  struct external_DOS_hdr dos_hdr;
1490
219k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
219k
  struct internal_filehdr internal_f;
1492
219k
  struct internal_aouthdr internal_a;
1493
219k
  bfd_size_type opt_hdr_size;
1494
219k
  file_ptr offset;
1495
219k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
219k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
219k
      || bfd_read (buffer, 6, abfd) != 6)
1501
929
    {
1502
929
      if (bfd_get_error () != bfd_error_system_call)
1503
925
  bfd_set_error (bfd_error_wrong_format);
1504
929
      return NULL;
1505
929
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
218k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.36k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.14k
    return pe_ILF_object_p (abfd);
1511
1512
217k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
217k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
38.5k
    {
1515
38.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
38.5k
  bfd_set_error (bfd_error_wrong_format);
1517
38.5k
      return NULL;
1518
38.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
178k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
139k
    {
1532
139k
      bfd_set_error (bfd_error_wrong_format);
1533
139k
      return NULL;
1534
139k
    }
1535
1536
39.5k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
39.5k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
39.5k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
592
    {
1540
592
      if (bfd_get_error () != bfd_error_system_call)
1541
592
  bfd_set_error (bfd_error_wrong_format);
1542
592
      return NULL;
1543
592
    }
1544
1545
38.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
728
    {
1547
728
      bfd_set_error (bfd_error_wrong_format);
1548
728
      return NULL;
1549
728
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.26k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
32.0k
    {
1558
32.0k
      bfd_set_error (bfd_error_wrong_format);
1559
32.0k
      return NULL;
1560
32.0k
    }
1561
1562
6.22k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.22k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.22k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.22k
  if (opt_hdr_size != 0)
1569
3.68k
    {
1570
3.68k
      bfd_size_type amt = opt_hdr_size;
1571
3.68k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.68k
      if (amt < sizeof (PEAOUTHDR))
1575
3.33k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.68k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.68k
      if (opthdr == NULL)
1579
27
  return NULL;
1580
3.66k
      if (amt > opt_hdr_size)
1581
3.31k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.66k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.66k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
3.66k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
3.66k
#ifdef WINCE
1591
3.66k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
2.02k
  {
1596
2.02k
    bfd_set_error (bfd_error_wrong_format);
1597
2.02k
    return NULL;
1598
2.02k
  }
1599
1.63k
#endif
1600
1601
1.63k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
294
    || a->SectionAlignment >= 0x80000000)
1603
1.37k
  {
1604
1.37k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.37k
            abfd);
1606
1.37k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.37k
    if (a->SectionAlignment >= 0x80000000)
1608
36
      a->SectionAlignment = 0x40000000;
1609
1.37k
  }
1610
1611
1.63k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
389
    || a->FileAlignment > a->SectionAlignment)
1613
1.44k
  {
1614
1.44k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.44k
            abfd);
1616
1.44k
    a->FileAlignment &= -a->FileAlignment;
1617
1.44k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.20k
      a->FileAlignment = a->SectionAlignment;
1619
1.44k
  }
1620
1621
1.63k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.27k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
1.63k
    }
1624
1625
4.17k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.17k
             (opt_hdr_size != 0
1627
4.17k
        ? &internal_a
1628
4.17k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.17k
  if (result)
1631
1.84k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
1.84k
      pe_bfd_read_buildid(abfd);
1634
1.84k
    }
1635
1636
4.17k
  return result;
1637
6.22k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1487
219k
{
1488
219k
  bfd_byte buffer[6];
1489
219k
  struct external_DOS_hdr dos_hdr;
1490
219k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
219k
  struct internal_filehdr internal_f;
1492
219k
  struct internal_aouthdr internal_a;
1493
219k
  bfd_size_type opt_hdr_size;
1494
219k
  file_ptr offset;
1495
219k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
219k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
219k
      || bfd_read (buffer, 6, abfd) != 6)
1501
929
    {
1502
929
      if (bfd_get_error () != bfd_error_system_call)
1503
925
  bfd_set_error (bfd_error_wrong_format);
1504
929
      return NULL;
1505
929
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
218k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.36k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.14k
    return pe_ILF_object_p (abfd);
1511
1512
217k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
217k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
38.5k
    {
1515
38.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
38.5k
  bfd_set_error (bfd_error_wrong_format);
1517
38.5k
      return NULL;
1518
38.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
178k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
139k
    {
1532
139k
      bfd_set_error (bfd_error_wrong_format);
1533
139k
      return NULL;
1534
139k
    }
1535
1536
39.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
39.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
39.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
592
    {
1540
592
      if (bfd_get_error () != bfd_error_system_call)
1541
592
  bfd_set_error (bfd_error_wrong_format);
1542
592
      return NULL;
1543
592
    }
1544
1545
39.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
728
    {
1547
728
      bfd_set_error (bfd_error_wrong_format);
1548
728
      return NULL;
1549
728
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.42k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
32.0k
    {
1558
32.0k
      bfd_set_error (bfd_error_wrong_format);
1559
32.0k
      return NULL;
1560
32.0k
    }
1561
1562
6.38k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.38k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.38k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.38k
  if (opt_hdr_size != 0)
1569
3.84k
    {
1570
3.84k
      bfd_size_type amt = opt_hdr_size;
1571
3.84k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.84k
      if (amt < sizeof (PEAOUTHDR))
1575
3.50k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.84k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.84k
      if (opthdr == NULL)
1579
27
  return NULL;
1580
3.82k
      if (amt > opt_hdr_size)
1581
3.47k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.82k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.82k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
3.82k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
3.82k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.24k
#endif
1595
1.24k
  {
1596
1.24k
    bfd_set_error (bfd_error_wrong_format);
1597
1.24k
    return NULL;
1598
1.24k
  }
1599
2.58k
#endif
1600
1601
2.58k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.03k
    || a->SectionAlignment >= 0x80000000)
1603
1.58k
  {
1604
1.58k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.58k
            abfd);
1606
1.58k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.58k
    if (a->SectionAlignment >= 0x80000000)
1608
34
      a->SectionAlignment = 0x40000000;
1609
1.58k
  }
1610
1611
2.58k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.29k
    || a->FileAlignment > a->SectionAlignment)
1613
1.53k
  {
1614
1.53k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.53k
            abfd);
1616
1.53k
    a->FileAlignment &= -a->FileAlignment;
1617
1.53k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.24k
      a->FileAlignment = a->SectionAlignment;
1619
1.53k
  }
1620
1621
2.58k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.45k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.58k
    }
1624
1625
5.12k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.12k
             (opt_hdr_size != 0
1627
5.12k
        ? &internal_a
1628
5.12k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.12k
  if (result)
1631
2.53k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.53k
      pe_bfd_read_buildid(abfd);
1634
2.53k
    }
1635
1636
5.12k
  return result;
1637
6.38k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1487
219k
{
1488
219k
  bfd_byte buffer[6];
1489
219k
  struct external_DOS_hdr dos_hdr;
1490
219k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
219k
  struct internal_filehdr internal_f;
1492
219k
  struct internal_aouthdr internal_a;
1493
219k
  bfd_size_type opt_hdr_size;
1494
219k
  file_ptr offset;
1495
219k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
219k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
219k
      || bfd_read (buffer, 6, abfd) != 6)
1501
929
    {
1502
929
      if (bfd_get_error () != bfd_error_system_call)
1503
925
  bfd_set_error (bfd_error_wrong_format);
1504
929
      return NULL;
1505
929
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
218k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.36k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.14k
    return pe_ILF_object_p (abfd);
1511
1512
217k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
217k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
38.5k
    {
1515
38.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
38.5k
  bfd_set_error (bfd_error_wrong_format);
1517
38.5k
      return NULL;
1518
38.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
178k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
140k
    {
1532
140k
      bfd_set_error (bfd_error_wrong_format);
1533
140k
      return NULL;
1534
140k
    }
1535
1536
38.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
38.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
38.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
94
    {
1540
94
      if (bfd_get_error () != bfd_error_system_call)
1541
94
  bfd_set_error (bfd_error_wrong_format);
1542
94
      return NULL;
1543
94
    }
1544
1545
38.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
170
    {
1547
170
      bfd_set_error (bfd_error_wrong_format);
1548
170
      return NULL;
1549
170
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
3.76k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
34.3k
    {
1558
34.3k
      bfd_set_error (bfd_error_wrong_format);
1559
34.3k
      return NULL;
1560
34.3k
    }
1561
1562
3.75k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
3.75k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
3.75k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
3.75k
  if (opt_hdr_size != 0)
1569
2.21k
    {
1570
2.21k
      bfd_size_type amt = opt_hdr_size;
1571
2.21k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.21k
      if (amt < sizeof (PEAOUTHDR))
1575
2.03k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.21k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.21k
      if (opthdr == NULL)
1579
21
  return NULL;
1580
2.18k
      if (amt > opt_hdr_size)
1581
2.02k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.18k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.18k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.18k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
986
    || a->SectionAlignment >= 0x80000000)
1603
1.23k
  {
1604
1.23k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.23k
            abfd);
1606
1.23k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.23k
    if (a->SectionAlignment >= 0x80000000)
1608
32
      a->SectionAlignment = 0x40000000;
1609
1.23k
  }
1610
1611
2.18k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.15k
    || a->FileAlignment > a->SectionAlignment)
1613
1.23k
  {
1614
1.23k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.23k
            abfd);
1616
1.23k
    a->FileAlignment &= -a->FileAlignment;
1617
1.23k
    if (a->FileAlignment > a->SectionAlignment)
1618
995
      a->FileAlignment = a->SectionAlignment;
1619
1.23k
  }
1620
1621
2.18k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.19k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.18k
    }
1624
1625
3.73k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
3.73k
             (opt_hdr_size != 0
1627
3.73k
        ? &internal_a
1628
3.73k
        : (struct internal_aouthdr *) NULL));
1629
1630
3.73k
  if (result)
1631
2.29k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.29k
      pe_bfd_read_buildid(abfd);
1634
2.29k
    }
1635
1636
3.73k
  return result;
1637
3.75k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1487
112k
{
1488
112k
  bfd_byte buffer[6];
1489
112k
  struct external_DOS_hdr dos_hdr;
1490
112k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
112k
  struct internal_filehdr internal_f;
1492
112k
  struct internal_aouthdr internal_a;
1493
112k
  bfd_size_type opt_hdr_size;
1494
112k
  file_ptr offset;
1495
112k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
112k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
112k
      || bfd_read (buffer, 6, abfd) != 6)
1501
461
    {
1502
461
      if (bfd_get_error () != bfd_error_system_call)
1503
459
  bfd_set_error (bfd_error_wrong_format);
1504
461
      return NULL;
1505
461
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
111k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
1.36k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.15k
    return pe_ILF_object_p (abfd);
1511
1512
110k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
110k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
18.7k
    {
1515
18.7k
      if (bfd_get_error () != bfd_error_system_call)
1516
18.7k
  bfd_set_error (bfd_error_wrong_format);
1517
18.7k
      return NULL;
1518
18.7k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
91.7k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
53.3k
    {
1532
53.3k
      bfd_set_error (bfd_error_wrong_format);
1533
53.3k
      return NULL;
1534
53.3k
    }
1535
1536
38.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
38.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
38.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
93
    {
1540
93
      if (bfd_get_error () != bfd_error_system_call)
1541
93
  bfd_set_error (bfd_error_wrong_format);
1542
93
      return NULL;
1543
93
    }
1544
1545
38.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
169
    {
1547
169
      bfd_set_error (bfd_error_wrong_format);
1548
169
      return NULL;
1549
169
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
38.1k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
38.1k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
3.79k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
34.3k
    {
1558
34.3k
      bfd_set_error (bfd_error_wrong_format);
1559
34.3k
      return NULL;
1560
34.3k
    }
1561
1562
3.78k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
3.78k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
3.78k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
3.78k
  if (opt_hdr_size != 0)
1569
2.36k
    {
1570
2.36k
      bfd_size_type amt = opt_hdr_size;
1571
2.36k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.36k
      if (amt < sizeof (PEAOUTHDR))
1575
2.19k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.36k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.36k
      if (opthdr == NULL)
1579
26
  return NULL;
1580
2.33k
      if (amt > opt_hdr_size)
1581
2.17k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.33k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.33k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.33k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.17k
    || a->SectionAlignment >= 0x80000000)
1603
1.17k
  {
1604
1.17k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.17k
            abfd);
1606
1.17k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.17k
    if (a->SectionAlignment >= 0x80000000)
1608
10
      a->SectionAlignment = 0x40000000;
1609
1.17k
  }
1610
1611
2.33k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.10k
    || a->FileAlignment > a->SectionAlignment)
1613
1.46k
  {
1614
1.46k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.46k
            abfd);
1616
1.46k
    a->FileAlignment &= -a->FileAlignment;
1617
1.46k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.17k
      a->FileAlignment = a->SectionAlignment;
1619
1.46k
  }
1620
1621
2.33k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.35k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.33k
    }
1624
1625
3.75k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
3.75k
             (opt_hdr_size != 0
1627
3.75k
        ? &internal_a
1628
3.75k
        : (struct internal_aouthdr *) NULL));
1629
1630
3.75k
  if (result)
1631
2.41k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.41k
      pe_bfd_read_buildid(abfd);
1634
2.41k
    }
1635
1636
3.75k
  return result;
1637
3.78k
}
1638
1639
14.9k
#define coff_object_p pe_bfd_object_p
1640
#endif /* COFF_IMAGE_WITH_PE */