Coverage Report

Created: 2023-06-29 07:05

/src/binutils-gdb/bfd/peicode.h
Line
Count
Source (jump to first uncovered line)
1
/* Support for the generic parts of PE/PEI, for BFD.
2
   Copyright (C) 1995-2023 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
/* This structure contains static variables used by the ILF code.  */
86
typedef asection * asection_ptr;
87
88
typedef struct
89
{
90
  bfd *     abfd;
91
  bfd_byte *    data;
92
  struct bfd_in_memory * bim;
93
  unsigned short  magic;
94
95
  arelent *   reltab;
96
  unsigned int    relcount;
97
98
  coff_symbol_type *  sym_cache;
99
  coff_symbol_type *  sym_ptr;
100
  unsigned int    sym_index;
101
102
  unsigned int *  sym_table;
103
  unsigned int *  table_ptr;
104
105
  combined_entry_type * native_syms;
106
  combined_entry_type * native_ptr;
107
108
  coff_symbol_type ** sym_ptr_table;
109
  coff_symbol_type ** sym_ptr_ptr;
110
111
  unsigned int    sec_index;
112
113
  char *    string_table;
114
  char *    string_ptr;
115
  char *    end_string_ptr;
116
117
  SYMENT *    esym_table;
118
  SYMENT *    esym_ptr;
119
120
  struct internal_reloc * int_reltab;
121
}
122
pe_ILF_vars;
123
#endif /* COFF_IMAGE_WITH_PE */
124
125
bfd_cleanup coff_real_object_p
126
  (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *);
127

128
#ifndef NO_COFF_RELOCS
129
static void
130
coff_swap_reloc_in (bfd * abfd, void * src, void * dst)
131
30.9k
{
132
30.9k
  RELOC *reloc_src = (RELOC *) src;
133
30.9k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
30.9k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
30.9k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
30.9k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
18.5k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
30.9k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
990
{
132
990
  RELOC *reloc_src = (RELOC *) src;
133
990
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
990
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
990
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
990
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
990
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
62
{
132
62
  RELOC *reloc_src = (RELOC *) src;
133
62
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
62
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
62
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
62
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
62
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
184
{
132
184
  RELOC *reloc_src = (RELOC *) src;
133
184
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
184
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
184
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
184
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
184
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
576
{
132
576
  RELOC *reloc_src = (RELOC *) src;
133
576
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
576
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
576
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
576
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
576
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
112
{
132
112
  RELOC *reloc_src = (RELOC *) src;
133
112
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
112
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
112
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
112
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
112
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
6.85k
{
132
6.85k
  RELOC *reloc_src = (RELOC *) src;
133
6.85k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
6.85k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
6.85k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
6.85k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
6.85k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
108
{
132
108
  RELOC *reloc_src = (RELOC *) src;
133
108
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
108
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
108
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
108
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
108
#ifdef SWAP_IN_RELOC_OFFSET
139
108
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
108
#endif
141
108
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
126
{
132
126
  RELOC *reloc_src = (RELOC *) src;
133
126
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
126
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
126
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
126
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
126
#ifdef SWAP_IN_RELOC_OFFSET
139
126
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
126
#endif
141
126
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
126
{
132
126
  RELOC *reloc_src = (RELOC *) src;
133
126
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
126
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
126
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
126
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
126
#ifdef SWAP_IN_RELOC_OFFSET
139
126
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
126
#endif
141
126
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
68
{
132
68
  RELOC *reloc_src = (RELOC *) src;
133
68
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
68
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
68
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
68
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
68
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
1.54k
{
132
1.54k
  RELOC *reloc_src = (RELOC *) src;
133
1.54k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.54k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.54k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.54k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
1.54k
#ifdef SWAP_IN_RELOC_OFFSET
139
1.54k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
1.54k
#endif
141
1.54k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
1.06k
{
132
1.06k
  RELOC *reloc_src = (RELOC *) src;
133
1.06k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.06k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.06k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.06k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.06k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
6.83k
{
132
6.83k
  RELOC *reloc_src = (RELOC *) src;
133
6.83k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
6.83k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
6.83k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
6.83k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
6.83k
#ifdef SWAP_IN_RELOC_OFFSET
139
6.83k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
6.83k
#endif
141
6.83k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
3.95k
{
132
3.95k
  RELOC *reloc_src = (RELOC *) src;
133
3.95k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
3.95k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
3.95k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
3.95k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
3.95k
#ifdef SWAP_IN_RELOC_OFFSET
139
3.95k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
3.95k
#endif
141
3.95k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
5.87k
{
132
5.87k
  RELOC *reloc_src = (RELOC *) src;
133
5.87k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
5.87k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
5.87k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
5.87k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
5.87k
#ifdef SWAP_IN_RELOC_OFFSET
139
5.87k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
5.87k
#endif
141
5.87k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
2.50k
{
132
2.50k
  RELOC *reloc_src = (RELOC *) src;
133
2.50k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.50k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.50k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.50k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
2.50k
}
142
143
static unsigned int
144
coff_swap_reloc_out (bfd * abfd, void * src, void * dst)
145
0
{
146
0
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
147
0
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
148
149
0
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
150
0
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
151
0
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
152
153
#ifdef SWAP_OUT_RELOC_OFFSET
154
0
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
155
#endif
156
#ifdef SWAP_OUT_RELOC_EXTRA
157
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
158
#endif
159
0
  return RELSZ;
160
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: pei-aarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-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: 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
161
#endif /* not NO_COFF_RELOCS */
162
163
#ifdef COFF_IMAGE_WITH_PE
164
#undef FILHDR
165
664k
#define FILHDR struct external_PEI_IMAGE_hdr
166
#endif
167
168
static void
169
coff_swap_filehdr_in (bfd * abfd, void * src, void * dst)
170
1.81M
{
171
1.81M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.81M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.81M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.81M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.81M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.81M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.81M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.81M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.81M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
389k
    {
185
389k
      filehdr_dst->f_nsyms = 0;
186
389k
      filehdr_dst->f_flags |= F_LSYMS;
187
389k
    }
188
189
1.81M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.81M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
114k
{
171
114k
  FILHDR *filehdr_src = (FILHDR *) src;
172
114k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
114k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
114k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
114k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
114k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
114k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
114k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
114k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
16.6k
    {
185
16.6k
      filehdr_dst->f_nsyms = 0;
186
16.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
16.6k
    }
188
189
114k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
114k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
114k
{
171
114k
  FILHDR *filehdr_src = (FILHDR *) src;
172
114k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
114k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
114k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
114k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
114k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
114k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
114k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
114k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
16.6k
    {
185
16.6k
      filehdr_dst->f_nsyms = 0;
186
16.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
16.6k
    }
188
189
114k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
114k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
71.9k
{
171
71.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
71.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
71.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
71.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
71.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
71.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
71.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
71.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
71.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.4k
    {
185
24.4k
      filehdr_dst->f_nsyms = 0;
186
24.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.4k
    }
188
189
71.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
71.9k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
73.9k
{
171
73.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
73.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
73.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
73.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
73.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
73.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
73.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
73.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
73.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
73.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
73.9k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
229k
{
171
229k
  FILHDR *filehdr_src = (FILHDR *) src;
172
229k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
229k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
229k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
229k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
229k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
229k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
229k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
229k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
33.3k
    {
185
33.3k
      filehdr_dst->f_nsyms = 0;
186
33.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
33.3k
    }
188
189
229k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
229k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
229k
{
171
229k
  FILHDR *filehdr_src = (FILHDR *) src;
172
229k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
229k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
229k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
229k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
229k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
229k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
229k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
229k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
33.3k
    {
185
33.3k
      filehdr_dst->f_nsyms = 0;
186
33.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
33.3k
    }
188
189
229k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
229k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
114k
{
171
114k
  FILHDR *filehdr_src = (FILHDR *) src;
172
114k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
114k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
114k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
114k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
114k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
114k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
114k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
114k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
16.6k
    {
185
16.6k
      filehdr_dst->f_nsyms = 0;
186
16.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
16.6k
    }
188
189
114k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
114k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
229k
{
171
229k
  FILHDR *filehdr_src = (FILHDR *) src;
172
229k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
229k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
229k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
229k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
229k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
229k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
229k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
229k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
33.3k
    {
185
33.3k
      filehdr_dst->f_nsyms = 0;
186
33.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
33.3k
    }
188
189
229k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
229k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
114k
{
171
114k
  FILHDR *filehdr_src = (FILHDR *) src;
172
114k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
114k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
114k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
114k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
114k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
114k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
114k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
114k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
16.6k
    {
185
16.6k
      filehdr_dst->f_nsyms = 0;
186
16.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
16.6k
    }
188
189
114k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
114k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
74.0k
{
171
74.0k
  FILHDR *filehdr_src = (FILHDR *) src;
172
74.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
74.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
74.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
74.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
74.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
74.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
74.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
74.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
24.8k
    {
185
24.8k
      filehdr_dst->f_nsyms = 0;
186
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
24.8k
    }
188
189
74.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
74.0k
}
191
192
#ifdef COFF_IMAGE_WITH_PE
193
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
194
#elif defined COFF_WITH_peAArch64
195
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
196
#elif defined COFF_WITH_pex64
197
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
198
#elif defined COFF_WITH_pep
199
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
200
#else
201
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
202
#endif
203
204
static void
205
coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
206
891k
{
207
891k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
891k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
891k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
891k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
891k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
891k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
891k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
891k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
891k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
891k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
756k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
756k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
134k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
134k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
891k
  if (scnhdr_int->s_vaddr != 0)
233
175k
    {
234
175k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
175k
    }
240
241
891k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
891k
  if (scnhdr_int->s_paddr > 0
247
891k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
170k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
170k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
37.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
891k
#endif
256
891k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
12.0k
{
207
12.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
12.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
12.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
12.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
12.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
12.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
12.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
12.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
12.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
12.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
12.0k
#ifdef COFF_IMAGE_WITH_PE
224
12.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
12.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
12.0k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
12.0k
  if (scnhdr_int->s_vaddr != 0)
233
4.95k
    {
234
4.95k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
4.95k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
4.95k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
4.95k
#endif
239
4.95k
    }
240
241
12.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
12.0k
  if (scnhdr_int->s_paddr > 0
247
12.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
6.46k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
6.46k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
2.20k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
12.0k
#endif
256
12.0k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
86.6k
{
207
86.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
86.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
86.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
86.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
86.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
86.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
86.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
86.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
86.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
86.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
86.6k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
86.6k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
86.6k
#endif
231
232
86.6k
  if (scnhdr_int->s_vaddr != 0)
233
14.7k
    {
234
14.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
14.7k
    }
240
241
86.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
86.6k
  if (scnhdr_int->s_paddr > 0
247
86.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
14.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
14.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
486
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
86.6k
#endif
256
86.6k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
3.22k
{
207
3.22k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
3.22k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
3.22k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
3.22k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
3.22k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
3.22k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
3.22k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
3.22k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
3.22k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
3.22k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
3.22k
#ifdef COFF_IMAGE_WITH_PE
224
3.22k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
3.22k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
3.22k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
3.22k
  if (scnhdr_int->s_vaddr != 0)
233
1.60k
    {
234
1.60k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
1.60k
    }
240
241
3.22k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
3.22k
  if (scnhdr_int->s_paddr > 0
247
3.22k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.50k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.50k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
312
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
3.22k
#endif
256
3.22k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
9.94k
{
207
9.94k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
9.94k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
9.94k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
9.94k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
9.94k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
9.94k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
9.94k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
9.94k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
9.94k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
9.94k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
9.94k
#ifdef COFF_IMAGE_WITH_PE
224
9.94k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
9.94k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
9.94k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
9.94k
  if (scnhdr_int->s_vaddr != 0)
233
5.43k
    {
234
5.43k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
5.43k
    }
240
241
9.94k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
9.94k
  if (scnhdr_int->s_paddr > 0
247
9.94k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
5.39k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
5.39k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.67k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
9.94k
#endif
256
9.94k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
4.02k
{
207
4.02k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
4.02k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
4.02k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
4.02k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
4.02k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
4.02k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
4.02k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
4.02k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
4.02k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
4.02k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
4.02k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
4.02k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
4.02k
#endif
231
232
4.02k
  if (scnhdr_int->s_vaddr != 0)
233
1.07k
    {
234
1.07k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
1.07k
    }
240
241
4.02k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
4.02k
  if (scnhdr_int->s_paddr > 0
247
4.02k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.46k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.46k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
168
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
4.02k
#endif
256
4.02k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
98.0k
{
207
98.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
98.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
98.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
98.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
98.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
98.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
98.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
98.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
98.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
98.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
98.0k
#ifdef COFF_IMAGE_WITH_PE
224
98.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
98.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
98.0k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
98.0k
  if (scnhdr_int->s_vaddr != 0)
233
41.4k
    {
234
41.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
41.4k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
41.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
41.4k
#endif
239
41.4k
    }
240
241
98.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
98.0k
  if (scnhdr_int->s_paddr > 0
247
98.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
40.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
40.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
10.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
98.0k
#endif
256
98.0k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.08k
{
207
2.08k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.08k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.08k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.08k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.08k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.08k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.08k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.08k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.08k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.08k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
2.08k
#ifdef COFF_IMAGE_WITH_PE
224
2.08k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
2.08k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
2.08k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
2.08k
  if (scnhdr_int->s_vaddr != 0)
233
1.14k
    {
234
1.14k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
1.14k
    }
240
241
2.08k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
2.08k
  if (scnhdr_int->s_paddr > 0
247
2.08k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.15k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.15k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
262
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.08k
#endif
256
2.08k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.73k
{
207
2.73k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.73k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.73k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.73k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.73k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.73k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.73k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.73k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.73k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.73k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
2.73k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
2.73k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
2.73k
#endif
231
232
2.73k
  if (scnhdr_int->s_vaddr != 0)
233
1.95k
    {
234
1.95k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
1.95k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
1.95k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
1.95k
#endif
239
1.95k
    }
240
241
2.73k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
2.73k
  if (scnhdr_int->s_paddr > 0
247
2.73k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.91k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.91k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
618
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.73k
#endif
256
2.73k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.73k
{
207
2.73k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.73k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.73k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.73k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.73k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.73k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.73k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.73k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.73k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.73k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
2.73k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
2.73k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
2.73k
#endif
231
232
2.73k
  if (scnhdr_int->s_vaddr != 0)
233
1.95k
    {
234
1.95k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
1.95k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
1.95k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
1.95k
#endif
239
1.95k
    }
240
241
2.73k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
2.73k
  if (scnhdr_int->s_paddr > 0
247
2.73k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.91k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.91k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
618
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.73k
#endif
256
2.73k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
3.95k
{
207
3.95k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
3.95k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
3.95k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
3.95k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
3.95k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
3.95k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
3.95k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
3.95k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
3.95k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
3.95k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
3.95k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
3.95k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
3.95k
#endif
231
232
3.95k
  if (scnhdr_int->s_vaddr != 0)
233
1.69k
    {
234
1.69k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
1.69k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
1.69k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
1.69k
#endif
239
1.69k
    }
240
241
3.95k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
3.95k
  if (scnhdr_int->s_paddr > 0
247
3.95k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.63k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.63k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
446
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
3.95k
#endif
256
3.95k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
23.1k
{
207
23.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
23.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
23.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
23.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
23.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
23.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
23.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
23.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
23.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
23.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
23.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
23.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
23.1k
#endif
231
232
23.1k
  if (scnhdr_int->s_vaddr != 0)
233
12.6k
    {
234
12.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
12.6k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
12.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
12.6k
#endif
239
12.6k
    }
240
241
23.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
23.1k
  if (scnhdr_int->s_paddr > 0
247
23.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
10.8k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
10.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
892
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
23.1k
#endif
256
23.1k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
11.7k
{
207
11.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
11.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
11.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
11.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
11.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
11.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
11.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
11.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
11.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
11.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
11.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
11.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
11.7k
#endif
231
232
11.7k
  if (scnhdr_int->s_vaddr != 0)
233
3.59k
    {
234
3.59k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
3.59k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
3.59k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
3.59k
#endif
239
3.59k
    }
240
241
11.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
11.7k
  if (scnhdr_int->s_paddr > 0
247
11.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
2.90k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
2.90k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
664
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
11.7k
#endif
256
11.7k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
38.9k
{
207
38.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
38.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
38.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
38.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
38.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
38.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
38.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
38.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
38.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
38.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
38.9k
#ifdef COFF_IMAGE_WITH_PE
224
38.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
38.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
38.9k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
38.9k
  if (scnhdr_int->s_vaddr != 0)
233
16.5k
    {
234
16.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
16.5k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
16.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
16.5k
#endif
239
16.5k
    }
240
241
38.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
38.9k
  if (scnhdr_int->s_paddr > 0
247
38.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
19.8k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
19.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
3.12k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
38.9k
#endif
256
38.9k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
480k
{
207
480k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
480k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
480k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
480k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
480k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
480k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
480k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
480k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
480k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
480k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
480k
#ifdef COFF_IMAGE_WITH_PE
224
480k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
480k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
480k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
480k
  if (scnhdr_int->s_vaddr != 0)
233
35.8k
    {
234
35.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
35.8k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
35.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
35.8k
#endif
239
35.8k
    }
240
241
480k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
480k
  if (scnhdr_int->s_paddr > 0
247
480k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
31.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
31.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
4.61k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
480k
#endif
256
480k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
60.9k
{
207
60.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
60.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
60.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
60.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
60.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
60.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
60.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
60.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
60.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
60.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
60.9k
#ifdef COFF_IMAGE_WITH_PE
224
60.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
60.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
60.9k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
60.9k
  if (scnhdr_int->s_vaddr != 0)
233
17.3k
    {
234
17.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
17.3k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
17.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
17.3k
#endif
239
17.3k
    }
240
241
60.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
60.9k
  if (scnhdr_int->s_paddr > 0
247
60.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
17.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
17.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
4.53k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
60.9k
#endif
256
60.9k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
50.6k
{
207
50.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
50.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
50.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
50.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
50.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
50.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
50.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
50.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
50.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
50.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
50.6k
#ifdef COFF_IMAGE_WITH_PE
224
50.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
50.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
50.6k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
50.6k
  if (scnhdr_int->s_vaddr != 0)
233
13.7k
    {
234
13.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
13.7k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
13.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
13.7k
#endif
239
13.7k
    }
240
241
50.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
50.6k
  if (scnhdr_int->s_paddr > 0
247
50.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
12.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
12.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
6.45k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
50.6k
#endif
256
50.6k
}
257
258
static bool
259
pe_mkobject (bfd * abfd)
260
83.3k
{
261
83.3k
  pe_data_type *pe;
262
83.3k
  size_t amt = sizeof (pe_data_type);
263
264
83.3k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
83.3k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
83.3k
  pe = pe_data (abfd);
270
271
83.3k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
83.3k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
83.3k
  pe->dos_message[0]  = 0x0eba1f0e;
278
83.3k
  pe->dos_message[1]  = 0xcd09b400;
279
83.3k
  pe->dos_message[2]  = 0x4c01b821;
280
83.3k
  pe->dos_message[3]  = 0x685421cd;
281
83.3k
  pe->dos_message[4]  = 0x70207369;
282
83.3k
  pe->dos_message[5]  = 0x72676f72;
283
83.3k
  pe->dos_message[6]  = 0x63206d61;
284
83.3k
  pe->dos_message[7]  = 0x6f6e6e61;
285
83.3k
  pe->dos_message[8]  = 0x65622074;
286
83.3k
  pe->dos_message[9]  = 0x6e757220;
287
83.3k
  pe->dos_message[10] = 0x206e6920;
288
83.3k
  pe->dos_message[11] = 0x20534f44;
289
83.3k
  pe->dos_message[12] = 0x65646f6d;
290
83.3k
  pe->dos_message[13] = 0x0a0d0d2e;
291
83.3k
  pe->dos_message[14] = 0x24;
292
83.3k
  pe->dos_message[15] = 0x0;
293
294
83.3k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
83.3k
  bfd_coff_long_section_names (abfd)
297
83.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
83.3k
  return true;
300
83.3k
}
pei-i386.c:pe_mkobject
Line
Count
Source
260
5.21k
{
261
5.21k
  pe_data_type *pe;
262
5.21k
  size_t amt = sizeof (pe_data_type);
263
264
5.21k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
5.21k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
5.21k
  pe = pe_data (abfd);
270
271
5.21k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
5.21k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
5.21k
  pe->dos_message[0]  = 0x0eba1f0e;
278
5.21k
  pe->dos_message[1]  = 0xcd09b400;
279
5.21k
  pe->dos_message[2]  = 0x4c01b821;
280
5.21k
  pe->dos_message[3]  = 0x685421cd;
281
5.21k
  pe->dos_message[4]  = 0x70207369;
282
5.21k
  pe->dos_message[5]  = 0x72676f72;
283
5.21k
  pe->dos_message[6]  = 0x63206d61;
284
5.21k
  pe->dos_message[7]  = 0x6f6e6e61;
285
5.21k
  pe->dos_message[8]  = 0x65622074;
286
5.21k
  pe->dos_message[9]  = 0x6e757220;
287
5.21k
  pe->dos_message[10] = 0x206e6920;
288
5.21k
  pe->dos_message[11] = 0x20534f44;
289
5.21k
  pe->dos_message[12] = 0x65646f6d;
290
5.21k
  pe->dos_message[13] = 0x0a0d0d2e;
291
5.21k
  pe->dos_message[14] = 0x24;
292
5.21k
  pe->dos_message[15] = 0x0;
293
294
5.21k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
5.21k
  bfd_coff_long_section_names (abfd)
297
5.21k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
5.21k
  return true;
300
5.21k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
260
836
{
261
836
  pe_data_type *pe;
262
836
  size_t amt = sizeof (pe_data_type);
263
264
836
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
836
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
836
  pe = pe_data (abfd);
270
271
836
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
836
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
836
  pe->dos_message[0]  = 0x0eba1f0e;
278
836
  pe->dos_message[1]  = 0xcd09b400;
279
836
  pe->dos_message[2]  = 0x4c01b821;
280
836
  pe->dos_message[3]  = 0x685421cd;
281
836
  pe->dos_message[4]  = 0x70207369;
282
836
  pe->dos_message[5]  = 0x72676f72;
283
836
  pe->dos_message[6]  = 0x63206d61;
284
836
  pe->dos_message[7]  = 0x6f6e6e61;
285
836
  pe->dos_message[8]  = 0x65622074;
286
836
  pe->dos_message[9]  = 0x6e757220;
287
836
  pe->dos_message[10] = 0x206e6920;
288
836
  pe->dos_message[11] = 0x20534f44;
289
836
  pe->dos_message[12] = 0x65646f6d;
290
836
  pe->dos_message[13] = 0x0a0d0d2e;
291
836
  pe->dos_message[14] = 0x24;
292
836
  pe->dos_message[15] = 0x0;
293
294
836
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
836
  bfd_coff_long_section_names (abfd)
297
836
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
836
  return true;
300
836
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
260
540
{
261
540
  pe_data_type *pe;
262
540
  size_t amt = sizeof (pe_data_type);
263
264
540
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
540
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
540
  pe = pe_data (abfd);
270
271
540
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
540
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
540
  pe->dos_message[0]  = 0x0eba1f0e;
278
540
  pe->dos_message[1]  = 0xcd09b400;
279
540
  pe->dos_message[2]  = 0x4c01b821;
280
540
  pe->dos_message[3]  = 0x685421cd;
281
540
  pe->dos_message[4]  = 0x70207369;
282
540
  pe->dos_message[5]  = 0x72676f72;
283
540
  pe->dos_message[6]  = 0x63206d61;
284
540
  pe->dos_message[7]  = 0x6f6e6e61;
285
540
  pe->dos_message[8]  = 0x65622074;
286
540
  pe->dos_message[9]  = 0x6e757220;
287
540
  pe->dos_message[10] = 0x206e6920;
288
540
  pe->dos_message[11] = 0x20534f44;
289
540
  pe->dos_message[12] = 0x65646f6d;
290
540
  pe->dos_message[13] = 0x0a0d0d2e;
291
540
  pe->dos_message[14] = 0x24;
292
540
  pe->dos_message[15] = 0x0;
293
294
540
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
540
  bfd_coff_long_section_names (abfd)
297
540
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
540
  return true;
300
540
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
260
6.12k
{
261
6.12k
  pe_data_type *pe;
262
6.12k
  size_t amt = sizeof (pe_data_type);
263
264
6.12k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
6.12k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
6.12k
  pe = pe_data (abfd);
270
271
6.12k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
6.12k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
6.12k
  pe->dos_message[0]  = 0x0eba1f0e;
278
6.12k
  pe->dos_message[1]  = 0xcd09b400;
279
6.12k
  pe->dos_message[2]  = 0x4c01b821;
280
6.12k
  pe->dos_message[3]  = 0x685421cd;
281
6.12k
  pe->dos_message[4]  = 0x70207369;
282
6.12k
  pe->dos_message[5]  = 0x72676f72;
283
6.12k
  pe->dos_message[6]  = 0x63206d61;
284
6.12k
  pe->dos_message[7]  = 0x6f6e6e61;
285
6.12k
  pe->dos_message[8]  = 0x65622074;
286
6.12k
  pe->dos_message[9]  = 0x6e757220;
287
6.12k
  pe->dos_message[10] = 0x206e6920;
288
6.12k
  pe->dos_message[11] = 0x20534f44;
289
6.12k
  pe->dos_message[12] = 0x65646f6d;
290
6.12k
  pe->dos_message[13] = 0x0a0d0d2e;
291
6.12k
  pe->dos_message[14] = 0x24;
292
6.12k
  pe->dos_message[15] = 0x0;
293
294
6.12k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
6.12k
  bfd_coff_long_section_names (abfd)
297
6.12k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
6.12k
  return true;
300
6.12k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
260
1.28k
{
261
1.28k
  pe_data_type *pe;
262
1.28k
  size_t amt = sizeof (pe_data_type);
263
264
1.28k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
1.28k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
1.28k
  pe = pe_data (abfd);
270
271
1.28k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
1.28k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
1.28k
  pe->dos_message[0]  = 0x0eba1f0e;
278
1.28k
  pe->dos_message[1]  = 0xcd09b400;
279
1.28k
  pe->dos_message[2]  = 0x4c01b821;
280
1.28k
  pe->dos_message[3]  = 0x685421cd;
281
1.28k
  pe->dos_message[4]  = 0x70207369;
282
1.28k
  pe->dos_message[5]  = 0x72676f72;
283
1.28k
  pe->dos_message[6]  = 0x63206d61;
284
1.28k
  pe->dos_message[7]  = 0x6f6e6e61;
285
1.28k
  pe->dos_message[8]  = 0x65622074;
286
1.28k
  pe->dos_message[9]  = 0x6e757220;
287
1.28k
  pe->dos_message[10] = 0x206e6920;
288
1.28k
  pe->dos_message[11] = 0x20534f44;
289
1.28k
  pe->dos_message[12] = 0x65646f6d;
290
1.28k
  pe->dos_message[13] = 0x0a0d0d2e;
291
1.28k
  pe->dos_message[14] = 0x24;
292
1.28k
  pe->dos_message[15] = 0x0;
293
294
1.28k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
1.28k
  bfd_coff_long_section_names (abfd)
297
1.28k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
1.28k
  return true;
300
1.28k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
260
15.7k
{
261
15.7k
  pe_data_type *pe;
262
15.7k
  size_t amt = sizeof (pe_data_type);
263
264
15.7k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
15.7k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
15.7k
  pe = pe_data (abfd);
270
271
15.7k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
15.7k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
15.7k
  pe->dos_message[0]  = 0x0eba1f0e;
278
15.7k
  pe->dos_message[1]  = 0xcd09b400;
279
15.7k
  pe->dos_message[2]  = 0x4c01b821;
280
15.7k
  pe->dos_message[3]  = 0x685421cd;
281
15.7k
  pe->dos_message[4]  = 0x70207369;
282
15.7k
  pe->dos_message[5]  = 0x72676f72;
283
15.7k
  pe->dos_message[6]  = 0x63206d61;
284
15.7k
  pe->dos_message[7]  = 0x6f6e6e61;
285
15.7k
  pe->dos_message[8]  = 0x65622074;
286
15.7k
  pe->dos_message[9]  = 0x6e757220;
287
15.7k
  pe->dos_message[10] = 0x206e6920;
288
15.7k
  pe->dos_message[11] = 0x20534f44;
289
15.7k
  pe->dos_message[12] = 0x65646f6d;
290
15.7k
  pe->dos_message[13] = 0x0a0d0d2e;
291
15.7k
  pe->dos_message[14] = 0x24;
292
15.7k
  pe->dos_message[15] = 0x0;
293
294
15.7k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
15.7k
  bfd_coff_long_section_names (abfd)
297
15.7k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
15.7k
  return true;
300
15.7k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
260
386
{
261
386
  pe_data_type *pe;
262
386
  size_t amt = sizeof (pe_data_type);
263
264
386
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
386
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
386
  pe = pe_data (abfd);
270
271
386
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
386
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
386
  pe->dos_message[0]  = 0x0eba1f0e;
278
386
  pe->dos_message[1]  = 0xcd09b400;
279
386
  pe->dos_message[2]  = 0x4c01b821;
280
386
  pe->dos_message[3]  = 0x685421cd;
281
386
  pe->dos_message[4]  = 0x70207369;
282
386
  pe->dos_message[5]  = 0x72676f72;
283
386
  pe->dos_message[6]  = 0x63206d61;
284
386
  pe->dos_message[7]  = 0x6f6e6e61;
285
386
  pe->dos_message[8]  = 0x65622074;
286
386
  pe->dos_message[9]  = 0x6e757220;
287
386
  pe->dos_message[10] = 0x206e6920;
288
386
  pe->dos_message[11] = 0x20534f44;
289
386
  pe->dos_message[12] = 0x65646f6d;
290
386
  pe->dos_message[13] = 0x0a0d0d2e;
291
386
  pe->dos_message[14] = 0x24;
292
386
  pe->dos_message[15] = 0x0;
293
294
386
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
386
  bfd_coff_long_section_names (abfd)
297
386
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
386
  return true;
300
386
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
260
346
{
261
346
  pe_data_type *pe;
262
346
  size_t amt = sizeof (pe_data_type);
263
264
346
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
346
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
346
  pe = pe_data (abfd);
270
271
346
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
346
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
346
  pe->dos_message[0]  = 0x0eba1f0e;
278
346
  pe->dos_message[1]  = 0xcd09b400;
279
346
  pe->dos_message[2]  = 0x4c01b821;
280
346
  pe->dos_message[3]  = 0x685421cd;
281
346
  pe->dos_message[4]  = 0x70207369;
282
346
  pe->dos_message[5]  = 0x72676f72;
283
346
  pe->dos_message[6]  = 0x63206d61;
284
346
  pe->dos_message[7]  = 0x6f6e6e61;
285
346
  pe->dos_message[8]  = 0x65622074;
286
346
  pe->dos_message[9]  = 0x6e757220;
287
346
  pe->dos_message[10] = 0x206e6920;
288
346
  pe->dos_message[11] = 0x20534f44;
289
346
  pe->dos_message[12] = 0x65646f6d;
290
346
  pe->dos_message[13] = 0x0a0d0d2e;
291
346
  pe->dos_message[14] = 0x24;
292
346
  pe->dos_message[15] = 0x0;
293
294
346
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
346
  bfd_coff_long_section_names (abfd)
297
346
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
346
  return true;
300
346
}
pe-arm.c:pe_mkobject
Line
Count
Source
260
346
{
261
346
  pe_data_type *pe;
262
346
  size_t amt = sizeof (pe_data_type);
263
264
346
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
346
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
346
  pe = pe_data (abfd);
270
271
346
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
346
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
346
  pe->dos_message[0]  = 0x0eba1f0e;
278
346
  pe->dos_message[1]  = 0xcd09b400;
279
346
  pe->dos_message[2]  = 0x4c01b821;
280
346
  pe->dos_message[3]  = 0x685421cd;
281
346
  pe->dos_message[4]  = 0x70207369;
282
346
  pe->dos_message[5]  = 0x72676f72;
283
346
  pe->dos_message[6]  = 0x63206d61;
284
346
  pe->dos_message[7]  = 0x6f6e6e61;
285
346
  pe->dos_message[8]  = 0x65622074;
286
346
  pe->dos_message[9]  = 0x6e757220;
287
346
  pe->dos_message[10] = 0x206e6920;
288
346
  pe->dos_message[11] = 0x20534f44;
289
346
  pe->dos_message[12] = 0x65646f6d;
290
346
  pe->dos_message[13] = 0x0a0d0d2e;
291
346
  pe->dos_message[14] = 0x24;
292
346
  pe->dos_message[15] = 0x0;
293
294
346
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
346
  bfd_coff_long_section_names (abfd)
297
346
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
346
  return true;
300
346
}
pe-i386.c:pe_mkobject
Line
Count
Source
260
586
{
261
586
  pe_data_type *pe;
262
586
  size_t amt = sizeof (pe_data_type);
263
264
586
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
586
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
586
  pe = pe_data (abfd);
270
271
586
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
586
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
586
  pe->dos_message[0]  = 0x0eba1f0e;
278
586
  pe->dos_message[1]  = 0xcd09b400;
279
586
  pe->dos_message[2]  = 0x4c01b821;
280
586
  pe->dos_message[3]  = 0x685421cd;
281
586
  pe->dos_message[4]  = 0x70207369;
282
586
  pe->dos_message[5]  = 0x72676f72;
283
586
  pe->dos_message[6]  = 0x63206d61;
284
586
  pe->dos_message[7]  = 0x6f6e6e61;
285
586
  pe->dos_message[8]  = 0x65622074;
286
586
  pe->dos_message[9]  = 0x6e757220;
287
586
  pe->dos_message[10] = 0x206e6920;
288
586
  pe->dos_message[11] = 0x20534f44;
289
586
  pe->dos_message[12] = 0x65646f6d;
290
586
  pe->dos_message[13] = 0x0a0d0d2e;
291
586
  pe->dos_message[14] = 0x24;
292
586
  pe->dos_message[15] = 0x0;
293
294
586
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
586
  bfd_coff_long_section_names (abfd)
297
586
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
586
  return true;
300
586
}
pe-mcore.c:pe_mkobject
Line
Count
Source
260
3.95k
{
261
3.95k
  pe_data_type *pe;
262
3.95k
  size_t amt = sizeof (pe_data_type);
263
264
3.95k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
3.95k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
3.95k
  pe = pe_data (abfd);
270
271
3.95k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
3.95k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
3.95k
  pe->dos_message[0]  = 0x0eba1f0e;
278
3.95k
  pe->dos_message[1]  = 0xcd09b400;
279
3.95k
  pe->dos_message[2]  = 0x4c01b821;
280
3.95k
  pe->dos_message[3]  = 0x685421cd;
281
3.95k
  pe->dos_message[4]  = 0x70207369;
282
3.95k
  pe->dos_message[5]  = 0x72676f72;
283
3.95k
  pe->dos_message[6]  = 0x63206d61;
284
3.95k
  pe->dos_message[7]  = 0x6f6e6e61;
285
3.95k
  pe->dos_message[8]  = 0x65622074;
286
3.95k
  pe->dos_message[9]  = 0x6e757220;
287
3.95k
  pe->dos_message[10] = 0x206e6920;
288
3.95k
  pe->dos_message[11] = 0x20534f44;
289
3.95k
  pe->dos_message[12] = 0x65646f6d;
290
3.95k
  pe->dos_message[13] = 0x0a0d0d2e;
291
3.95k
  pe->dos_message[14] = 0x24;
292
3.95k
  pe->dos_message[15] = 0x0;
293
294
3.95k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
3.95k
  bfd_coff_long_section_names (abfd)
297
3.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
3.95k
  return true;
300
3.95k
}
pe-sh.c:pe_mkobject
Line
Count
Source
260
3.89k
{
261
3.89k
  pe_data_type *pe;
262
3.89k
  size_t amt = sizeof (pe_data_type);
263
264
3.89k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
3.89k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
3.89k
  pe = pe_data (abfd);
270
271
3.89k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
3.89k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
3.89k
  pe->dos_message[0]  = 0x0eba1f0e;
278
3.89k
  pe->dos_message[1]  = 0xcd09b400;
279
3.89k
  pe->dos_message[2]  = 0x4c01b821;
280
3.89k
  pe->dos_message[3]  = 0x685421cd;
281
3.89k
  pe->dos_message[4]  = 0x70207369;
282
3.89k
  pe->dos_message[5]  = 0x72676f72;
283
3.89k
  pe->dos_message[6]  = 0x63206d61;
284
3.89k
  pe->dos_message[7]  = 0x6f6e6e61;
285
3.89k
  pe->dos_message[8]  = 0x65622074;
286
3.89k
  pe->dos_message[9]  = 0x6e757220;
287
3.89k
  pe->dos_message[10] = 0x206e6920;
288
3.89k
  pe->dos_message[11] = 0x20534f44;
289
3.89k
  pe->dos_message[12] = 0x65646f6d;
290
3.89k
  pe->dos_message[13] = 0x0a0d0d2e;
291
3.89k
  pe->dos_message[14] = 0x24;
292
3.89k
  pe->dos_message[15] = 0x0;
293
294
3.89k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
3.89k
  bfd_coff_long_section_names (abfd)
297
3.89k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
3.89k
  return true;
300
3.89k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
260
11.3k
{
261
11.3k
  pe_data_type *pe;
262
11.3k
  size_t amt = sizeof (pe_data_type);
263
264
11.3k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
11.3k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
11.3k
  pe = pe_data (abfd);
270
271
11.3k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
11.3k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
11.3k
  pe->dos_message[0]  = 0x0eba1f0e;
278
11.3k
  pe->dos_message[1]  = 0xcd09b400;
279
11.3k
  pe->dos_message[2]  = 0x4c01b821;
280
11.3k
  pe->dos_message[3]  = 0x685421cd;
281
11.3k
  pe->dos_message[4]  = 0x70207369;
282
11.3k
  pe->dos_message[5]  = 0x72676f72;
283
11.3k
  pe->dos_message[6]  = 0x63206d61;
284
11.3k
  pe->dos_message[7]  = 0x6f6e6e61;
285
11.3k
  pe->dos_message[8]  = 0x65622074;
286
11.3k
  pe->dos_message[9]  = 0x6e757220;
287
11.3k
  pe->dos_message[10] = 0x206e6920;
288
11.3k
  pe->dos_message[11] = 0x20534f44;
289
11.3k
  pe->dos_message[12] = 0x65646f6d;
290
11.3k
  pe->dos_message[13] = 0x0a0d0d2e;
291
11.3k
  pe->dos_message[14] = 0x24;
292
11.3k
  pe->dos_message[15] = 0x0;
293
294
11.3k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
11.3k
  bfd_coff_long_section_names (abfd)
297
11.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
11.3k
  return true;
300
11.3k
}
pei-arm.c:pe_mkobject
Line
Count
Source
260
11.4k
{
261
11.4k
  pe_data_type *pe;
262
11.4k
  size_t amt = sizeof (pe_data_type);
263
264
11.4k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
11.4k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
11.4k
  pe = pe_data (abfd);
270
271
11.4k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
11.4k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
11.4k
  pe->dos_message[0]  = 0x0eba1f0e;
278
11.4k
  pe->dos_message[1]  = 0xcd09b400;
279
11.4k
  pe->dos_message[2]  = 0x4c01b821;
280
11.4k
  pe->dos_message[3]  = 0x685421cd;
281
11.4k
  pe->dos_message[4]  = 0x70207369;
282
11.4k
  pe->dos_message[5]  = 0x72676f72;
283
11.4k
  pe->dos_message[6]  = 0x63206d61;
284
11.4k
  pe->dos_message[7]  = 0x6f6e6e61;
285
11.4k
  pe->dos_message[8]  = 0x65622074;
286
11.4k
  pe->dos_message[9]  = 0x6e757220;
287
11.4k
  pe->dos_message[10] = 0x206e6920;
288
11.4k
  pe->dos_message[11] = 0x20534f44;
289
11.4k
  pe->dos_message[12] = 0x65646f6d;
290
11.4k
  pe->dos_message[13] = 0x0a0d0d2e;
291
11.4k
  pe->dos_message[14] = 0x24;
292
11.4k
  pe->dos_message[15] = 0x0;
293
294
11.4k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
11.4k
  bfd_coff_long_section_names (abfd)
297
11.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
11.4k
  return true;
300
11.4k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
260
10.8k
{
261
10.8k
  pe_data_type *pe;
262
10.8k
  size_t amt = sizeof (pe_data_type);
263
264
10.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
10.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
10.8k
  pe = pe_data (abfd);
270
271
10.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
10.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
10.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
10.8k
  pe->dos_message[1]  = 0xcd09b400;
279
10.8k
  pe->dos_message[2]  = 0x4c01b821;
280
10.8k
  pe->dos_message[3]  = 0x685421cd;
281
10.8k
  pe->dos_message[4]  = 0x70207369;
282
10.8k
  pe->dos_message[5]  = 0x72676f72;
283
10.8k
  pe->dos_message[6]  = 0x63206d61;
284
10.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
10.8k
  pe->dos_message[8]  = 0x65622074;
286
10.8k
  pe->dos_message[9]  = 0x6e757220;
287
10.8k
  pe->dos_message[10] = 0x206e6920;
288
10.8k
  pe->dos_message[11] = 0x20534f44;
289
10.8k
  pe->dos_message[12] = 0x65646f6d;
290
10.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
10.8k
  pe->dos_message[14] = 0x24;
292
10.8k
  pe->dos_message[15] = 0x0;
293
294
10.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
10.8k
  bfd_coff_long_section_names (abfd)
297
10.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
10.8k
  return true;
300
10.8k
}
pei-sh.c:pe_mkobject
Line
Count
Source
260
10.4k
{
261
10.4k
  pe_data_type *pe;
262
10.4k
  size_t amt = sizeof (pe_data_type);
263
264
10.4k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
10.4k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
10.4k
  pe = pe_data (abfd);
270
271
10.4k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
10.4k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
10.4k
  pe->dos_message[0]  = 0x0eba1f0e;
278
10.4k
  pe->dos_message[1]  = 0xcd09b400;
279
10.4k
  pe->dos_message[2]  = 0x4c01b821;
280
10.4k
  pe->dos_message[3]  = 0x685421cd;
281
10.4k
  pe->dos_message[4]  = 0x70207369;
282
10.4k
  pe->dos_message[5]  = 0x72676f72;
283
10.4k
  pe->dos_message[6]  = 0x63206d61;
284
10.4k
  pe->dos_message[7]  = 0x6f6e6e61;
285
10.4k
  pe->dos_message[8]  = 0x65622074;
286
10.4k
  pe->dos_message[9]  = 0x6e757220;
287
10.4k
  pe->dos_message[10] = 0x206e6920;
288
10.4k
  pe->dos_message[11] = 0x20534f44;
289
10.4k
  pe->dos_message[12] = 0x65646f6d;
290
10.4k
  pe->dos_message[13] = 0x0a0d0d2e;
291
10.4k
  pe->dos_message[14] = 0x24;
292
10.4k
  pe->dos_message[15] = 0x0;
293
294
10.4k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
10.4k
  bfd_coff_long_section_names (abfd)
297
10.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
10.4k
  return true;
300
10.4k
}
301
302
/* Create the COFF backend specific information.  */
303
304
static void *
305
pe_mkobject_hook (bfd * abfd,
306
      void * filehdr,
307
      void * aouthdr ATTRIBUTE_UNUSED)
308
83.3k
{
309
83.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
83.3k
  pe_data_type *pe;
311
312
83.3k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
83.3k
  pe = pe_data (abfd);
316
83.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
83.3k
  pe->coff.local_n_btmask = N_BTMASK;
321
83.3k
  pe->coff.local_n_btshft = N_BTSHFT;
322
83.3k
  pe->coff.local_n_tmask = N_TMASK;
323
83.3k
  pe->coff.local_n_tshift = N_TSHIFT;
324
83.3k
  pe->coff.local_symesz = SYMESZ;
325
83.3k
  pe->coff.local_auxesz = AUXESZ;
326
83.3k
  pe->coff.local_linesz = LINESZ;
327
328
83.3k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
83.3k
  obj_raw_syment_count (abfd) =
331
83.3k
    obj_conv_table_size (abfd) =
332
83.3k
      internal_f->f_nsyms;
333
334
83.3k
  pe->real_flags = internal_f->f_flags;
335
336
83.3k
  if ((internal_f->f_flags & F_DLL) != 0)
337
18.4k
    pe->dll = 1;
338
339
83.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
65.1k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
72.1k
  if (aouthdr)
344
56.4k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
23.4k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
83.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
83.3k
    sizeof (pe->dos_message));
354
355
83.3k
  return (void *) pe;
356
83.3k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
308
5.21k
{
309
5.21k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
5.21k
  pe_data_type *pe;
311
312
5.21k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
5.21k
  pe = pe_data (abfd);
316
5.21k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
5.21k
  pe->coff.local_n_btmask = N_BTMASK;
321
5.21k
  pe->coff.local_n_btshft = N_BTSHFT;
322
5.21k
  pe->coff.local_n_tmask = N_TMASK;
323
5.21k
  pe->coff.local_n_tshift = N_TSHIFT;
324
5.21k
  pe->coff.local_symesz = SYMESZ;
325
5.21k
  pe->coff.local_auxesz = AUXESZ;
326
5.21k
  pe->coff.local_linesz = LINESZ;
327
328
5.21k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
5.21k
  obj_raw_syment_count (abfd) =
331
5.21k
    obj_conv_table_size (abfd) =
332
5.21k
      internal_f->f_nsyms;
333
334
5.21k
  pe->real_flags = internal_f->f_flags;
335
336
5.21k
  if ((internal_f->f_flags & F_DLL) != 0)
337
604
    pe->dll = 1;
338
339
5.21k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
4.61k
    abfd->flags |= HAS_DEBUG;
341
342
5.21k
#ifdef COFF_IMAGE_WITH_PE
343
5.21k
  if (aouthdr)
344
2.52k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
5.21k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
5.21k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
5.21k
    sizeof (pe->dos_message));
354
355
5.21k
  return (void *) pe;
356
5.21k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
836
{
309
836
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
836
  pe_data_type *pe;
311
312
836
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
836
  pe = pe_data (abfd);
316
836
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
836
  pe->coff.local_n_btmask = N_BTMASK;
321
836
  pe->coff.local_n_btshft = N_BTSHFT;
322
836
  pe->coff.local_n_tmask = N_TMASK;
323
836
  pe->coff.local_n_tshift = N_TSHIFT;
324
836
  pe->coff.local_symesz = SYMESZ;
325
836
  pe->coff.local_auxesz = AUXESZ;
326
836
  pe->coff.local_linesz = LINESZ;
327
328
836
  pe->coff.timestamp = internal_f->f_timdat;
329
330
836
  obj_raw_syment_count (abfd) =
331
836
    obj_conv_table_size (abfd) =
332
836
      internal_f->f_nsyms;
333
334
836
  pe->real_flags = internal_f->f_flags;
335
336
836
  if ((internal_f->f_flags & F_DLL) != 0)
337
66
    pe->dll = 1;
338
339
836
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
710
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
836
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
836
    sizeof (pe->dos_message));
354
355
836
  return (void *) pe;
356
836
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
540
{
309
540
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
540
  pe_data_type *pe;
311
312
540
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
540
  pe = pe_data (abfd);
316
540
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
540
  pe->coff.local_n_btmask = N_BTMASK;
321
540
  pe->coff.local_n_btshft = N_BTSHFT;
322
540
  pe->coff.local_n_tmask = N_TMASK;
323
540
  pe->coff.local_n_tshift = N_TSHIFT;
324
540
  pe->coff.local_symesz = SYMESZ;
325
540
  pe->coff.local_auxesz = AUXESZ;
326
540
  pe->coff.local_linesz = LINESZ;
327
328
540
  pe->coff.timestamp = internal_f->f_timdat;
329
330
540
  obj_raw_syment_count (abfd) =
331
540
    obj_conv_table_size (abfd) =
332
540
      internal_f->f_nsyms;
333
334
540
  pe->real_flags = internal_f->f_flags;
335
336
540
  if ((internal_f->f_flags & F_DLL) != 0)
337
26
    pe->dll = 1;
338
339
540
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
92
    abfd->flags |= HAS_DEBUG;
341
342
540
#ifdef COFF_IMAGE_WITH_PE
343
540
  if (aouthdr)
344
224
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
540
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
540
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
540
    sizeof (pe->dos_message));
354
355
540
  return (void *) pe;
356
540
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
6.12k
{
309
6.12k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
6.12k
  pe_data_type *pe;
311
312
6.12k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
6.12k
  pe = pe_data (abfd);
316
6.12k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
6.12k
  pe->coff.local_n_btmask = N_BTMASK;
321
6.12k
  pe->coff.local_n_btshft = N_BTSHFT;
322
6.12k
  pe->coff.local_n_tmask = N_TMASK;
323
6.12k
  pe->coff.local_n_tshift = N_TSHIFT;
324
6.12k
  pe->coff.local_symesz = SYMESZ;
325
6.12k
  pe->coff.local_auxesz = AUXESZ;
326
6.12k
  pe->coff.local_linesz = LINESZ;
327
328
6.12k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
6.12k
  obj_raw_syment_count (abfd) =
331
6.12k
    obj_conv_table_size (abfd) =
332
6.12k
      internal_f->f_nsyms;
333
334
6.12k
  pe->real_flags = internal_f->f_flags;
335
336
6.12k
  if ((internal_f->f_flags & F_DLL) != 0)
337
4.82k
    pe->dll = 1;
338
339
6.12k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
1.11k
    abfd->flags |= HAS_DEBUG;
341
342
6.12k
#ifdef COFF_IMAGE_WITH_PE
343
6.12k
  if (aouthdr)
344
5.38k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
6.12k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
6.12k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
6.12k
    sizeof (pe->dos_message));
354
355
6.12k
  return (void *) pe;
356
6.12k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
1.28k
{
309
1.28k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
1.28k
  pe_data_type *pe;
311
312
1.28k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
1.28k
  pe = pe_data (abfd);
316
1.28k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
1.28k
  pe->coff.local_n_btmask = N_BTMASK;
321
1.28k
  pe->coff.local_n_btshft = N_BTSHFT;
322
1.28k
  pe->coff.local_n_tmask = N_TMASK;
323
1.28k
  pe->coff.local_n_tshift = N_TSHIFT;
324
1.28k
  pe->coff.local_symesz = SYMESZ;
325
1.28k
  pe->coff.local_auxesz = AUXESZ;
326
1.28k
  pe->coff.local_linesz = LINESZ;
327
328
1.28k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
1.28k
  obj_raw_syment_count (abfd) =
331
1.28k
    obj_conv_table_size (abfd) =
332
1.28k
      internal_f->f_nsyms;
333
334
1.28k
  pe->real_flags = internal_f->f_flags;
335
336
1.28k
  if ((internal_f->f_flags & F_DLL) != 0)
337
506
    pe->dll = 1;
338
339
1.28k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
1.08k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
1.28k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
1.28k
    sizeof (pe->dos_message));
354
355
1.28k
  return (void *) pe;
356
1.28k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
308
15.7k
{
309
15.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
15.7k
  pe_data_type *pe;
311
312
15.7k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
15.7k
  pe = pe_data (abfd);
316
15.7k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
15.7k
  pe->coff.local_n_btmask = N_BTMASK;
321
15.7k
  pe->coff.local_n_btshft = N_BTSHFT;
322
15.7k
  pe->coff.local_n_tmask = N_TMASK;
323
15.7k
  pe->coff.local_n_tshift = N_TSHIFT;
324
15.7k
  pe->coff.local_symesz = SYMESZ;
325
15.7k
  pe->coff.local_auxesz = AUXESZ;
326
15.7k
  pe->coff.local_linesz = LINESZ;
327
328
15.7k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
15.7k
  obj_raw_syment_count (abfd) =
331
15.7k
    obj_conv_table_size (abfd) =
332
15.7k
      internal_f->f_nsyms;
333
334
15.7k
  pe->real_flags = internal_f->f_flags;
335
336
15.7k
  if ((internal_f->f_flags & F_DLL) != 0)
337
504
    pe->dll = 1;
338
339
15.7k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
14.3k
    abfd->flags |= HAS_DEBUG;
341
342
15.7k
#ifdef COFF_IMAGE_WITH_PE
343
15.7k
  if (aouthdr)
344
13.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
15.7k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
15.7k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
15.7k
    sizeof (pe->dos_message));
354
355
15.7k
  return (void *) pe;
356
15.7k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
308
386
{
309
386
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
386
  pe_data_type *pe;
311
312
386
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
386
  pe = pe_data (abfd);
316
386
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
386
  pe->coff.local_n_btmask = N_BTMASK;
321
386
  pe->coff.local_n_btshft = N_BTSHFT;
322
386
  pe->coff.local_n_tmask = N_TMASK;
323
386
  pe->coff.local_n_tshift = N_TSHIFT;
324
386
  pe->coff.local_symesz = SYMESZ;
325
386
  pe->coff.local_auxesz = AUXESZ;
326
386
  pe->coff.local_linesz = LINESZ;
327
328
386
  pe->coff.timestamp = internal_f->f_timdat;
329
330
386
  obj_raw_syment_count (abfd) =
331
386
    obj_conv_table_size (abfd) =
332
386
      internal_f->f_nsyms;
333
334
386
  pe->real_flags = internal_f->f_flags;
335
336
386
  if ((internal_f->f_flags & F_DLL) != 0)
337
36
    pe->dll = 1;
338
339
386
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
96
    abfd->flags |= HAS_DEBUG;
341
342
386
#ifdef COFF_IMAGE_WITH_PE
343
386
  if (aouthdr)
344
158
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
386
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
386
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
386
    sizeof (pe->dos_message));
354
355
386
  return (void *) pe;
356
386
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
346
{
309
346
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
346
  pe_data_type *pe;
311
312
346
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
346
  pe = pe_data (abfd);
316
346
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
346
  pe->coff.local_n_btmask = N_BTMASK;
321
346
  pe->coff.local_n_btshft = N_BTSHFT;
322
346
  pe->coff.local_n_tmask = N_TMASK;
323
346
  pe->coff.local_n_tshift = N_TSHIFT;
324
346
  pe->coff.local_symesz = SYMESZ;
325
346
  pe->coff.local_auxesz = AUXESZ;
326
346
  pe->coff.local_linesz = LINESZ;
327
328
346
  pe->coff.timestamp = internal_f->f_timdat;
329
330
346
  obj_raw_syment_count (abfd) =
331
346
    obj_conv_table_size (abfd) =
332
346
      internal_f->f_nsyms;
333
334
346
  pe->real_flags = internal_f->f_flags;
335
336
346
  if ((internal_f->f_flags & F_DLL) != 0)
337
74
    pe->dll = 1;
338
339
346
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
274
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
346
#ifdef ARM
348
346
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
346
#endif
351
352
346
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
346
    sizeof (pe->dos_message));
354
355
346
  return (void *) pe;
356
346
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
308
346
{
309
346
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
346
  pe_data_type *pe;
311
312
346
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
346
  pe = pe_data (abfd);
316
346
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
346
  pe->coff.local_n_btmask = N_BTMASK;
321
346
  pe->coff.local_n_btshft = N_BTSHFT;
322
346
  pe->coff.local_n_tmask = N_TMASK;
323
346
  pe->coff.local_n_tshift = N_TSHIFT;
324
346
  pe->coff.local_symesz = SYMESZ;
325
346
  pe->coff.local_auxesz = AUXESZ;
326
346
  pe->coff.local_linesz = LINESZ;
327
328
346
  pe->coff.timestamp = internal_f->f_timdat;
329
330
346
  obj_raw_syment_count (abfd) =
331
346
    obj_conv_table_size (abfd) =
332
346
      internal_f->f_nsyms;
333
334
346
  pe->real_flags = internal_f->f_flags;
335
336
346
  if ((internal_f->f_flags & F_DLL) != 0)
337
74
    pe->dll = 1;
338
339
346
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
274
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
346
#ifdef ARM
348
346
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
346
#endif
351
352
346
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
346
    sizeof (pe->dos_message));
354
355
346
  return (void *) pe;
356
346
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
308
586
{
309
586
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
586
  pe_data_type *pe;
311
312
586
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
586
  pe = pe_data (abfd);
316
586
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
586
  pe->coff.local_n_btmask = N_BTMASK;
321
586
  pe->coff.local_n_btshft = N_BTSHFT;
322
586
  pe->coff.local_n_tmask = N_TMASK;
323
586
  pe->coff.local_n_tshift = N_TSHIFT;
324
586
  pe->coff.local_symesz = SYMESZ;
325
586
  pe->coff.local_auxesz = AUXESZ;
326
586
  pe->coff.local_linesz = LINESZ;
327
328
586
  pe->coff.timestamp = internal_f->f_timdat;
329
330
586
  obj_raw_syment_count (abfd) =
331
586
    obj_conv_table_size (abfd) =
332
586
      internal_f->f_nsyms;
333
334
586
  pe->real_flags = internal_f->f_flags;
335
336
586
  if ((internal_f->f_flags & F_DLL) != 0)
337
32
    pe->dll = 1;
338
339
586
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
506
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
586
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
586
    sizeof (pe->dos_message));
354
355
586
  return (void *) pe;
356
586
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
308
3.95k
{
309
3.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
3.95k
  pe_data_type *pe;
311
312
3.95k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
3.95k
  pe = pe_data (abfd);
316
3.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
3.95k
  pe->coff.local_n_btmask = N_BTMASK;
321
3.95k
  pe->coff.local_n_btshft = N_BTSHFT;
322
3.95k
  pe->coff.local_n_tmask = N_TMASK;
323
3.95k
  pe->coff.local_n_tshift = N_TSHIFT;
324
3.95k
  pe->coff.local_symesz = SYMESZ;
325
3.95k
  pe->coff.local_auxesz = AUXESZ;
326
3.95k
  pe->coff.local_linesz = LINESZ;
327
328
3.95k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
3.95k
  obj_raw_syment_count (abfd) =
331
3.95k
    obj_conv_table_size (abfd) =
332
3.95k
      internal_f->f_nsyms;
333
334
3.95k
  pe->real_flags = internal_f->f_flags;
335
336
3.95k
  if ((internal_f->f_flags & F_DLL) != 0)
337
1.00k
    pe->dll = 1;
338
339
3.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
3.44k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
3.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
3.95k
    sizeof (pe->dos_message));
354
355
3.95k
  return (void *) pe;
356
3.95k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
308
3.89k
{
309
3.89k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
3.89k
  pe_data_type *pe;
311
312
3.89k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
3.89k
  pe = pe_data (abfd);
316
3.89k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
3.89k
  pe->coff.local_n_btmask = N_BTMASK;
321
3.89k
  pe->coff.local_n_btshft = N_BTSHFT;
322
3.89k
  pe->coff.local_n_tmask = N_TMASK;
323
3.89k
  pe->coff.local_n_tshift = N_TSHIFT;
324
3.89k
  pe->coff.local_symesz = SYMESZ;
325
3.89k
  pe->coff.local_auxesz = AUXESZ;
326
3.89k
  pe->coff.local_linesz = LINESZ;
327
328
3.89k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
3.89k
  obj_raw_syment_count (abfd) =
331
3.89k
    obj_conv_table_size (abfd) =
332
3.89k
      internal_f->f_nsyms;
333
334
3.89k
  pe->real_flags = internal_f->f_flags;
335
336
3.89k
  if ((internal_f->f_flags & F_DLL) != 0)
337
1.93k
    pe->dll = 1;
338
339
3.89k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
3.38k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
3.89k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
3.89k
    sizeof (pe->dos_message));
354
355
3.89k
  return (void *) pe;
356
3.89k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
11.3k
{
309
11.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
11.3k
  pe_data_type *pe;
311
312
11.3k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
11.3k
  pe = pe_data (abfd);
316
11.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
11.3k
  pe->coff.local_n_btmask = N_BTMASK;
321
11.3k
  pe->coff.local_n_btshft = N_BTSHFT;
322
11.3k
  pe->coff.local_n_tmask = N_TMASK;
323
11.3k
  pe->coff.local_n_tshift = N_TSHIFT;
324
11.3k
  pe->coff.local_symesz = SYMESZ;
325
11.3k
  pe->coff.local_auxesz = AUXESZ;
326
11.3k
  pe->coff.local_linesz = LINESZ;
327
328
11.3k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
11.3k
  obj_raw_syment_count (abfd) =
331
11.3k
    obj_conv_table_size (abfd) =
332
11.3k
      internal_f->f_nsyms;
333
334
11.3k
  pe->real_flags = internal_f->f_flags;
335
336
11.3k
  if ((internal_f->f_flags & F_DLL) != 0)
337
1.94k
    pe->dll = 1;
338
339
11.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
9.84k
    abfd->flags |= HAS_DEBUG;
341
342
11.3k
#ifdef COFF_IMAGE_WITH_PE
343
11.3k
  if (aouthdr)
344
8.25k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
11.3k
#endif
346
347
11.3k
#ifdef ARM
348
11.3k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
11.3k
#endif
351
352
11.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
11.3k
    sizeof (pe->dos_message));
354
355
11.3k
  return (void *) pe;
356
11.3k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
308
11.4k
{
309
11.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
11.4k
  pe_data_type *pe;
311
312
11.4k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
11.4k
  pe = pe_data (abfd);
316
11.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
11.4k
  pe->coff.local_n_btmask = N_BTMASK;
321
11.4k
  pe->coff.local_n_btshft = N_BTSHFT;
322
11.4k
  pe->coff.local_n_tmask = N_TMASK;
323
11.4k
  pe->coff.local_n_tshift = N_TSHIFT;
324
11.4k
  pe->coff.local_symesz = SYMESZ;
325
11.4k
  pe->coff.local_auxesz = AUXESZ;
326
11.4k
  pe->coff.local_linesz = LINESZ;
327
328
11.4k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
11.4k
  obj_raw_syment_count (abfd) =
331
11.4k
    obj_conv_table_size (abfd) =
332
11.4k
      internal_f->f_nsyms;
333
334
11.4k
  pe->real_flags = internal_f->f_flags;
335
336
11.4k
  if ((internal_f->f_flags & F_DLL) != 0)
337
4.34k
    pe->dll = 1;
338
339
11.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
7.09k
    abfd->flags |= HAS_DEBUG;
341
342
11.4k
#ifdef COFF_IMAGE_WITH_PE
343
11.4k
  if (aouthdr)
344
8.38k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
11.4k
#endif
346
347
11.4k
#ifdef ARM
348
11.4k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
11.4k
#endif
351
352
11.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
11.4k
    sizeof (pe->dos_message));
354
355
11.4k
  return (void *) pe;
356
11.4k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
308
10.8k
{
309
10.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
10.8k
  pe_data_type *pe;
311
312
10.8k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
10.8k
  pe = pe_data (abfd);
316
10.8k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
10.8k
  pe->coff.local_n_btmask = N_BTMASK;
321
10.8k
  pe->coff.local_n_btshft = N_BTSHFT;
322
10.8k
  pe->coff.local_n_tmask = N_TMASK;
323
10.8k
  pe->coff.local_n_tshift = N_TSHIFT;
324
10.8k
  pe->coff.local_symesz = SYMESZ;
325
10.8k
  pe->coff.local_auxesz = AUXESZ;
326
10.8k
  pe->coff.local_linesz = LINESZ;
327
328
10.8k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
10.8k
  obj_raw_syment_count (abfd) =
331
10.8k
    obj_conv_table_size (abfd) =
332
10.8k
      internal_f->f_nsyms;
333
334
10.8k
  pe->real_flags = internal_f->f_flags;
335
336
10.8k
  if ((internal_f->f_flags & F_DLL) != 0)
337
1.47k
    pe->dll = 1;
338
339
10.8k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
9.36k
    abfd->flags |= HAS_DEBUG;
341
342
10.8k
#ifdef COFF_IMAGE_WITH_PE
343
10.8k
  if (aouthdr)
344
9.24k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
10.8k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
10.8k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
10.8k
    sizeof (pe->dos_message));
354
355
10.8k
  return (void *) pe;
356
10.8k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
308
10.4k
{
309
10.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
10.4k
  pe_data_type *pe;
311
312
10.4k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
10.4k
  pe = pe_data (abfd);
316
10.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
10.4k
  pe->coff.local_n_btmask = N_BTMASK;
321
10.4k
  pe->coff.local_n_btshft = N_BTSHFT;
322
10.4k
  pe->coff.local_n_tmask = N_TMASK;
323
10.4k
  pe->coff.local_n_tshift = N_TSHIFT;
324
10.4k
  pe->coff.local_symesz = SYMESZ;
325
10.4k
  pe->coff.local_auxesz = AUXESZ;
326
10.4k
  pe->coff.local_linesz = LINESZ;
327
328
10.4k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
10.4k
  obj_raw_syment_count (abfd) =
331
10.4k
    obj_conv_table_size (abfd) =
332
10.4k
      internal_f->f_nsyms;
333
334
10.4k
  pe->real_flags = internal_f->f_flags;
335
336
10.4k
  if ((internal_f->f_flags & F_DLL) != 0)
337
996
    pe->dll = 1;
338
339
10.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
8.90k
    abfd->flags |= HAS_DEBUG;
341
342
10.4k
#ifdef COFF_IMAGE_WITH_PE
343
10.4k
  if (aouthdr)
344
8.71k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
10.4k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
10.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
10.4k
    sizeof (pe->dos_message));
354
355
10.4k
  return (void *) pe;
356
10.4k
}
357
358
static bool
359
pe_print_private_bfd_data (bfd *abfd, void * vfile)
360
0
{
361
0
  FILE *file = (FILE *) vfile;
362
363
0
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
0
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
0
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
0
}
Unexecuted instantiation: pei-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_print_private_bfd_data
373
374
/* Copy any private info we understand from the input bfd
375
   to the output bfd.  */
376
377
static bool
378
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
379
0
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
0
  if (pe_data (obfd) != NULL
384
0
      && pe_data (ibfd) != NULL
385
0
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
0
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
0
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
0
  return true;
395
0
}
Unexecuted instantiation: pei-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_bfd_copy_private_bfd_data
396
397
#define coff_bfd_copy_private_section_data \
398
  _bfd_XX_bfd_copy_private_section_data
399
400
#define coff_get_symbol_info _bfd_XX_get_symbol_info
401
402
#ifdef COFF_IMAGE_WITH_PE
403

404
/* Code to handle Microsoft's Import Library Format.
405
   Also known as LINK6 format.
406
   Documentation about this format can be found at:
407
408
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
409
410
/* The following constants specify the sizes of the various data
411
   structures that we have to create in order to build a bfd describing
412
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
413
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
414
   need a padding byte in order to ensure 16 bit alignment for the section's
415
   contents.
416
417
   The value for SIZEOF_ILF_STRINGS is computed as follows:
418
419
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
420
      per symbol for their names (longest section name is .idata$x).
421
422
      There will be two symbols for the imported value, one the symbol name
423
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
424
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
425
426
      The strings in the string table must start STRING__SIZE_SIZE bytes into
427
      the table in order to for the string lookup code in coffgen/coffcode to
428
      work.  */
429
684
#define NUM_ILF_RELOCS    8
430
2.28k
#define NUM_ILF_SECTIONS  6
431
1.71k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
432
433
342
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
434
342
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (* vars.sym_table))
435
342
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (* vars.native_syms))
436
342
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
437
342
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (* vars.esym_table))
438
342
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.reltab))
439
342
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
440
342
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
441
342
          + 21 + strlen (source_dll) \
442
342
          + NUM_ILF_SECTIONS * 9 \
443
342
          + STRING_SIZE_SIZE)
444
228
#define SIZEOF_IDATA2   (5 * 4)
445
446
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
447
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
448
84
#define SIZEOF_IDATA4   (2 * 4)
449
84
#define SIZEOF_IDATA5   (2 * 4)
450
#else
451
258
#define SIZEOF_IDATA4   (1 * 4)
452
258
#define SIZEOF_IDATA5   (1 * 4)
453
#endif
454
455
306
#define SIZEOF_IDATA6   (2 + strlen (symbol_name) + 1 + 1)
456
228
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
457
228
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
458
459
#define ILF_DATA_SIZE       \
460
228
    + SIZEOF_ILF_SYMS        \
461
228
    + SIZEOF_ILF_SYM_TABLE      \
462
228
    + SIZEOF_ILF_NATIVE_SYMS      \
463
228
    + SIZEOF_ILF_SYM_PTR_TABLE      \
464
228
    + SIZEOF_ILF_EXT_SYMS      \
465
228
    + SIZEOF_ILF_RELOCS        \
466
228
    + SIZEOF_ILF_INT_RELOCS      \
467
228
    + SIZEOF_ILF_STRINGS      \
468
228
    + SIZEOF_IDATA2        \
469
228
    + SIZEOF_IDATA4        \
470
228
    + SIZEOF_IDATA5        \
471
228
    + SIZEOF_IDATA6        \
472
228
    + SIZEOF_IDATA7        \
473
228
    + SIZEOF_ILF_SECTIONS      \
474
228
    + MAX_TEXT_SECTION_SIZE
475
476
/* Create an empty relocation against the given symbol.  */
477
478
static void
479
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
480
          bfd_vma     address,
481
          bfd_reloc_code_real_type  reloc,
482
          struct bfd_symbol **  sym,
483
          unsigned int    sym_index)
484
220
{
485
220
  arelent * entry;
486
220
  struct internal_reloc * internal;
487
488
220
  entry = vars->reltab + vars->relcount;
489
220
  internal = vars->int_reltab + vars->relcount;
490
491
220
  entry->address     = address;
492
220
  entry->addend      = 0;
493
220
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
220
  entry->sym_ptr_ptr = sym;
495
496
220
  internal->r_vaddr  = address;
497
220
  internal->r_symndx = sym_index;
498
220
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
220
  vars->relcount ++;
501
502
220
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
220
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
22
{
485
22
  arelent * entry;
486
22
  struct internal_reloc * internal;
487
488
22
  entry = vars->reltab + vars->relcount;
489
22
  internal = vars->int_reltab + vars->relcount;
490
491
22
  entry->address     = address;
492
22
  entry->addend      = 0;
493
22
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
22
  entry->sym_ptr_ptr = sym;
495
496
22
  internal->r_vaddr  = address;
497
22
  internal->r_symndx = sym_index;
498
22
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
22
  vars->relcount ++;
501
502
22
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
22
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
26
{
485
26
  arelent * entry;
486
26
  struct internal_reloc * internal;
487
488
26
  entry = vars->reltab + vars->relcount;
489
26
  internal = vars->int_reltab + vars->relcount;
490
491
26
  entry->address     = address;
492
26
  entry->addend      = 0;
493
26
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
26
  entry->sym_ptr_ptr = sym;
495
496
26
  internal->r_vaddr  = address;
497
26
  internal->r_symndx = sym_index;
498
26
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
26
  vars->relcount ++;
501
502
26
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
26
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
26
{
485
26
  arelent * entry;
486
26
  struct internal_reloc * internal;
487
488
26
  entry = vars->reltab + vars->relcount;
489
26
  internal = vars->int_reltab + vars->relcount;
490
491
26
  entry->address     = address;
492
26
  entry->addend      = 0;
493
26
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
26
  entry->sym_ptr_ptr = sym;
495
496
26
  internal->r_vaddr  = address;
497
26
  internal->r_symndx = sym_index;
498
26
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
26
  vars->relcount ++;
501
502
26
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
26
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
30
{
485
30
  arelent * entry;
486
30
  struct internal_reloc * internal;
487
488
30
  entry = vars->reltab + vars->relcount;
489
30
  internal = vars->int_reltab + vars->relcount;
490
491
30
  entry->address     = address;
492
30
  entry->addend      = 0;
493
30
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
30
  entry->sym_ptr_ptr = sym;
495
496
30
  internal->r_vaddr  = address;
497
30
  internal->r_symndx = sym_index;
498
30
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
30
  vars->relcount ++;
501
502
30
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
30
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
48
{
485
48
  arelent * entry;
486
48
  struct internal_reloc * internal;
487
488
48
  entry = vars->reltab + vars->relcount;
489
48
  internal = vars->int_reltab + vars->relcount;
490
491
48
  entry->address     = address;
492
48
  entry->addend      = 0;
493
48
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
48
  entry->sym_ptr_ptr = sym;
495
496
48
  internal->r_vaddr  = address;
497
48
  internal->r_symndx = sym_index;
498
48
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
48
  vars->relcount ++;
501
502
48
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
48
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
48
{
485
48
  arelent * entry;
486
48
  struct internal_reloc * internal;
487
488
48
  entry = vars->reltab + vars->relcount;
489
48
  internal = vars->int_reltab + vars->relcount;
490
491
48
  entry->address     = address;
492
48
  entry->addend      = 0;
493
48
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
48
  entry->sym_ptr_ptr = sym;
495
496
48
  internal->r_vaddr  = address;
497
48
  internal->r_symndx = sym_index;
498
48
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
48
  vars->relcount ++;
501
502
48
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
48
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
20
{
485
20
  arelent * entry;
486
20
  struct internal_reloc * internal;
487
488
20
  entry = vars->reltab + vars->relcount;
489
20
  internal = vars->int_reltab + vars->relcount;
490
491
20
  entry->address     = address;
492
20
  entry->addend      = 0;
493
20
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
20
  entry->sym_ptr_ptr = sym;
495
496
20
  internal->r_vaddr  = address;
497
20
  internal->r_symndx = sym_index;
498
20
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
20
  vars->relcount ++;
501
502
20
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
20
}
504
505
/* Create an empty relocation against the given section.  */
506
507
static void
508
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
509
         bfd_vma           address,
510
         bfd_reloc_code_real_type  reloc,
511
         asection_ptr        sec)
512
156
{
513
156
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
156
            coff_section_data (vars->abfd, sec)->i);
515
156
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
512
16
{
513
16
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
16
            coff_section_data (vars->abfd, sec)->i);
515
16
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
20
{
513
20
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
20
            coff_section_data (vars->abfd, sec)->i);
515
20
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
16
{
513
16
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
16
            coff_section_data (vars->abfd, sec)->i);
515
16
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
20
{
513
20
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
20
            coff_section_data (vars->abfd, sec)->i);
515
20
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
512
36
{
513
36
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
36
            coff_section_data (vars->abfd, sec)->i);
515
36
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
512
36
{
513
36
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
36
            coff_section_data (vars->abfd, sec)->i);
515
36
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
512
12
{
513
12
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
12
            coff_section_data (vars->abfd, sec)->i);
515
12
}
516
517
/* Move the queued relocs into the given section.  */
518
519
static void
520
pe_ILF_save_relocs (pe_ILF_vars * vars,
521
        asection_ptr  sec)
522
220
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
220
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
220
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
220
  sec->relocation  = vars->reltab;
531
220
  sec->reloc_count = vars->relcount;
532
220
  sec->flags      |= SEC_RELOC;
533
534
220
  vars->reltab     += vars->relcount;
535
220
  vars->int_reltab += vars->relcount;
536
220
  vars->relcount   = 0;
537
538
220
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
220
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
522
22
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
22
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
22
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
22
  sec->relocation  = vars->reltab;
531
22
  sec->reloc_count = vars->relcount;
532
22
  sec->flags      |= SEC_RELOC;
533
534
22
  vars->reltab     += vars->relcount;
535
22
  vars->int_reltab += vars->relcount;
536
22
  vars->relcount   = 0;
537
538
22
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
22
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
522
26
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
26
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
26
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
26
  sec->relocation  = vars->reltab;
531
26
  sec->reloc_count = vars->relcount;
532
26
  sec->flags      |= SEC_RELOC;
533
534
26
  vars->reltab     += vars->relcount;
535
26
  vars->int_reltab += vars->relcount;
536
26
  vars->relcount   = 0;
537
538
26
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
26
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
26
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
26
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
26
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
26
  sec->relocation  = vars->reltab;
531
26
  sec->reloc_count = vars->relcount;
532
26
  sec->flags      |= SEC_RELOC;
533
534
26
  vars->reltab     += vars->relcount;
535
26
  vars->int_reltab += vars->relcount;
536
26
  vars->relcount   = 0;
537
538
26
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
26
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
30
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
30
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
30
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
30
  sec->relocation  = vars->reltab;
531
30
  sec->reloc_count = vars->relcount;
532
30
  sec->flags      |= SEC_RELOC;
533
534
30
  vars->reltab     += vars->relcount;
535
30
  vars->int_reltab += vars->relcount;
536
30
  vars->relcount   = 0;
537
538
30
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
30
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
522
48
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
48
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
48
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
48
  sec->relocation  = vars->reltab;
531
48
  sec->reloc_count = vars->relcount;
532
48
  sec->flags      |= SEC_RELOC;
533
534
48
  vars->reltab     += vars->relcount;
535
48
  vars->int_reltab += vars->relcount;
536
48
  vars->relcount   = 0;
537
538
48
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
48
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
522
48
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
48
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
48
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
48
  sec->relocation  = vars->reltab;
531
48
  sec->reloc_count = vars->relcount;
532
48
  sec->flags      |= SEC_RELOC;
533
534
48
  vars->reltab     += vars->relcount;
535
48
  vars->int_reltab += vars->relcount;
536
48
  vars->relcount   = 0;
537
538
48
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
48
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
522
20
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
20
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
20
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
20
  sec->relocation  = vars->reltab;
531
20
  sec->reloc_count = vars->relcount;
532
20
  sec->flags      |= SEC_RELOC;
533
534
20
  vars->reltab     += vars->relcount;
535
20
  vars->int_reltab += vars->relcount;
536
20
  vars->relcount   = 0;
537
538
20
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
20
}
540
541
/* Create a global symbol and add it to the relevant tables.  */
542
543
static void
544
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
545
          const char *   prefix,
546
          const char *   symbol_name,
547
          asection_ptr   section,
548
          flagword       extra_flags)
549
626
{
550
626
  coff_symbol_type * sym;
551
626
  combined_entry_type * ent;
552
626
  SYMENT * esym;
553
626
  unsigned short sclass;
554
555
626
  if (extra_flags & BSF_LOCAL)
556
370
    sclass = C_STAT;
557
256
  else
558
256
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
260
  if (vars->magic == THUMBPEMAGIC)
562
76
    {
563
76
      if (extra_flags & BSF_FUNCTION)
564
4
  sclass = C_THUMBEXTFUNC;
565
72
      else if (extra_flags & BSF_LOCAL)
566
48
  sclass = C_THUMBSTAT;
567
24
      else
568
24
  sclass = C_THUMBEXT;
569
76
    }
570
#endif
571
572
626
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
626
  sym = vars->sym_ptr;
575
626
  ent = vars->native_ptr;
576
626
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
626
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
626
  if (section == NULL)
582
96
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
626
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
626
      esym->e.e.e_offset);
587
626
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
626
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
626
  ent->u.syment.n_sclass    = sclass;
595
626
  ent->u.syment.n_scnum     = section->target_index;
596
626
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
626
  ent->is_sym = true;
598
599
626
  sym->symbol.the_bfd = vars->abfd;
600
626
  sym->symbol.name    = vars->string_ptr;
601
626
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
626
  sym->symbol.section = section;
603
626
  sym->native       = ent;
604
605
626
  * vars->table_ptr = vars->sym_index;
606
626
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
626
  vars->sym_index ++;
610
626
  vars->sym_ptr ++;
611
626
  vars->sym_ptr_ptr ++;
612
626
  vars->table_ptr ++;
613
626
  vars->native_ptr ++;
614
626
  vars->esym_ptr ++;
615
626
  vars->string_ptr += len + 1;
616
617
626
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
626
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
549
64
{
550
64
  coff_symbol_type * sym;
551
64
  combined_entry_type * ent;
552
64
  SYMENT * esym;
553
64
  unsigned short sclass;
554
555
64
  if (extra_flags & BSF_LOCAL)
556
38
    sclass = C_STAT;
557
26
  else
558
26
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
64
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
64
  sym = vars->sym_ptr;
575
64
  ent = vars->native_ptr;
576
64
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
64
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
64
  if (section == NULL)
582
10
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
64
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
64
      esym->e.e.e_offset);
587
64
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
64
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
64
  ent->u.syment.n_sclass    = sclass;
595
64
  ent->u.syment.n_scnum     = section->target_index;
596
64
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
64
  ent->is_sym = true;
598
599
64
  sym->symbol.the_bfd = vars->abfd;
600
64
  sym->symbol.name    = vars->string_ptr;
601
64
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
64
  sym->symbol.section = section;
603
64
  sym->native       = ent;
604
605
64
  * vars->table_ptr = vars->sym_index;
606
64
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
64
  vars->sym_index ++;
610
64
  vars->sym_ptr ++;
611
64
  vars->sym_ptr_ptr ++;
612
64
  vars->table_ptr ++;
613
64
  vars->native_ptr ++;
614
64
  vars->esym_ptr ++;
615
64
  vars->string_ptr += len + 1;
616
617
64
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
64
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
74
{
550
74
  coff_symbol_type * sym;
551
74
  combined_entry_type * ent;
552
74
  SYMENT * esym;
553
74
  unsigned short sclass;
554
555
74
  if (extra_flags & BSF_LOCAL)
556
44
    sclass = C_STAT;
557
30
  else
558
30
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
74
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
74
  sym = vars->sym_ptr;
575
74
  ent = vars->native_ptr;
576
74
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
74
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
74
  if (section == NULL)
582
12
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
74
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
74
      esym->e.e.e_offset);
587
74
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
74
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
74
  ent->u.syment.n_sclass    = sclass;
595
74
  ent->u.syment.n_scnum     = section->target_index;
596
74
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
74
  ent->is_sym = true;
598
599
74
  sym->symbol.the_bfd = vars->abfd;
600
74
  sym->symbol.name    = vars->string_ptr;
601
74
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
74
  sym->symbol.section = section;
603
74
  sym->native       = ent;
604
605
74
  * vars->table_ptr = vars->sym_index;
606
74
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
74
  vars->sym_index ++;
610
74
  vars->sym_ptr ++;
611
74
  vars->sym_ptr_ptr ++;
612
74
  vars->table_ptr ++;
613
74
  vars->native_ptr ++;
614
74
  vars->esym_ptr ++;
615
74
  vars->string_ptr += len + 1;
616
617
74
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
74
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
80
{
550
80
  coff_symbol_type * sym;
551
80
  combined_entry_type * ent;
552
80
  SYMENT * esym;
553
80
  unsigned short sclass;
554
555
80
  if (extra_flags & BSF_LOCAL)
556
46
    sclass = C_STAT;
557
34
  else
558
34
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
80
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
80
  sym = vars->sym_ptr;
575
80
  ent = vars->native_ptr;
576
80
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
80
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
80
  if (section == NULL)
582
12
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
80
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
80
      esym->e.e.e_offset);
587
80
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
80
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
80
  ent->u.syment.n_sclass    = sclass;
595
80
  ent->u.syment.n_scnum     = section->target_index;
596
80
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
80
  ent->is_sym = true;
598
599
80
  sym->symbol.the_bfd = vars->abfd;
600
80
  sym->symbol.name    = vars->string_ptr;
601
80
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
80
  sym->symbol.section = section;
603
80
  sym->native       = ent;
604
605
80
  * vars->table_ptr = vars->sym_index;
606
80
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
80
  vars->sym_index ++;
610
80
  vars->sym_ptr ++;
611
80
  vars->sym_ptr_ptr ++;
612
80
  vars->table_ptr ++;
613
80
  vars->native_ptr ++;
614
80
  vars->esym_ptr ++;
615
80
  vars->string_ptr += len + 1;
616
617
80
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
80
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
82
{
550
82
  coff_symbol_type * sym;
551
82
  combined_entry_type * ent;
552
82
  SYMENT * esym;
553
82
  unsigned short sclass;
554
555
82
  if (extra_flags & BSF_LOCAL)
556
48
    sclass = C_STAT;
557
34
  else
558
34
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
82
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
82
  sym = vars->sym_ptr;
575
82
  ent = vars->native_ptr;
576
82
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
82
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
82
  if (section == NULL)
582
12
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
82
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
82
      esym->e.e.e_offset);
587
82
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
82
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
82
  ent->u.syment.n_sclass    = sclass;
595
82
  ent->u.syment.n_scnum     = section->target_index;
596
82
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
82
  ent->is_sym = true;
598
599
82
  sym->symbol.the_bfd = vars->abfd;
600
82
  sym->symbol.name    = vars->string_ptr;
601
82
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
82
  sym->symbol.section = section;
603
82
  sym->native       = ent;
604
605
82
  * vars->table_ptr = vars->sym_index;
606
82
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
82
  vars->sym_index ++;
610
82
  vars->sym_ptr ++;
611
82
  vars->sym_ptr_ptr ++;
612
82
  vars->table_ptr ++;
613
82
  vars->native_ptr ++;
614
82
  vars->esym_ptr ++;
615
82
  vars->string_ptr += len + 1;
616
617
82
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
82
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
549
130
{
550
130
  coff_symbol_type * sym;
551
130
  combined_entry_type * ent;
552
130
  SYMENT * esym;
553
130
  unsigned short sclass;
554
555
130
  if (extra_flags & BSF_LOCAL)
556
78
    sclass = C_STAT;
557
52
  else
558
52
    sclass = C_EXT;
559
560
130
#ifdef THUMBPEMAGIC
561
130
  if (vars->magic == THUMBPEMAGIC)
562
38
    {
563
38
      if (extra_flags & BSF_FUNCTION)
564
2
  sclass = C_THUMBEXTFUNC;
565
36
      else if (extra_flags & BSF_LOCAL)
566
24
  sclass = C_THUMBSTAT;
567
12
      else
568
12
  sclass = C_THUMBEXT;
569
38
    }
570
130
#endif
571
572
130
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
130
  sym = vars->sym_ptr;
575
130
  ent = vars->native_ptr;
576
130
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
130
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
130
  if (section == NULL)
582
20
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
130
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
130
      esym->e.e.e_offset);
587
130
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
130
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
130
  ent->u.syment.n_sclass    = sclass;
595
130
  ent->u.syment.n_scnum     = section->target_index;
596
130
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
130
  ent->is_sym = true;
598
599
130
  sym->symbol.the_bfd = vars->abfd;
600
130
  sym->symbol.name    = vars->string_ptr;
601
130
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
130
  sym->symbol.section = section;
603
130
  sym->native       = ent;
604
605
130
  * vars->table_ptr = vars->sym_index;
606
130
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
130
  vars->sym_index ++;
610
130
  vars->sym_ptr ++;
611
130
  vars->sym_ptr_ptr ++;
612
130
  vars->table_ptr ++;
613
130
  vars->native_ptr ++;
614
130
  vars->esym_ptr ++;
615
130
  vars->string_ptr += len + 1;
616
617
130
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
130
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
549
130
{
550
130
  coff_symbol_type * sym;
551
130
  combined_entry_type * ent;
552
130
  SYMENT * esym;
553
130
  unsigned short sclass;
554
555
130
  if (extra_flags & BSF_LOCAL)
556
78
    sclass = C_STAT;
557
52
  else
558
52
    sclass = C_EXT;
559
560
130
#ifdef THUMBPEMAGIC
561
130
  if (vars->magic == THUMBPEMAGIC)
562
38
    {
563
38
      if (extra_flags & BSF_FUNCTION)
564
2
  sclass = C_THUMBEXTFUNC;
565
36
      else if (extra_flags & BSF_LOCAL)
566
24
  sclass = C_THUMBSTAT;
567
12
      else
568
12
  sclass = C_THUMBEXT;
569
38
    }
570
130
#endif
571
572
130
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
130
  sym = vars->sym_ptr;
575
130
  ent = vars->native_ptr;
576
130
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
130
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
130
  if (section == NULL)
582
20
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
130
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
130
      esym->e.e.e_offset);
587
130
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
130
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
130
  ent->u.syment.n_sclass    = sclass;
595
130
  ent->u.syment.n_scnum     = section->target_index;
596
130
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
130
  ent->is_sym = true;
598
599
130
  sym->symbol.the_bfd = vars->abfd;
600
130
  sym->symbol.name    = vars->string_ptr;
601
130
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
130
  sym->symbol.section = section;
603
130
  sym->native       = ent;
604
605
130
  * vars->table_ptr = vars->sym_index;
606
130
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
130
  vars->sym_index ++;
610
130
  vars->sym_ptr ++;
611
130
  vars->sym_ptr_ptr ++;
612
130
  vars->table_ptr ++;
613
130
  vars->native_ptr ++;
614
130
  vars->esym_ptr ++;
615
130
  vars->string_ptr += len + 1;
616
617
130
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
130
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
549
66
{
550
66
  coff_symbol_type * sym;
551
66
  combined_entry_type * ent;
552
66
  SYMENT * esym;
553
66
  unsigned short sclass;
554
555
66
  if (extra_flags & BSF_LOCAL)
556
38
    sclass = C_STAT;
557
28
  else
558
28
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
66
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
66
  sym = vars->sym_ptr;
575
66
  ent = vars->native_ptr;
576
66
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
66
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
66
  if (section == NULL)
582
10
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
66
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
66
      esym->e.e.e_offset);
587
66
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
66
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
66
  ent->u.syment.n_sclass    = sclass;
595
66
  ent->u.syment.n_scnum     = section->target_index;
596
66
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
66
  ent->is_sym = true;
598
599
66
  sym->symbol.the_bfd = vars->abfd;
600
66
  sym->symbol.name    = vars->string_ptr;
601
66
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
66
  sym->symbol.section = section;
603
66
  sym->native       = ent;
604
605
66
  * vars->table_ptr = vars->sym_index;
606
66
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
66
  vars->sym_index ++;
610
66
  vars->sym_ptr ++;
611
66
  vars->sym_ptr_ptr ++;
612
66
  vars->table_ptr ++;
613
66
  vars->native_ptr ++;
614
66
  vars->esym_ptr ++;
615
66
  vars->string_ptr += len + 1;
616
617
66
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
66
}
619
620
/* Create a section.  */
621
622
static asection_ptr
623
pe_ILF_make_a_section (pe_ILF_vars * vars,
624
           const char *  name,
625
           unsigned int  size,
626
           flagword      extra_flags)
627
370
{
628
370
  asection_ptr sec;
629
370
  flagword     flags;
630
370
  intptr_t alignment;
631
632
370
  sec = bfd_make_section_old_way (vars->abfd, name);
633
370
  if (sec == NULL)
634
0
    return NULL;
635
636
370
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
370
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
370
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
370
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
370
  bfd_set_section_size (sec, (bfd_size_type) size);
648
370
  sec->contents = vars->data;
649
370
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
370
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
370
  if (size & 1)
659
38
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
370
#if GCC_VERSION >= 3000
666
370
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
370
  vars->data
671
370
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
370
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
370
  vars->data += sizeof (struct coff_section_tdata);
676
677
370
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
370
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
370
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
370
  return sec;
686
370
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
627
38
{
628
38
  asection_ptr sec;
629
38
  flagword     flags;
630
38
  intptr_t alignment;
631
632
38
  sec = bfd_make_section_old_way (vars->abfd, name);
633
38
  if (sec == NULL)
634
0
    return NULL;
635
636
38
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
38
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
38
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
38
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
38
  bfd_set_section_size (sec, (bfd_size_type) size);
648
38
  sec->contents = vars->data;
649
38
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
38
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
38
  if (size & 1)
659
4
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
38
#if GCC_VERSION >= 3000
666
38
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
38
  vars->data
671
38
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
38
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
38
  vars->data += sizeof (struct coff_section_tdata);
676
677
38
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
38
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
38
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
38
  return sec;
686
38
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
627
44
{
628
44
  asection_ptr sec;
629
44
  flagword     flags;
630
44
  intptr_t alignment;
631
632
44
  sec = bfd_make_section_old_way (vars->abfd, name);
633
44
  if (sec == NULL)
634
0
    return NULL;
635
636
44
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
44
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
44
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
44
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
44
  bfd_set_section_size (sec, (bfd_size_type) size);
648
44
  sec->contents = vars->data;
649
44
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
44
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
44
  if (size & 1)
659
6
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
44
#if GCC_VERSION >= 3000
666
44
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
44
  vars->data
671
44
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
44
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
44
  vars->data += sizeof (struct coff_section_tdata);
676
677
44
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
44
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
44
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
44
  return sec;
686
44
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
46
{
628
46
  asection_ptr sec;
629
46
  flagword     flags;
630
46
  intptr_t alignment;
631
632
46
  sec = bfd_make_section_old_way (vars->abfd, name);
633
46
  if (sec == NULL)
634
0
    return NULL;
635
636
46
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
46
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
46
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
46
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
46
  bfd_set_section_size (sec, (bfd_size_type) size);
648
46
  sec->contents = vars->data;
649
46
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
46
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
46
  if (size & 1)
659
6
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
46
#if GCC_VERSION >= 3000
666
46
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
46
  vars->data
671
46
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
46
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
46
  vars->data += sizeof (struct coff_section_tdata);
676
677
46
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
46
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
46
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
46
  return sec;
686
46
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
48
{
628
48
  asection_ptr sec;
629
48
  flagword     flags;
630
48
  intptr_t alignment;
631
632
48
  sec = bfd_make_section_old_way (vars->abfd, name);
633
48
  if (sec == NULL)
634
0
    return NULL;
635
636
48
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
48
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
48
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
48
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
48
  bfd_set_section_size (sec, (bfd_size_type) size);
648
48
  sec->contents = vars->data;
649
48
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
48
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
48
  if (size & 1)
659
4
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
48
#if GCC_VERSION >= 3000
666
48
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
48
  vars->data
671
48
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
48
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
48
  vars->data += sizeof (struct coff_section_tdata);
676
677
48
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
48
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
48
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
48
  return sec;
686
48
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
627
78
{
628
78
  asection_ptr sec;
629
78
  flagword     flags;
630
78
  intptr_t alignment;
631
632
78
  sec = bfd_make_section_old_way (vars->abfd, name);
633
78
  if (sec == NULL)
634
0
    return NULL;
635
636
78
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
78
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
78
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
78
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
78
  bfd_set_section_size (sec, (bfd_size_type) size);
648
78
  sec->contents = vars->data;
649
78
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
78
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
78
  if (size & 1)
659
8
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
78
#if GCC_VERSION >= 3000
666
78
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
78
  vars->data
671
78
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
78
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
78
  vars->data += sizeof (struct coff_section_tdata);
676
677
78
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
78
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
78
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
78
  return sec;
686
78
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
627
78
{
628
78
  asection_ptr sec;
629
78
  flagword     flags;
630
78
  intptr_t alignment;
631
632
78
  sec = bfd_make_section_old_way (vars->abfd, name);
633
78
  if (sec == NULL)
634
0
    return NULL;
635
636
78
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
78
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
78
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
78
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
78
  bfd_set_section_size (sec, (bfd_size_type) size);
648
78
  sec->contents = vars->data;
649
78
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
78
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
78
  if (size & 1)
659
8
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
78
#if GCC_VERSION >= 3000
666
78
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
78
  vars->data
671
78
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
78
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
78
  vars->data += sizeof (struct coff_section_tdata);
676
677
78
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
78
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
78
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
78
  return sec;
686
78
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
627
38
{
628
38
  asection_ptr sec;
629
38
  flagword     flags;
630
38
  intptr_t alignment;
631
632
38
  sec = bfd_make_section_old_way (vars->abfd, name);
633
38
  if (sec == NULL)
634
0
    return NULL;
635
636
38
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
38
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
38
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
38
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
38
  bfd_set_section_size (sec, (bfd_size_type) size);
648
38
  sec->contents = vars->data;
649
38
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
38
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
38
  if (size & 1)
659
2
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
38
#if GCC_VERSION >= 3000
666
38
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
38
  vars->data
671
38
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
38
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
38
  vars->data += sizeof (struct coff_section_tdata);
676
677
38
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
38
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
38
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
38
  return sec;
686
38
}
687
688
/* This structure contains the code that goes into the .text section
689
   in order to perform a jump into the DLL lookup table.  The entries
690
   in the table are index by the magic number used to represent the
691
   machine type in the PE file.  The contents of the data[] arrays in
692
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
693
   The SIZE field says how many bytes in the DATA array are actually
694
   used.  The OFFSET field says where in the data array the address
695
   of the .idata$5 section should be placed.  */
696
228
#define MAX_TEXT_SECTION_SIZE 32
697
698
typedef struct
699
{
700
  unsigned short magic;
701
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
702
  unsigned int   size;
703
  unsigned int   offset;
704
}
705
jump_table;
706
707
static const jump_table jtab[] =
708
{
709
#ifdef I386MAGIC
710
  { I386MAGIC,
711
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
712
    8, 2
713
  },
714
#endif
715
716
#ifdef AMD64MAGIC
717
  { AMD64MAGIC,
718
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
719
    8, 2
720
  },
721
#endif
722
723
#ifdef  MC68MAGIC
724
  { MC68MAGIC,
725
    { /* XXX fill me in */ },
726
    0, 0
727
  },
728
#endif
729
730
#ifdef  MIPS_ARCH_MAGIC_WINCE
731
  { MIPS_ARCH_MAGIC_WINCE,
732
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
733
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
734
    16, 0
735
  },
736
#endif
737
738
#ifdef  SH_ARCH_MAGIC_WINCE
739
  { SH_ARCH_MAGIC_WINCE,
740
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
741
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
742
    12, 8
743
  },
744
#endif
745
746
#ifdef AARCH64MAGIC
747
/* We don't currently support jumping to DLLs, so if
748
   someone does try emit a runtime trap.  Through UDF #0.  */
749
  { AARCH64MAGIC,
750
    { 0x00, 0x00, 0x00, 0x00 },
751
    4, 0
752
  },
753
754
#endif
755
756
#ifdef  ARMPEMAGIC
757
  { ARMPEMAGIC,
758
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
759
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
760
    12, 8
761
  },
762
#endif
763
764
#ifdef  THUMBPEMAGIC
765
  { THUMBPEMAGIC,
766
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
767
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
768
    16, 12
769
  },
770
#endif
771
772
#ifdef LOONGARCH64MAGIC
773
/* We don't currently support jumping to DLLs, so if
774
   someone does try emit a runtime trap.  Through BREAK 0.  */
775
  { LOONGARCH64MAGIC,
776
    { 0x00, 0x00, 0x2a, 0x00 },
777
    4, 0
778
  },
779
780
#endif
781
782
  { 0, { 0 }, 0, 0 }
783
};
784
785
#ifndef NUM_ENTRIES
786
64
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
787
#endif
788
789
/* Build a full BFD from the information supplied in a ILF object.  */
790
791
static bool
792
pe_ILF_build_a_bfd (bfd *     abfd,
793
        unsigned int    magic,
794
        char *      symbol_name,
795
        char *      source_dll,
796
        unsigned int    ordinal,
797
        unsigned int    types)
798
166
{
799
166
  bfd_byte *       ptr;
800
166
  pe_ILF_vars      vars;
801
166
  struct internal_filehdr  internal_f;
802
166
  unsigned int       import_type;
803
166
  unsigned int       import_name_type;
804
166
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
166
  coff_symbol_type **    imp_sym;
806
166
  unsigned int       imp_index;
807
166
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
166
  import_type = types & 0x3;
811
166
  import_name_type = (types & 0x1c) >> 2;
812
813
166
  switch (import_type)
814
166
    {
815
90
    case IMPORT_CODE:
816
130
    case IMPORT_DATA:
817
130
      break;
818
819
22
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
22
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
22
        abfd, import_type);
824
22
      return false;
825
826
14
    default:
827
      /* xgettext:c-format */
828
14
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
14
        abfd, import_type);
830
14
      return false;
831
166
    }
832
833
130
  switch (import_name_type)
834
130
    {
835
36
    case IMPORT_ORDINAL:
836
50
    case IMPORT_NAME:
837
72
    case IMPORT_NAME_NOPREFIX:
838
114
    case IMPORT_NAME_UNDECORATE:
839
114
      break;
840
841
16
    default:
842
      /* xgettext:c-format */
843
16
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
16
        abfd, import_name_type);
845
16
      return false;
846
130
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
114
  vars.bim
856
114
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
114
  if (vars.bim == NULL)
858
0
    return false;
859
860
114
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
114
  vars.bim->buffer = ptr;
862
114
  vars.bim->size   = ILF_DATA_SIZE;
863
114
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
114
  vars.sym_cache = (coff_symbol_type *) ptr;
869
114
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
114
  vars.sym_index = 0;
871
114
  ptr += SIZEOF_ILF_SYMS;
872
873
114
  vars.sym_table = (unsigned int *) ptr;
874
114
  vars.table_ptr = (unsigned int *) ptr;
875
114
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
114
  vars.native_syms = (combined_entry_type *) ptr;
878
114
  vars.native_ptr  = (combined_entry_type *) ptr;
879
114
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
114
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
114
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
114
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
114
  vars.esym_table = (SYMENT *) ptr;
886
114
  vars.esym_ptr   = (SYMENT *) ptr;
887
114
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
114
  vars.reltab   = (arelent *) ptr;
890
114
  vars.relcount = 0;
891
114
  ptr += SIZEOF_ILF_RELOCS;
892
893
114
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
114
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
114
  vars.string_table = (char *) ptr;
897
114
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
114
  ptr += SIZEOF_ILF_STRINGS;
899
114
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
114
#if GCC_VERSION >= 3000
909
114
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
114
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
114
  vars.data = ptr;
916
114
  vars.abfd = abfd;
917
114
  vars.sec_index = 0;
918
114
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
114
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
114
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
114
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
114
  if (import_name_type == IMPORT_ORDINAL)
934
36
    {
935
36
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
18
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
8
      ((unsigned int *) id4->contents)[0] = ordinal;
941
8
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
8
      ((unsigned int *) id5->contents)[0] = ordinal;
943
8
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
10
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
10
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
10
#endif
948
10
    }
949
78
  else
950
78
    {
951
78
      char * symbol;
952
78
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
78
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
78
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
78
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
78
      if (import_name_type != IMPORT_NAME)
970
64
  {
971
64
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
64
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
64
        || c == '@' || c == '?')
977
18
      symbol++;
978
64
  }
979
980
78
      len = strlen (symbol);
981
78
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
42
  {
983
    /* Truncate at the first '@'.  */
984
42
    char *at = strchr (symbol, '@');
985
986
42
    if (at != NULL)
987
8
      len = at - symbol;
988
42
  }
989
990
78
      id6->contents[0] = ordinal & 0xff;
991
78
      id6->contents[1] = ordinal >> 8;
992
993
78
      memcpy ((char *) id6->contents + 2, symbol, len);
994
78
      id6->contents[len + 2] = '\0';
995
78
    }
996
997
96
  if (import_name_type != IMPORT_ORDINAL)
998
78
    {
999
78
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
78
      pe_ILF_save_relocs (&vars, id4);
1001
1002
78
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
78
      pe_ILF_save_relocs (&vars, id5);
1004
78
    }
1005
1006
  /* Create an import symbol.  */
1007
96
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
96
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
96
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
96
  switch (import_type)
1013
96
    {
1014
0
      int i;
1015
1016
64
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
148
      for (i = NUM_ENTRIES (jtab); i--;)
1021
148
  {
1022
148
    if (jtab[i].size == 0)
1023
64
      continue;
1024
84
    if (jtab[i].magic == magic)
1025
64
      break;
1026
84
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
64
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
64
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
64
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
64
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
6
      if (magic == AMD64MAGIC)
1055
6
  {
1056
6
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
6
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
6
              imp_index);
1059
6
  }
1060
0
      else
1061
0
#endif
1062
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
0
            imp_index);
1065
1066
64
      pe_ILF_save_relocs (& vars, text);
1067
64
      break;
1068
1069
32
    case IMPORT_DATA:
1070
32
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
96
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
96
  switch (import_type)
1079
96
    {
1080
64
    case IMPORT_CODE:
1081
64
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
64
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
64
      break;
1085
1086
32
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
32
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
96
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
96
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
96
  if (ptr)
1098
12
    * ptr = 0;
1099
96
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
96
  if (ptr)
1101
12
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
96
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
96
  internal_f.f_magic  = magic;
1107
96
  internal_f.f_symptr = 0;
1108
96
  internal_f.f_nsyms  = 0;
1109
96
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
96
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
96
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
96
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
96
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
40
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
12
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
96
  bfd_cache_close (abfd);
1127
1128
96
  abfd->iostream = (void *) vars.bim;
1129
96
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
96
  abfd->iovec = &_bfd_memory_iovec;
1131
96
  abfd->where = 0;
1132
96
  abfd->origin = 0;
1133
96
  abfd->size = 0;
1134
96
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
96
  obj_symbols (abfd) = vars.sym_cache;
1138
96
  abfd->symcount = vars.sym_index;
1139
1140
96
  obj_raw_syments (abfd) = vars.native_syms;
1141
96
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
96
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
96
  obj_coff_keep_syms (abfd) = true;
1145
1146
96
  obj_convert (abfd) = vars.sym_table;
1147
96
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
96
  obj_coff_strings (abfd) = vars.string_table;
1150
96
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
96
  obj_coff_keep_strings (abfd) = true;
1152
1153
96
  return true;
1154
1155
18
 error_return:
1156
18
  free (vars.bim->buffer);
1157
18
  free (vars.bim);
1158
18
  return false;
1159
96
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
798
18
{
799
18
  bfd_byte *       ptr;
800
18
  pe_ILF_vars      vars;
801
18
  struct internal_filehdr  internal_f;
802
18
  unsigned int       import_type;
803
18
  unsigned int       import_name_type;
804
18
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
18
  coff_symbol_type **    imp_sym;
806
18
  unsigned int       imp_index;
807
18
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
18
  import_type = types & 0x3;
811
18
  import_name_type = (types & 0x1c) >> 2;
812
813
18
  switch (import_type)
814
18
    {
815
10
    case IMPORT_CODE:
816
14
    case IMPORT_DATA:
817
14
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
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
18
    }
832
833
14
  switch (import_name_type)
834
14
    {
835
4
    case IMPORT_ORDINAL:
836
6
    case IMPORT_NAME:
837
8
    case IMPORT_NAME_NOPREFIX:
838
12
    case IMPORT_NAME_UNDECORATE:
839
12
      break;
840
841
2
    default:
842
      /* xgettext:c-format */
843
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
2
        abfd, import_name_type);
845
2
      return false;
846
14
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
12
  vars.bim
856
12
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
12
  if (vars.bim == NULL)
858
0
    return false;
859
860
12
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
12
  vars.bim->buffer = ptr;
862
12
  vars.bim->size   = ILF_DATA_SIZE;
863
12
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
12
  vars.sym_cache = (coff_symbol_type *) ptr;
869
12
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
12
  vars.sym_index = 0;
871
12
  ptr += SIZEOF_ILF_SYMS;
872
873
12
  vars.sym_table = (unsigned int *) ptr;
874
12
  vars.table_ptr = (unsigned int *) ptr;
875
12
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
12
  vars.native_syms = (combined_entry_type *) ptr;
878
12
  vars.native_ptr  = (combined_entry_type *) ptr;
879
12
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
12
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
12
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
12
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
12
  vars.esym_table = (SYMENT *) ptr;
886
12
  vars.esym_ptr   = (SYMENT *) ptr;
887
12
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
12
  vars.reltab   = (arelent *) ptr;
890
12
  vars.relcount = 0;
891
12
  ptr += SIZEOF_ILF_RELOCS;
892
893
12
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
12
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
12
  vars.string_table = (char *) ptr;
897
12
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
12
  ptr += SIZEOF_ILF_STRINGS;
899
12
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
12
#if GCC_VERSION >= 3000
909
12
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
12
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
12
  vars.data = ptr;
916
12
  vars.abfd = abfd;
917
12
  vars.sec_index = 0;
918
12
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
12
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
12
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
12
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
12
  if (import_name_type == IMPORT_ORDINAL)
934
4
    {
935
4
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
2
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
2
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
2
#endif
948
2
    }
949
8
  else
950
8
    {
951
8
      char * symbol;
952
8
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
8
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
8
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
8
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
8
      if (import_name_type != IMPORT_NAME)
970
6
  {
971
6
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
6
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
6
        || c == '@' || c == '?')
977
4
      symbol++;
978
6
  }
979
980
8
      len = strlen (symbol);
981
8
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
4
  {
983
    /* Truncate at the first '@'.  */
984
4
    char *at = strchr (symbol, '@');
985
986
4
    if (at != NULL)
987
0
      len = at - symbol;
988
4
  }
989
990
8
      id6->contents[0] = ordinal & 0xff;
991
8
      id6->contents[1] = ordinal >> 8;
992
993
8
      memcpy ((char *) id6->contents + 2, symbol, len);
994
8
      id6->contents[len + 2] = '\0';
995
8
    }
996
997
10
  if (import_name_type != IMPORT_ORDINAL)
998
8
    {
999
8
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
8
      pe_ILF_save_relocs (&vars, id4);
1001
1002
8
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
8
      pe_ILF_save_relocs (&vars, id5);
1004
8
    }
1005
1006
  /* Create an import symbol.  */
1007
10
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
10
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
10
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
10
  switch (import_type)
1013
10
    {
1014
0
      int i;
1015
1016
6
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
12
      for (i = NUM_ENTRIES (jtab); i--;)
1021
12
  {
1022
12
    if (jtab[i].size == 0)
1023
6
      continue;
1024
6
    if (jtab[i].magic == magic)
1025
6
      break;
1026
6
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
6
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
6
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
6
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
6
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
6
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
6
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
6
            imp_index);
1065
1066
6
      pe_ILF_save_relocs (& vars, text);
1067
6
      break;
1068
1069
4
    case IMPORT_DATA:
1070
4
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
10
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
10
  switch (import_type)
1079
10
    {
1080
6
    case IMPORT_CODE:
1081
6
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
6
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
6
      break;
1085
1086
4
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
4
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
10
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
10
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
10
  if (ptr)
1098
2
    * ptr = 0;
1099
10
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
10
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
10
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
10
  internal_f.f_magic  = magic;
1107
10
  internal_f.f_symptr = 0;
1108
10
  internal_f.f_nsyms  = 0;
1109
10
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
10
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
10
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
10
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
10
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
10
  bfd_cache_close (abfd);
1127
1128
10
  abfd->iostream = (void *) vars.bim;
1129
10
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
10
  abfd->iovec = &_bfd_memory_iovec;
1131
10
  abfd->where = 0;
1132
10
  abfd->origin = 0;
1133
10
  abfd->size = 0;
1134
10
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
10
  obj_symbols (abfd) = vars.sym_cache;
1138
10
  abfd->symcount = vars.sym_index;
1139
1140
10
  obj_raw_syments (abfd) = vars.native_syms;
1141
10
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
10
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
10
  obj_coff_keep_syms (abfd) = true;
1145
1146
10
  obj_convert (abfd) = vars.sym_table;
1147
10
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
10
  obj_coff_strings (abfd) = vars.string_table;
1150
10
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
10
  obj_coff_keep_strings (abfd) = true;
1152
1153
10
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
10
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
20
{
799
20
  bfd_byte *       ptr;
800
20
  pe_ILF_vars      vars;
801
20
  struct internal_filehdr  internal_f;
802
20
  unsigned int       import_type;
803
20
  unsigned int       import_name_type;
804
20
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
20
  coff_symbol_type **    imp_sym;
806
20
  unsigned int       imp_index;
807
20
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
20
  import_type = types & 0x3;
811
20
  import_name_type = (types & 0x1c) >> 2;
812
813
20
  switch (import_type)
814
20
    {
815
10
    case IMPORT_CODE:
816
16
    case IMPORT_DATA:
817
16
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
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
20
    }
832
833
16
  switch (import_name_type)
834
16
    {
835
4
    case IMPORT_ORDINAL:
836
6
    case IMPORT_NAME:
837
8
    case IMPORT_NAME_NOPREFIX:
838
14
    case IMPORT_NAME_UNDECORATE:
839
14
      break;
840
841
2
    default:
842
      /* xgettext:c-format */
843
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
2
        abfd, import_name_type);
845
2
      return false;
846
16
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
14
  vars.bim
856
14
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
14
  if (vars.bim == NULL)
858
0
    return false;
859
860
14
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
14
  vars.bim->buffer = ptr;
862
14
  vars.bim->size   = ILF_DATA_SIZE;
863
14
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
14
  vars.sym_cache = (coff_symbol_type *) ptr;
869
14
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
14
  vars.sym_index = 0;
871
14
  ptr += SIZEOF_ILF_SYMS;
872
873
14
  vars.sym_table = (unsigned int *) ptr;
874
14
  vars.table_ptr = (unsigned int *) ptr;
875
14
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
14
  vars.native_syms = (combined_entry_type *) ptr;
878
14
  vars.native_ptr  = (combined_entry_type *) ptr;
879
14
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
14
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
14
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
14
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
14
  vars.esym_table = (SYMENT *) ptr;
886
14
  vars.esym_ptr   = (SYMENT *) ptr;
887
14
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
14
  vars.reltab   = (arelent *) ptr;
890
14
  vars.relcount = 0;
891
14
  ptr += SIZEOF_ILF_RELOCS;
892
893
14
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
14
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
14
  vars.string_table = (char *) ptr;
897
14
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
14
  ptr += SIZEOF_ILF_STRINGS;
899
14
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
14
#if GCC_VERSION >= 3000
909
14
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
14
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
14
  vars.data = ptr;
916
14
  vars.abfd = abfd;
917
14
  vars.sec_index = 0;
918
14
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
14
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
14
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
14
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
14
  if (import_name_type == IMPORT_ORDINAL)
934
4
    {
935
4
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
2
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
2
      ((unsigned int *) id4->contents)[0] = ordinal;
941
2
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
2
      ((unsigned int *) id5->contents)[0] = ordinal;
943
2
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
2
    }
949
10
  else
950
10
    {
951
10
      char * symbol;
952
10
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
10
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
10
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
10
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
10
      if (import_name_type != IMPORT_NAME)
970
8
  {
971
8
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
8
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
8
        || c == '@' || c == '?')
977
2
      symbol++;
978
8
  }
979
980
10
      len = strlen (symbol);
981
10
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
6
  {
983
    /* Truncate at the first '@'.  */
984
6
    char *at = strchr (symbol, '@');
985
986
6
    if (at != NULL)
987
0
      len = at - symbol;
988
6
  }
989
990
10
      id6->contents[0] = ordinal & 0xff;
991
10
      id6->contents[1] = ordinal >> 8;
992
993
10
      memcpy ((char *) id6->contents + 2, symbol, len);
994
10
      id6->contents[len + 2] = '\0';
995
10
    }
996
997
12
  if (import_name_type != IMPORT_ORDINAL)
998
10
    {
999
10
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
10
      pe_ILF_save_relocs (&vars, id4);
1001
1002
10
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
10
      pe_ILF_save_relocs (&vars, id5);
1004
10
    }
1005
1006
  /* Create an import symbol.  */
1007
12
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
12
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
12
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
12
  switch (import_type)
1013
12
    {
1014
0
      int i;
1015
1016
6
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
12
      for (i = NUM_ENTRIES (jtab); i--;)
1021
12
  {
1022
12
    if (jtab[i].size == 0)
1023
6
      continue;
1024
6
    if (jtab[i].magic == magic)
1025
6
      break;
1026
6
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
6
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
6
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
6
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
6
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
6
#ifdef AMD64MAGIC
1054
6
      if (magic == AMD64MAGIC)
1055
6
  {
1056
6
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
6
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
6
              imp_index);
1059
6
  }
1060
0
      else
1061
0
#endif
1062
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
0
            imp_index);
1065
1066
6
      pe_ILF_save_relocs (& vars, text);
1067
6
      break;
1068
1069
6
    case IMPORT_DATA:
1070
6
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
12
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
12
  switch (import_type)
1079
12
    {
1080
6
    case IMPORT_CODE:
1081
6
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
6
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
6
      break;
1085
1086
6
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
6
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
12
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
12
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
12
  if (ptr)
1098
2
    * ptr = 0;
1099
12
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
12
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
12
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
12
  internal_f.f_magic  = magic;
1107
12
  internal_f.f_symptr = 0;
1108
12
  internal_f.f_nsyms  = 0;
1109
12
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
12
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
12
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
12
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
12
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
12
  bfd_cache_close (abfd);
1127
1128
12
  abfd->iostream = (void *) vars.bim;
1129
12
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
12
  abfd->iovec = &_bfd_memory_iovec;
1131
12
  abfd->where = 0;
1132
12
  abfd->origin = 0;
1133
12
  abfd->size = 0;
1134
12
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
12
  obj_symbols (abfd) = vars.sym_cache;
1138
12
  abfd->symcount = vars.sym_index;
1139
1140
12
  obj_raw_syments (abfd) = vars.native_syms;
1141
12
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
12
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
12
  obj_coff_keep_syms (abfd) = true;
1145
1146
12
  obj_convert (abfd) = vars.sym_table;
1147
12
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
12
  obj_coff_strings (abfd) = vars.string_table;
1150
12
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
12
  obj_coff_keep_strings (abfd) = true;
1152
1153
12
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
12
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
20
{
799
20
  bfd_byte *       ptr;
800
20
  pe_ILF_vars      vars;
801
20
  struct internal_filehdr  internal_f;
802
20
  unsigned int       import_type;
803
20
  unsigned int       import_name_type;
804
20
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
20
  coff_symbol_type **    imp_sym;
806
20
  unsigned int       imp_index;
807
20
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
20
  import_type = types & 0x3;
811
20
  import_name_type = (types & 0x1c) >> 2;
812
813
20
  switch (import_type)
814
20
    {
815
14
    case IMPORT_CODE:
816
16
    case IMPORT_DATA:
817
16
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
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
20
    }
832
833
16
  switch (import_name_type)
834
16
    {
835
6
    case IMPORT_ORDINAL:
836
8
    case IMPORT_NAME:
837
8
    case IMPORT_NAME_NOPREFIX:
838
14
    case IMPORT_NAME_UNDECORATE:
839
14
      break;
840
841
2
    default:
842
      /* xgettext:c-format */
843
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
2
        abfd, import_name_type);
845
2
      return false;
846
16
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
14
  vars.bim
856
14
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
14
  if (vars.bim == NULL)
858
0
    return false;
859
860
14
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
14
  vars.bim->buffer = ptr;
862
14
  vars.bim->size   = ILF_DATA_SIZE;
863
14
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
14
  vars.sym_cache = (coff_symbol_type *) ptr;
869
14
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
14
  vars.sym_index = 0;
871
14
  ptr += SIZEOF_ILF_SYMS;
872
873
14
  vars.sym_table = (unsigned int *) ptr;
874
14
  vars.table_ptr = (unsigned int *) ptr;
875
14
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
14
  vars.native_syms = (combined_entry_type *) ptr;
878
14
  vars.native_ptr  = (combined_entry_type *) ptr;
879
14
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
14
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
14
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
14
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
14
  vars.esym_table = (SYMENT *) ptr;
886
14
  vars.esym_ptr   = (SYMENT *) ptr;
887
14
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
14
  vars.reltab   = (arelent *) ptr;
890
14
  vars.relcount = 0;
891
14
  ptr += SIZEOF_ILF_RELOCS;
892
893
14
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
14
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
14
  vars.string_table = (char *) ptr;
897
14
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
14
  ptr += SIZEOF_ILF_STRINGS;
899
14
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
14
#if GCC_VERSION >= 3000
909
14
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
14
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
14
  vars.data = ptr;
916
14
  vars.abfd = abfd;
917
14
  vars.sec_index = 0;
918
14
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
14
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
14
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
14
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
14
  if (import_name_type == IMPORT_ORDINAL)
934
6
    {
935
6
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
4
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
4
      ((unsigned int *) id4->contents)[0] = ordinal;
941
4
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
4
      ((unsigned int *) id5->contents)[0] = ordinal;
943
4
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
4
    }
949
8
  else
950
8
    {
951
8
      char * symbol;
952
8
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
8
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
8
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
8
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
8
      if (import_name_type != IMPORT_NAME)
970
6
  {
971
6
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
6
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
6
        || c == '@' || c == '?')
977
2
      symbol++;
978
6
  }
979
980
8
      len = strlen (symbol);
981
8
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
6
  {
983
    /* Truncate at the first '@'.  */
984
6
    char *at = strchr (symbol, '@');
985
986
6
    if (at != NULL)
987
0
      len = at - symbol;
988
6
  }
989
990
8
      id6->contents[0] = ordinal & 0xff;
991
8
      id6->contents[1] = ordinal >> 8;
992
993
8
      memcpy ((char *) id6->contents + 2, symbol, len);
994
8
      id6->contents[len + 2] = '\0';
995
8
    }
996
997
12
  if (import_name_type != IMPORT_ORDINAL)
998
8
    {
999
8
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
8
      pe_ILF_save_relocs (&vars, id4);
1001
1002
8
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
8
      pe_ILF_save_relocs (&vars, id5);
1004
8
    }
1005
1006
  /* Create an import symbol.  */
1007
12
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
12
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
12
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
12
  switch (import_type)
1013
12
    {
1014
0
      int i;
1015
1016
10
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
20
      for (i = NUM_ENTRIES (jtab); i--;)
1021
20
  {
1022
20
    if (jtab[i].size == 0)
1023
10
      continue;
1024
10
    if (jtab[i].magic == magic)
1025
10
      break;
1026
10
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
10
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
10
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
10
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
10
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
10
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
10
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
10
            imp_index);
1065
1066
10
      pe_ILF_save_relocs (& vars, text);
1067
10
      break;
1068
1069
2
    case IMPORT_DATA:
1070
2
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
12
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
12
  switch (import_type)
1079
12
    {
1080
10
    case IMPORT_CODE:
1081
10
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
10
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
10
      break;
1085
1086
2
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
2
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
12
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
12
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
12
  if (ptr)
1098
2
    * ptr = 0;
1099
12
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
12
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
12
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
12
  internal_f.f_magic  = magic;
1107
12
  internal_f.f_symptr = 0;
1108
12
  internal_f.f_nsyms  = 0;
1109
12
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
12
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
12
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
12
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
12
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
12
  bfd_cache_close (abfd);
1127
1128
12
  abfd->iostream = (void *) vars.bim;
1129
12
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
12
  abfd->iovec = &_bfd_memory_iovec;
1131
12
  abfd->where = 0;
1132
12
  abfd->origin = 0;
1133
12
  abfd->size = 0;
1134
12
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
12
  obj_symbols (abfd) = vars.sym_cache;
1138
12
  abfd->symcount = vars.sym_index;
1139
1140
12
  obj_raw_syments (abfd) = vars.native_syms;
1141
12
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
12
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
12
  obj_coff_keep_syms (abfd) = true;
1145
1146
12
  obj_convert (abfd) = vars.sym_table;
1147
12
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
12
  obj_coff_strings (abfd) = vars.string_table;
1150
12
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
12
  obj_coff_keep_strings (abfd) = true;
1152
1153
12
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
12
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
18
{
799
18
  bfd_byte *       ptr;
800
18
  pe_ILF_vars      vars;
801
18
  struct internal_filehdr  internal_f;
802
18
  unsigned int       import_type;
803
18
  unsigned int       import_name_type;
804
18
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
18
  coff_symbol_type **    imp_sym;
806
18
  unsigned int       imp_index;
807
18
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
18
  import_type = types & 0x3;
811
18
  import_name_type = (types & 0x1c) >> 2;
812
813
18
  switch (import_type)
814
18
    {
815
12
    case IMPORT_CODE:
816
14
    case IMPORT_DATA:
817
14
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
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
18
    }
832
833
14
  switch (import_name_type)
834
14
    {
835
4
    case IMPORT_ORDINAL:
836
6
    case IMPORT_NAME:
837
6
    case IMPORT_NAME_NOPREFIX:
838
14
    case IMPORT_NAME_UNDECORATE:
839
14
      break;
840
841
0
    default:
842
      /* xgettext:c-format */
843
0
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
0
        abfd, import_name_type);
845
0
      return false;
846
14
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
14
  vars.bim
856
14
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
14
  if (vars.bim == NULL)
858
0
    return false;
859
860
14
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
14
  vars.bim->buffer = ptr;
862
14
  vars.bim->size   = ILF_DATA_SIZE;
863
14
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
14
  vars.sym_cache = (coff_symbol_type *) ptr;
869
14
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
14
  vars.sym_index = 0;
871
14
  ptr += SIZEOF_ILF_SYMS;
872
873
14
  vars.sym_table = (unsigned int *) ptr;
874
14
  vars.table_ptr = (unsigned int *) ptr;
875
14
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
14
  vars.native_syms = (combined_entry_type *) ptr;
878
14
  vars.native_ptr  = (combined_entry_type *) ptr;
879
14
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
14
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
14
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
14
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
14
  vars.esym_table = (SYMENT *) ptr;
886
14
  vars.esym_ptr   = (SYMENT *) ptr;
887
14
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
14
  vars.reltab   = (arelent *) ptr;
890
14
  vars.relcount = 0;
891
14
  ptr += SIZEOF_ILF_RELOCS;
892
893
14
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
14
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
14
  vars.string_table = (char *) ptr;
897
14
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
14
  ptr += SIZEOF_ILF_STRINGS;
899
14
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
14
#if GCC_VERSION >= 3000
909
14
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
14
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
14
  vars.data = ptr;
916
14
  vars.abfd = abfd;
917
14
  vars.sec_index = 0;
918
14
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
14
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
14
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
14
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
14
  if (import_name_type == IMPORT_ORDINAL)
934
4
    {
935
4
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
2
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
2
      ((unsigned int *) id4->contents)[0] = ordinal;
941
2
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
2
      ((unsigned int *) id5->contents)[0] = ordinal;
943
2
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
2
    }
949
10
  else
950
10
    {
951
10
      char * symbol;
952
10
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
10
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
10
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
10
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
10
      if (import_name_type != IMPORT_NAME)
970
8
  {
971
8
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
8
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
8
        || c == '@' || c == '?')
977
2
      symbol++;
978
8
  }
979
980
10
      len = strlen (symbol);
981
10
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
8
  {
983
    /* Truncate at the first '@'.  */
984
8
    char *at = strchr (symbol, '@');
985
986
8
    if (at != NULL)
987
0
      len = at - symbol;
988
8
  }
989
990
10
      id6->contents[0] = ordinal & 0xff;
991
10
      id6->contents[1] = ordinal >> 8;
992
993
10
      memcpy ((char *) id6->contents + 2, symbol, len);
994
10
      id6->contents[len + 2] = '\0';
995
10
    }
996
997
12
  if (import_name_type != IMPORT_ORDINAL)
998
10
    {
999
10
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
10
      pe_ILF_save_relocs (&vars, id4);
1001
1002
10
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
10
      pe_ILF_save_relocs (&vars, id5);
1004
10
    }
1005
1006
  /* Create an import symbol.  */
1007
12
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
12
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
12
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
12
  switch (import_type)
1013
12
    {
1014
0
      int i;
1015
1016
10
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
20
      for (i = NUM_ENTRIES (jtab); i--;)
1021
20
  {
1022
20
    if (jtab[i].size == 0)
1023
10
      continue;
1024
10
    if (jtab[i].magic == magic)
1025
10
      break;
1026
10
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
10
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
10
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
10
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
10
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
10
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
10
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
10
            imp_index);
1065
1066
10
      pe_ILF_save_relocs (& vars, text);
1067
10
      break;
1068
1069
2
    case IMPORT_DATA:
1070
2
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
12
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
12
  switch (import_type)
1079
12
    {
1080
10
    case IMPORT_CODE:
1081
10
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
10
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
10
      break;
1085
1086
2
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
2
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
12
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
12
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
12
  if (ptr)
1098
2
    * ptr = 0;
1099
12
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
12
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
12
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
12
  internal_f.f_magic  = magic;
1107
12
  internal_f.f_symptr = 0;
1108
12
  internal_f.f_nsyms  = 0;
1109
12
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
12
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
12
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
12
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
12
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
12
  bfd_cache_close (abfd);
1127
1128
12
  abfd->iostream = (void *) vars.bim;
1129
12
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
12
  abfd->iovec = &_bfd_memory_iovec;
1131
12
  abfd->where = 0;
1132
12
  abfd->origin = 0;
1133
12
  abfd->size = 0;
1134
12
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
12
  obj_symbols (abfd) = vars.sym_cache;
1138
12
  abfd->symcount = vars.sym_index;
1139
1140
12
  obj_raw_syments (abfd) = vars.native_syms;
1141
12
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
12
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
12
  obj_coff_keep_syms (abfd) = true;
1145
1146
12
  obj_convert (abfd) = vars.sym_table;
1147
12
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
12
  obj_coff_strings (abfd) = vars.string_table;
1150
12
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
12
  obj_coff_keep_strings (abfd) = true;
1152
1153
12
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
12
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
798
36
{
799
36
  bfd_byte *       ptr;
800
36
  pe_ILF_vars      vars;
801
36
  struct internal_filehdr  internal_f;
802
36
  unsigned int       import_type;
803
36
  unsigned int       import_name_type;
804
36
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
36
  coff_symbol_type **    imp_sym;
806
36
  unsigned int       imp_index;
807
36
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
36
  import_type = types & 0x3;
811
36
  import_name_type = (types & 0x1c) >> 2;
812
813
36
  switch (import_type)
814
36
    {
815
16
    case IMPORT_CODE:
816
28
    case IMPORT_DATA:
817
28
      break;
818
819
6
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
6
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
6
        abfd, import_type);
824
6
      return false;
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
36
    }
832
833
28
  switch (import_name_type)
834
28
    {
835
6
    case IMPORT_ORDINAL:
836
8
    case IMPORT_NAME:
837
16
    case IMPORT_NAME_NOPREFIX:
838
24
    case IMPORT_NAME_UNDECORATE:
839
24
      break;
840
841
4
    default:
842
      /* xgettext:c-format */
843
4
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
4
        abfd, import_name_type);
845
4
      return false;
846
28
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
24
  vars.bim
856
24
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
24
  if (vars.bim == NULL)
858
0
    return false;
859
860
24
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
24
  vars.bim->buffer = ptr;
862
24
  vars.bim->size   = ILF_DATA_SIZE;
863
24
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
24
  vars.sym_cache = (coff_symbol_type *) ptr;
869
24
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
24
  vars.sym_index = 0;
871
24
  ptr += SIZEOF_ILF_SYMS;
872
873
24
  vars.sym_table = (unsigned int *) ptr;
874
24
  vars.table_ptr = (unsigned int *) ptr;
875
24
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
24
  vars.native_syms = (combined_entry_type *) ptr;
878
24
  vars.native_ptr  = (combined_entry_type *) ptr;
879
24
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
24
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
24
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
24
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
24
  vars.esym_table = (SYMENT *) ptr;
886
24
  vars.esym_ptr   = (SYMENT *) ptr;
887
24
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
24
  vars.reltab   = (arelent *) ptr;
890
24
  vars.relcount = 0;
891
24
  ptr += SIZEOF_ILF_RELOCS;
892
893
24
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
24
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
24
  vars.string_table = (char *) ptr;
897
24
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
24
  ptr += SIZEOF_ILF_STRINGS;
899
24
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
24
#if GCC_VERSION >= 3000
909
24
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
24
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
24
  vars.data = ptr;
916
24
  vars.abfd = abfd;
917
24
  vars.sec_index = 0;
918
24
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
24
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
24
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
24
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
24
  if (import_name_type == IMPORT_ORDINAL)
934
6
    {
935
6
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
4
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
2
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
2
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
2
#endif
948
2
    }
949
18
  else
950
18
    {
951
18
      char * symbol;
952
18
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
18
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
18
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
18
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
18
      if (import_name_type != IMPORT_NAME)
970
16
  {
971
16
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
16
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
16
        || c == '@' || c == '?')
977
2
      symbol++;
978
16
  }
979
980
18
      len = strlen (symbol);
981
18
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
8
  {
983
    /* Truncate at the first '@'.  */
984
8
    char *at = strchr (symbol, '@');
985
986
8
    if (at != NULL)
987
4
      len = at - symbol;
988
8
  }
989
990
18
      id6->contents[0] = ordinal & 0xff;
991
18
      id6->contents[1] = ordinal >> 8;
992
993
18
      memcpy ((char *) id6->contents + 2, symbol, len);
994
18
      id6->contents[len + 2] = '\0';
995
18
    }
996
997
20
  if (import_name_type != IMPORT_ORDINAL)
998
18
    {
999
18
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
18
      pe_ILF_save_relocs (&vars, id4);
1001
1002
18
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
18
      pe_ILF_save_relocs (&vars, id5);
1004
18
    }
1005
1006
  /* Create an import symbol.  */
1007
20
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
20
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
20
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
20
  switch (import_type)
1013
20
    {
1014
0
      int i;
1015
1016
12
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
34
      for (i = NUM_ENTRIES (jtab); i--;)
1021
34
  {
1022
34
    if (jtab[i].size == 0)
1023
12
      continue;
1024
22
    if (jtab[i].magic == magic)
1025
12
      break;
1026
22
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
12
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
12
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
12
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
12
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
12
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
12
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
12
            imp_index);
1065
1066
12
      pe_ILF_save_relocs (& vars, text);
1067
12
      break;
1068
1069
8
    case IMPORT_DATA:
1070
8
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
20
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
20
  switch (import_type)
1079
20
    {
1080
12
    case IMPORT_CODE:
1081
12
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
12
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
12
      break;
1085
1086
8
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
8
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
20
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
20
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
20
  if (ptr)
1098
2
    * ptr = 0;
1099
20
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
20
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
20
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
20
  internal_f.f_magic  = magic;
1107
20
  internal_f.f_symptr = 0;
1108
20
  internal_f.f_nsyms  = 0;
1109
20
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
20
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
20
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
20
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
20
  obj_pe (abfd) = true;
1119
20
#ifdef THUMBPEMAGIC
1120
20
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
6
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
20
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
20
  bfd_cache_close (abfd);
1127
1128
20
  abfd->iostream = (void *) vars.bim;
1129
20
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
20
  abfd->iovec = &_bfd_memory_iovec;
1131
20
  abfd->where = 0;
1132
20
  abfd->origin = 0;
1133
20
  abfd->size = 0;
1134
20
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
20
  obj_symbols (abfd) = vars.sym_cache;
1138
20
  abfd->symcount = vars.sym_index;
1139
1140
20
  obj_raw_syments (abfd) = vars.native_syms;
1141
20
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
20
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
20
  obj_coff_keep_syms (abfd) = true;
1145
1146
20
  obj_convert (abfd) = vars.sym_table;
1147
20
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
20
  obj_coff_strings (abfd) = vars.string_table;
1150
20
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
20
  obj_coff_keep_strings (abfd) = true;
1152
1153
20
  return true;
1154
1155
4
 error_return:
1156
4
  free (vars.bim->buffer);
1157
4
  free (vars.bim);
1158
4
  return false;
1159
20
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
798
36
{
799
36
  bfd_byte *       ptr;
800
36
  pe_ILF_vars      vars;
801
36
  struct internal_filehdr  internal_f;
802
36
  unsigned int       import_type;
803
36
  unsigned int       import_name_type;
804
36
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
36
  coff_symbol_type **    imp_sym;
806
36
  unsigned int       imp_index;
807
36
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
36
  import_type = types & 0x3;
811
36
  import_name_type = (types & 0x1c) >> 2;
812
813
36
  switch (import_type)
814
36
    {
815
16
    case IMPORT_CODE:
816
28
    case IMPORT_DATA:
817
28
      break;
818
819
6
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
6
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
6
        abfd, import_type);
824
6
      return false;
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
36
    }
832
833
28
  switch (import_name_type)
834
28
    {
835
6
    case IMPORT_ORDINAL:
836
8
    case IMPORT_NAME:
837
16
    case IMPORT_NAME_NOPREFIX:
838
24
    case IMPORT_NAME_UNDECORATE:
839
24
      break;
840
841
4
    default:
842
      /* xgettext:c-format */
843
4
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
4
        abfd, import_name_type);
845
4
      return false;
846
28
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
24
  vars.bim
856
24
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
24
  if (vars.bim == NULL)
858
0
    return false;
859
860
24
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
24
  vars.bim->buffer = ptr;
862
24
  vars.bim->size   = ILF_DATA_SIZE;
863
24
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
24
  vars.sym_cache = (coff_symbol_type *) ptr;
869
24
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
24
  vars.sym_index = 0;
871
24
  ptr += SIZEOF_ILF_SYMS;
872
873
24
  vars.sym_table = (unsigned int *) ptr;
874
24
  vars.table_ptr = (unsigned int *) ptr;
875
24
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
24
  vars.native_syms = (combined_entry_type *) ptr;
878
24
  vars.native_ptr  = (combined_entry_type *) ptr;
879
24
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
24
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
24
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
24
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
24
  vars.esym_table = (SYMENT *) ptr;
886
24
  vars.esym_ptr   = (SYMENT *) ptr;
887
24
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
24
  vars.reltab   = (arelent *) ptr;
890
24
  vars.relcount = 0;
891
24
  ptr += SIZEOF_ILF_RELOCS;
892
893
24
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
24
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
24
  vars.string_table = (char *) ptr;
897
24
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
24
  ptr += SIZEOF_ILF_STRINGS;
899
24
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
24
#if GCC_VERSION >= 3000
909
24
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
24
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
24
  vars.data = ptr;
916
24
  vars.abfd = abfd;
917
24
  vars.sec_index = 0;
918
24
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
24
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
24
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
24
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
24
  if (import_name_type == IMPORT_ORDINAL)
934
6
    {
935
6
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
4
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
2
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
2
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
2
#endif
948
2
    }
949
18
  else
950
18
    {
951
18
      char * symbol;
952
18
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
18
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
18
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
18
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
18
      if (import_name_type != IMPORT_NAME)
970
16
  {
971
16
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
16
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
16
        || c == '@' || c == '?')
977
4
      symbol++;
978
16
  }
979
980
18
      len = strlen (symbol);
981
18
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
8
  {
983
    /* Truncate at the first '@'.  */
984
8
    char *at = strchr (symbol, '@');
985
986
8
    if (at != NULL)
987
4
      len = at - symbol;
988
8
  }
989
990
18
      id6->contents[0] = ordinal & 0xff;
991
18
      id6->contents[1] = ordinal >> 8;
992
993
18
      memcpy ((char *) id6->contents + 2, symbol, len);
994
18
      id6->contents[len + 2] = '\0';
995
18
    }
996
997
20
  if (import_name_type != IMPORT_ORDINAL)
998
18
    {
999
18
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
18
      pe_ILF_save_relocs (&vars, id4);
1001
1002
18
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
18
      pe_ILF_save_relocs (&vars, id5);
1004
18
    }
1005
1006
  /* Create an import symbol.  */
1007
20
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
20
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
20
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
20
  switch (import_type)
1013
20
    {
1014
0
      int i;
1015
1016
12
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
34
      for (i = NUM_ENTRIES (jtab); i--;)
1021
34
  {
1022
34
    if (jtab[i].size == 0)
1023
12
      continue;
1024
22
    if (jtab[i].magic == magic)
1025
12
      break;
1026
22
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
12
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
12
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
12
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
12
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
12
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
12
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
12
            imp_index);
1065
1066
12
      pe_ILF_save_relocs (& vars, text);
1067
12
      break;
1068
1069
8
    case IMPORT_DATA:
1070
8
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
20
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
20
  switch (import_type)
1079
20
    {
1080
12
    case IMPORT_CODE:
1081
12
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
12
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
12
      break;
1085
1086
8
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
8
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
20
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
20
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
20
  if (ptr)
1098
2
    * ptr = 0;
1099
20
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
20
  if (ptr)
1101
2
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
20
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
20
  internal_f.f_magic  = magic;
1107
20
  internal_f.f_symptr = 0;
1108
20
  internal_f.f_nsyms  = 0;
1109
20
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
20
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
20
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
20
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
20
  obj_pe (abfd) = true;
1119
20
#ifdef THUMBPEMAGIC
1120
20
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
6
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
20
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
20
  bfd_cache_close (abfd);
1127
1128
20
  abfd->iostream = (void *) vars.bim;
1129
20
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
20
  abfd->iovec = &_bfd_memory_iovec;
1131
20
  abfd->where = 0;
1132
20
  abfd->origin = 0;
1133
20
  abfd->size = 0;
1134
20
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
20
  obj_symbols (abfd) = vars.sym_cache;
1138
20
  abfd->symcount = vars.sym_index;
1139
1140
20
  obj_raw_syments (abfd) = vars.native_syms;
1141
20
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
20
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
20
  obj_coff_keep_syms (abfd) = true;
1145
1146
20
  obj_convert (abfd) = vars.sym_table;
1147
20
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
20
  obj_coff_strings (abfd) = vars.string_table;
1150
20
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
20
  obj_coff_keep_strings (abfd) = true;
1152
1153
20
  return true;
1154
1155
4
 error_return:
1156
4
  free (vars.bim->buffer);
1157
4
  free (vars.bim);
1158
4
  return false;
1159
20
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
798
18
{
799
18
  bfd_byte *       ptr;
800
18
  pe_ILF_vars      vars;
801
18
  struct internal_filehdr  internal_f;
802
18
  unsigned int       import_type;
803
18
  unsigned int       import_name_type;
804
18
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
18
  coff_symbol_type **    imp_sym;
806
18
  unsigned int       imp_index;
807
18
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
18
  import_type = types & 0x3;
811
18
  import_name_type = (types & 0x1c) >> 2;
812
813
18
  switch (import_type)
814
18
    {
815
12
    case IMPORT_CODE:
816
14
    case IMPORT_DATA:
817
14
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
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
18
    }
832
833
14
  switch (import_name_type)
834
14
    {
835
6
    case IMPORT_ORDINAL:
836
8
    case IMPORT_NAME:
837
10
    case IMPORT_NAME_NOPREFIX:
838
12
    case IMPORT_NAME_UNDECORATE:
839
12
      break;
840
841
2
    default:
842
      /* xgettext:c-format */
843
2
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
2
        abfd, import_name_type);
845
2
      return false;
846
14
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
12
  vars.bim
856
12
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
12
  if (vars.bim == NULL)
858
0
    return false;
859
860
12
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
12
  vars.bim->buffer = ptr;
862
12
  vars.bim->size   = ILF_DATA_SIZE;
863
12
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
12
  vars.sym_cache = (coff_symbol_type *) ptr;
869
12
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
12
  vars.sym_index = 0;
871
12
  ptr += SIZEOF_ILF_SYMS;
872
873
12
  vars.sym_table = (unsigned int *) ptr;
874
12
  vars.table_ptr = (unsigned int *) ptr;
875
12
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
12
  vars.native_syms = (combined_entry_type *) ptr;
878
12
  vars.native_ptr  = (combined_entry_type *) ptr;
879
12
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
12
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
12
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
12
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
12
  vars.esym_table = (SYMENT *) ptr;
886
12
  vars.esym_ptr   = (SYMENT *) ptr;
887
12
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
12
  vars.reltab   = (arelent *) ptr;
890
12
  vars.relcount = 0;
891
12
  ptr += SIZEOF_ILF_RELOCS;
892
893
12
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
12
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
12
  vars.string_table = (char *) ptr;
897
12
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
12
  ptr += SIZEOF_ILF_STRINGS;
899
12
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
12
#if GCC_VERSION >= 3000
909
12
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
12
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
12
  vars.data = ptr;
916
12
  vars.abfd = abfd;
917
12
  vars.sec_index = 0;
918
12
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
12
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
12
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
12
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
12
  if (import_name_type == IMPORT_ORDINAL)
934
6
    {
935
6
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
4
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
4
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
4
#endif
948
4
    }
949
6
  else
950
6
    {
951
6
      char * symbol;
952
6
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
6
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
6
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
6
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
6
      if (import_name_type != IMPORT_NAME)
970
4
  {
971
4
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
4
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
4
        || c == '@' || c == '?')
977
2
      symbol++;
978
4
  }
979
980
6
      len = strlen (symbol);
981
6
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
2
  {
983
    /* Truncate at the first '@'.  */
984
2
    char *at = strchr (symbol, '@');
985
986
2
    if (at != NULL)
987
0
      len = at - symbol;
988
2
  }
989
990
6
      id6->contents[0] = ordinal & 0xff;
991
6
      id6->contents[1] = ordinal >> 8;
992
993
6
      memcpy ((char *) id6->contents + 2, symbol, len);
994
6
      id6->contents[len + 2] = '\0';
995
6
    }
996
997
10
  if (import_name_type != IMPORT_ORDINAL)
998
6
    {
999
6
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
6
      pe_ILF_save_relocs (&vars, id4);
1001
1002
6
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
6
      pe_ILF_save_relocs (&vars, id5);
1004
6
    }
1005
1006
  /* Create an import symbol.  */
1007
10
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
10
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
10
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
10
  switch (import_type)
1013
10
    {
1014
0
      int i;
1015
1016
8
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
16
      for (i = NUM_ENTRIES (jtab); i--;)
1021
16
  {
1022
16
    if (jtab[i].size == 0)
1023
8
      continue;
1024
8
    if (jtab[i].magic == magic)
1025
8
      break;
1026
8
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
8
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
8
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
8
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
8
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
8
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
8
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
8
            imp_index);
1065
1066
8
      pe_ILF_save_relocs (& vars, text);
1067
8
      break;
1068
1069
2
    case IMPORT_DATA:
1070
2
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
10
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
10
  switch (import_type)
1079
10
    {
1080
8
    case IMPORT_CODE:
1081
8
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
8
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
8
      break;
1085
1086
2
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
2
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
10
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
10
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
10
  if (ptr)
1098
0
    * ptr = 0;
1099
10
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
10
  if (ptr)
1101
0
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
10
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
10
  internal_f.f_magic  = magic;
1107
10
  internal_f.f_symptr = 0;
1108
10
  internal_f.f_nsyms  = 0;
1109
10
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
10
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
10
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
10
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
10
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
10
  bfd_cache_close (abfd);
1127
1128
10
  abfd->iostream = (void *) vars.bim;
1129
10
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
10
  abfd->iovec = &_bfd_memory_iovec;
1131
10
  abfd->where = 0;
1132
10
  abfd->origin = 0;
1133
10
  abfd->size = 0;
1134
10
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
10
  obj_symbols (abfd) = vars.sym_cache;
1138
10
  abfd->symcount = vars.sym_index;
1139
1140
10
  obj_raw_syments (abfd) = vars.native_syms;
1141
10
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
10
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
10
  obj_coff_keep_syms (abfd) = true;
1145
1146
10
  obj_convert (abfd) = vars.sym_table;
1147
10
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
10
  obj_coff_strings (abfd) = vars.string_table;
1150
10
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
10
  obj_coff_keep_strings (abfd) = true;
1152
1153
10
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
10
}
1160
1161
/* Cleanup function, returned from check_format hook.  */
1162
1163
static void
1164
pe_ILF_cleanup (bfd *abfd)
1165
40
{
1166
40
  struct bfd_in_memory *bim = abfd->iostream;
1167
40
  free (bim->buffer);
1168
40
  free (bim);
1169
40
  abfd->iostream = NULL;
1170
40
}
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
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1165
20
{
1166
20
  struct bfd_in_memory *bim = abfd->iostream;
1167
20
  free (bim->buffer);
1168
20
  free (bim);
1169
20
  abfd->iostream = NULL;
1170
20
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1165
20
{
1166
20
  struct bfd_in_memory *bim = abfd->iostream;
1167
20
  free (bim->buffer);
1168
20
  free (bim);
1169
20
  abfd->iostream = NULL;
1170
20
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1171
1172
/* We have detected an Import Library Format archive element.
1173
   Decode the element and return the appropriate target.  */
1174
1175
static bfd_cleanup
1176
pe_ILF_object_p (bfd * abfd)
1177
1.84k
{
1178
1.84k
  bfd_byte    buffer[14];
1179
1.84k
  bfd_byte *    ptr;
1180
1.84k
  char *    symbol_name;
1181
1.84k
  char *    source_dll;
1182
1.84k
  unsigned int    machine;
1183
1.84k
  bfd_size_type   size;
1184
1.84k
  unsigned int    ordinal;
1185
1.84k
  unsigned int    types;
1186
1.84k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
1.84k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
48
    return NULL;
1192
1193
1.79k
  ptr = buffer;
1194
1195
1.79k
  machine = H_GET_16 (abfd, ptr);
1196
1.79k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
1.79k
  magic = 0;
1200
1201
1.79k
  switch (machine)
1202
1.79k
    {
1203
102
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
102
    case IMAGE_FILE_MACHINE_ALPHA:
1205
102
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
118
    case IMAGE_FILE_MACHINE_IA64:
1207
118
      break;
1208
1209
208
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
26
      magic = I386MAGIC;
1212
#endif
1213
208
      break;
1214
1215
224
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
28
      magic = AMD64MAGIC;
1218
#endif
1219
224
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
6
    case IMAGE_FILE_MACHINE_MIPS16:
1226
6
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
6
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
6
      break;
1232
1233
48
    case IMAGE_FILE_MACHINE_SH3:
1234
208
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
26
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
208
      break;
1239
1240
212
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
68
      magic = ARMPEMAGIC;
1243
#endif
1244
212
      break;
1245
1246
240
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
30
      magic = AARCH64MAGIC;
1249
#endif
1250
240
      break;
1251
1252
192
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
24
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
192
      break;
1257
1258
102
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
28
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
24
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
102
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
286
    default:
1272
286
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
286
  (_("%pB: unrecognised machine type (0x%x)"
1275
286
     " in Import Library Format archive"),
1276
286
   abfd, machine);
1277
286
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
286
      return NULL;
1280
0
      break;
1281
1.79k
    }
1282
1283
1.51k
  if (magic == 0)
1284
1.28k
    {
1285
1.28k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
1.28k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
1.28k
     " in Import Library Format archive"),
1289
1.28k
   abfd, machine);
1290
1.28k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
1.28k
      return NULL;
1293
1.28k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
226
  ptr += 4;
1298
1299
226
  size = H_GET_32 (abfd, ptr);
1300
226
  ptr += 4;
1301
1302
226
  if (size == 0)
1303
14
    {
1304
14
      _bfd_error_handler
1305
14
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
14
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
14
      return NULL;
1309
14
    }
1310
1311
212
  ordinal = H_GET_16 (abfd, ptr);
1312
212
  ptr += 2;
1313
1314
212
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
212
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
212
  if (ptr == NULL)
1320
26
    return NULL;
1321
1322
186
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
186
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
186
  if (ptr[size - 1] != 0
1328
186
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
20
    {
1330
20
      _bfd_error_handler
1331
20
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
20
      bfd_set_error (bfd_error_malformed_archive);
1333
20
      bfd_release (abfd, ptr);
1334
20
      return NULL;
1335
20
    }
1336
1337
  /* Now construct the bfd.  */
1338
166
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
166
          source_dll, ordinal, types))
1340
70
    {
1341
70
      bfd_release (abfd, ptr);
1342
70
      return NULL;
1343
70
    }
1344
1345
96
  return pe_ILF_cleanup;
1346
166
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1177
220
{
1178
220
  bfd_byte    buffer[14];
1179
220
  bfd_byte *    ptr;
1180
220
  char *    symbol_name;
1181
220
  char *    source_dll;
1182
220
  unsigned int    machine;
1183
220
  bfd_size_type   size;
1184
220
  unsigned int    ordinal;
1185
220
  unsigned int    types;
1186
220
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
220
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
214
  ptr = buffer;
1194
1195
214
  machine = H_GET_16 (abfd, ptr);
1196
214
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
214
  magic = 0;
1200
1201
214
  switch (machine)
1202
214
    {
1203
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
12
    case IMAGE_FILE_MACHINE_ALPHA:
1205
12
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
14
    case IMAGE_FILE_MACHINE_IA64:
1207
14
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
26
#ifdef I386MAGIC
1211
26
      magic = I386MAGIC;
1212
26
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
0
    case IMAGE_FILE_MACHINE_MIPS16:
1226
0
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
0
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
0
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
22
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
22
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
12
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
12
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
32
    default:
1272
32
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
32
  (_("%pB: unrecognised machine type (0x%x)"
1275
32
     " in Import Library Format archive"),
1276
32
   abfd, machine);
1277
32
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
32
      return NULL;
1280
0
      break;
1281
214
    }
1282
1283
182
  if (magic == 0)
1284
156
    {
1285
156
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
156
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
156
     " in Import Library Format archive"),
1289
156
   abfd, machine);
1290
156
      bfd_set_error (bfd_error_wrong_format);
1291
1292
156
      return NULL;
1293
156
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
26
  ptr += 4;
1298
1299
26
  size = H_GET_32 (abfd, ptr);
1300
26
  ptr += 4;
1301
1302
26
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
24
  ordinal = H_GET_16 (abfd, ptr);
1312
24
  ptr += 2;
1313
1314
24
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
24
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
24
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
20
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
20
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
20
  if (ptr[size - 1] != 0
1328
20
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
2
    {
1330
2
      _bfd_error_handler
1331
2
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
2
      bfd_set_error (bfd_error_malformed_archive);
1333
2
      bfd_release (abfd, ptr);
1334
2
      return NULL;
1335
2
    }
1336
1337
  /* Now construct the bfd.  */
1338
18
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
18
          source_dll, ordinal, types))
1340
8
    {
1341
8
      bfd_release (abfd, ptr);
1342
8
      return NULL;
1343
8
    }
1344
1345
10
  return pe_ILF_cleanup;
1346
18
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1177
220
{
1178
220
  bfd_byte    buffer[14];
1179
220
  bfd_byte *    ptr;
1180
220
  char *    symbol_name;
1181
220
  char *    source_dll;
1182
220
  unsigned int    machine;
1183
220
  bfd_size_type   size;
1184
220
  unsigned int    ordinal;
1185
220
  unsigned int    types;
1186
220
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
220
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
214
  ptr = buffer;
1194
1195
214
  machine = H_GET_16 (abfd, ptr);
1196
214
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
214
  magic = 0;
1200
1201
214
  switch (machine)
1202
214
    {
1203
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
12
    case IMAGE_FILE_MACHINE_ALPHA:
1205
12
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
14
    case IMAGE_FILE_MACHINE_IA64:
1207
14
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
28
#ifdef AMD64MAGIC
1217
28
      magic = AMD64MAGIC;
1218
28
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
0
    case IMAGE_FILE_MACHINE_MIPS16:
1226
0
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
0
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
0
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
22
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
22
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
12
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
12
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
32
    default:
1272
32
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
32
  (_("%pB: unrecognised machine type (0x%x)"
1275
32
     " in Import Library Format archive"),
1276
32
   abfd, machine);
1277
32
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
32
      return NULL;
1280
0
      break;
1281
214
    }
1282
1283
182
  if (magic == 0)
1284
154
    {
1285
154
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
154
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
154
     " in Import Library Format archive"),
1289
154
   abfd, machine);
1290
154
      bfd_set_error (bfd_error_wrong_format);
1291
1292
154
      return NULL;
1293
154
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
28
  ptr += 4;
1298
1299
28
  size = H_GET_32 (abfd, ptr);
1300
28
  ptr += 4;
1301
1302
28
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
26
  ordinal = H_GET_16 (abfd, ptr);
1312
26
  ptr += 2;
1313
1314
26
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
26
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
26
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
22
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
22
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
22
  if (ptr[size - 1] != 0
1328
22
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
2
    {
1330
2
      _bfd_error_handler
1331
2
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
2
      bfd_set_error (bfd_error_malformed_archive);
1333
2
      bfd_release (abfd, ptr);
1334
2
      return NULL;
1335
2
    }
1336
1337
  /* Now construct the bfd.  */
1338
20
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
20
          source_dll, ordinal, types))
1340
8
    {
1341
8
      bfd_release (abfd, ptr);
1342
8
      return NULL;
1343
8
    }
1344
1345
12
  return pe_ILF_cleanup;
1346
20
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1177
220
{
1178
220
  bfd_byte    buffer[14];
1179
220
  bfd_byte *    ptr;
1180
220
  char *    symbol_name;
1181
220
  char *    source_dll;
1182
220
  unsigned int    machine;
1183
220
  bfd_size_type   size;
1184
220
  unsigned int    ordinal;
1185
220
  unsigned int    types;
1186
220
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
220
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
214
  ptr = buffer;
1194
1195
214
  machine = H_GET_16 (abfd, ptr);
1196
214
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
214
  magic = 0;
1200
1201
214
  switch (machine)
1202
214
    {
1203
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
12
    case IMAGE_FILE_MACHINE_ALPHA:
1205
12
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
14
    case IMAGE_FILE_MACHINE_IA64:
1207
14
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
0
    case IMAGE_FILE_MACHINE_MIPS16:
1226
0
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
0
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
0
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
22
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
22
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
30
#ifdef AARCH64MAGIC
1248
30
      magic = AARCH64MAGIC;
1249
30
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
12
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
12
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
32
    default:
1272
32
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
32
  (_("%pB: unrecognised machine type (0x%x)"
1275
32
     " in Import Library Format archive"),
1276
32
   abfd, machine);
1277
32
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
32
      return NULL;
1280
0
      break;
1281
214
    }
1282
1283
182
  if (magic == 0)
1284
152
    {
1285
152
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
152
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
152
     " in Import Library Format archive"),
1289
152
   abfd, machine);
1290
152
      bfd_set_error (bfd_error_wrong_format);
1291
1292
152
      return NULL;
1293
152
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
30
  ptr += 4;
1298
1299
30
  size = H_GET_32 (abfd, ptr);
1300
30
  ptr += 4;
1301
1302
30
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
28
  ordinal = H_GET_16 (abfd, ptr);
1312
28
  ptr += 2;
1313
1314
28
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
28
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
28
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
24
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
24
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
24
  if (ptr[size - 1] != 0
1328
24
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
4
    {
1330
4
      _bfd_error_handler
1331
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
4
      bfd_set_error (bfd_error_malformed_archive);
1333
4
      bfd_release (abfd, ptr);
1334
4
      return NULL;
1335
4
    }
1336
1337
  /* Now construct the bfd.  */
1338
20
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
20
          source_dll, ordinal, types))
1340
8
    {
1341
8
      bfd_release (abfd, ptr);
1342
8
      return NULL;
1343
8
    }
1344
1345
12
  return pe_ILF_cleanup;
1346
20
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1177
220
{
1178
220
  bfd_byte    buffer[14];
1179
220
  bfd_byte *    ptr;
1180
220
  char *    symbol_name;
1181
220
  char *    source_dll;
1182
220
  unsigned int    machine;
1183
220
  bfd_size_type   size;
1184
220
  unsigned int    ordinal;
1185
220
  unsigned int    types;
1186
220
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
220
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
214
  ptr = buffer;
1194
1195
214
  machine = H_GET_16 (abfd, ptr);
1196
214
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
214
  magic = 0;
1200
1201
214
  switch (machine)
1202
214
    {
1203
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
12
    case IMAGE_FILE_MACHINE_ALPHA:
1205
12
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
14
    case IMAGE_FILE_MACHINE_IA64:
1207
14
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
0
    case IMAGE_FILE_MACHINE_MIPS16:
1226
0
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
0
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
0
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
22
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
22
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
24
#ifdef LOONGARCH64MAGIC
1254
24
      magic = LOONGARCH64MAGIC;
1255
24
#endif
1256
24
      break;
1257
1258
12
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
12
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
32
    default:
1272
32
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
32
  (_("%pB: unrecognised machine type (0x%x)"
1275
32
     " in Import Library Format archive"),
1276
32
   abfd, machine);
1277
32
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
32
      return NULL;
1280
0
      break;
1281
214
    }
1282
1283
182
  if (magic == 0)
1284
158
    {
1285
158
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
158
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
158
     " in Import Library Format archive"),
1289
158
   abfd, machine);
1290
158
      bfd_set_error (bfd_error_wrong_format);
1291
1292
158
      return NULL;
1293
158
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
24
  ptr += 4;
1298
1299
24
  size = H_GET_32 (abfd, ptr);
1300
24
  ptr += 4;
1301
1302
24
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
22
  ordinal = H_GET_16 (abfd, ptr);
1312
22
  ptr += 2;
1313
1314
22
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
22
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
22
  if (ptr == NULL)
1320
2
    return NULL;
1321
1322
20
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
20
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
20
  if (ptr[size - 1] != 0
1328
20
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
2
    {
1330
2
      _bfd_error_handler
1331
2
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
2
      bfd_set_error (bfd_error_malformed_archive);
1333
2
      bfd_release (abfd, ptr);
1334
2
      return NULL;
1335
2
    }
1336
1337
  /* Now construct the bfd.  */
1338
18
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
18
          source_dll, ordinal, types))
1340
6
    {
1341
6
      bfd_release (abfd, ptr);
1342
6
      return NULL;
1343
6
    }
1344
1345
12
  return pe_ILF_cleanup;
1346
18
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1177
248
{
1178
248
  bfd_byte    buffer[14];
1179
248
  bfd_byte *    ptr;
1180
248
  char *    symbol_name;
1181
248
  char *    source_dll;
1182
248
  unsigned int    machine;
1183
248
  bfd_size_type   size;
1184
248
  unsigned int    ordinal;
1185
248
  unsigned int    types;
1186
248
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
248
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
242
  ptr = buffer;
1194
1195
242
  machine = H_GET_16 (abfd, ptr);
1196
242
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
242
  magic = 0;
1200
1201
242
  switch (machine)
1202
242
    {
1203
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
14
    case IMAGE_FILE_MACHINE_ALPHA:
1205
14
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
16
    case IMAGE_FILE_MACHINE_IA64:
1207
16
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
2
    case IMAGE_FILE_MACHINE_MIPS16:
1226
2
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
2
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
2
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
34
    case IMAGE_FILE_MACHINE_ARM:
1241
34
#ifdef ARMPEMAGIC
1242
34
      magic = ARMPEMAGIC;
1243
34
#endif
1244
34
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
14
    case IMAGE_FILE_MACHINE_THUMB:
1259
14
#ifdef THUMBPEMAGIC
1260
14
      {
1261
14
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
14
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
12
    magic = THUMBPEMAGIC;
1265
14
      }
1266
14
#endif
1267
14
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
42
    default:
1272
42
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
42
  (_("%pB: unrecognised machine type (0x%x)"
1275
42
     " in Import Library Format archive"),
1276
42
   abfd, machine);
1277
42
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
42
      return NULL;
1280
0
      break;
1281
242
    }
1282
1283
200
  if (magic == 0)
1284
154
    {
1285
154
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
154
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
154
     " in Import Library Format archive"),
1289
154
   abfd, machine);
1290
154
      bfd_set_error (bfd_error_wrong_format);
1291
1292
154
      return NULL;
1293
154
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
46
  ptr += 4;
1298
1299
46
  size = H_GET_32 (abfd, ptr);
1300
46
  ptr += 4;
1301
1302
46
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
44
  ordinal = H_GET_16 (abfd, ptr);
1312
44
  ptr += 2;
1313
1314
44
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
44
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
44
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
40
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
40
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
40
  if (ptr[size - 1] != 0
1328
40
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
4
    {
1330
4
      _bfd_error_handler
1331
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
4
      bfd_set_error (bfd_error_malformed_archive);
1333
4
      bfd_release (abfd, ptr);
1334
4
      return NULL;
1335
4
    }
1336
1337
  /* Now construct the bfd.  */
1338
36
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
36
          source_dll, ordinal, types))
1340
16
    {
1341
16
      bfd_release (abfd, ptr);
1342
16
      return NULL;
1343
16
    }
1344
1345
20
  return pe_ILF_cleanup;
1346
36
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1177
248
{
1178
248
  bfd_byte    buffer[14];
1179
248
  bfd_byte *    ptr;
1180
248
  char *    symbol_name;
1181
248
  char *    source_dll;
1182
248
  unsigned int    machine;
1183
248
  bfd_size_type   size;
1184
248
  unsigned int    ordinal;
1185
248
  unsigned int    types;
1186
248
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
248
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
242
  ptr = buffer;
1194
1195
242
  machine = H_GET_16 (abfd, ptr);
1196
242
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
242
  magic = 0;
1200
1201
242
  switch (machine)
1202
242
    {
1203
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
14
    case IMAGE_FILE_MACHINE_ALPHA:
1205
14
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
16
    case IMAGE_FILE_MACHINE_IA64:
1207
16
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
2
    case IMAGE_FILE_MACHINE_MIPS16:
1226
2
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
2
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
2
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
34
    case IMAGE_FILE_MACHINE_ARM:
1241
34
#ifdef ARMPEMAGIC
1242
34
      magic = ARMPEMAGIC;
1243
34
#endif
1244
34
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
14
    case IMAGE_FILE_MACHINE_THUMB:
1259
14
#ifdef THUMBPEMAGIC
1260
14
      {
1261
14
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
14
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
12
    magic = THUMBPEMAGIC;
1265
14
      }
1266
14
#endif
1267
14
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
42
    default:
1272
42
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
42
  (_("%pB: unrecognised machine type (0x%x)"
1275
42
     " in Import Library Format archive"),
1276
42
   abfd, machine);
1277
42
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
42
      return NULL;
1280
0
      break;
1281
242
    }
1282
1283
200
  if (magic == 0)
1284
154
    {
1285
154
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
154
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
154
     " in Import Library Format archive"),
1289
154
   abfd, machine);
1290
154
      bfd_set_error (bfd_error_wrong_format);
1291
1292
154
      return NULL;
1293
154
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
46
  ptr += 4;
1298
1299
46
  size = H_GET_32 (abfd, ptr);
1300
46
  ptr += 4;
1301
1302
46
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
44
  ordinal = H_GET_16 (abfd, ptr);
1312
44
  ptr += 2;
1313
1314
44
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
44
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
44
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
40
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
40
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
40
  if (ptr[size - 1] != 0
1328
40
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
4
    {
1330
4
      _bfd_error_handler
1331
4
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
4
      bfd_set_error (bfd_error_malformed_archive);
1333
4
      bfd_release (abfd, ptr);
1334
4
      return NULL;
1335
4
    }
1336
1337
  /* Now construct the bfd.  */
1338
36
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
36
          source_dll, ordinal, types))
1340
16
    {
1341
16
      bfd_release (abfd, ptr);
1342
16
      return NULL;
1343
16
    }
1344
1345
20
  return pe_ILF_cleanup;
1346
36
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1177
248
{
1178
248
  bfd_byte    buffer[14];
1179
248
  bfd_byte *    ptr;
1180
248
  char *    symbol_name;
1181
248
  char *    source_dll;
1182
248
  unsigned int    machine;
1183
248
  bfd_size_type   size;
1184
248
  unsigned int    ordinal;
1185
248
  unsigned int    types;
1186
248
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
248
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
242
  ptr = buffer;
1194
1195
242
  machine = H_GET_16 (abfd, ptr);
1196
242
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
242
  magic = 0;
1200
1201
242
  switch (machine)
1202
242
    {
1203
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
14
    case IMAGE_FILE_MACHINE_ALPHA:
1205
14
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
16
    case IMAGE_FILE_MACHINE_IA64:
1207
16
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
2
    case IMAGE_FILE_MACHINE_MIPS16:
1226
2
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
2
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
2
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
26
      break;
1239
1240
34
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
34
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
14
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
14
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
42
    default:
1272
42
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
42
  (_("%pB: unrecognised machine type (0x%x)"
1275
42
     " in Import Library Format archive"),
1276
42
   abfd, machine);
1277
42
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
42
      return NULL;
1280
0
      break;
1281
242
    }
1282
1283
200
  if (magic == 0)
1284
200
    {
1285
200
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
200
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
200
     " in Import Library Format archive"),
1289
200
   abfd, machine);
1290
200
      bfd_set_error (bfd_error_wrong_format);
1291
1292
200
      return NULL;
1293
200
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
0
  ptr += 4;
1298
1299
0
  size = H_GET_32 (abfd, ptr);
1300
0
  ptr += 4;
1301
1302
0
  if (size == 0)
1303
0
    {
1304
0
      _bfd_error_handler
1305
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
0
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
0
      return NULL;
1309
0
    }
1310
1311
0
  ordinal = H_GET_16 (abfd, ptr);
1312
0
  ptr += 2;
1313
1314
0
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
0
  if (ptr == NULL)
1320
0
    return NULL;
1321
1322
0
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
0
  if (ptr[size - 1] != 0
1328
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
0
    {
1330
0
      _bfd_error_handler
1331
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
0
      bfd_set_error (bfd_error_malformed_archive);
1333
0
      bfd_release (abfd, ptr);
1334
0
      return NULL;
1335
0
    }
1336
1337
  /* Now construct the bfd.  */
1338
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
0
          source_dll, ordinal, types))
1340
0
    {
1341
0
      bfd_release (abfd, ptr);
1342
0
      return NULL;
1343
0
    }
1344
1345
0
  return pe_ILF_cleanup;
1346
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1177
220
{
1178
220
  bfd_byte    buffer[14];
1179
220
  bfd_byte *    ptr;
1180
220
  char *    symbol_name;
1181
220
  char *    source_dll;
1182
220
  unsigned int    machine;
1183
220
  bfd_size_type   size;
1184
220
  unsigned int    ordinal;
1185
220
  unsigned int    types;
1186
220
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
220
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
6
    return NULL;
1192
1193
214
  ptr = buffer;
1194
1195
214
  machine = H_GET_16 (abfd, ptr);
1196
214
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
214
  magic = 0;
1200
1201
214
  switch (machine)
1202
214
    {
1203
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
12
    case IMAGE_FILE_MACHINE_ALPHA:
1205
12
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
14
    case IMAGE_FILE_MACHINE_IA64:
1207
14
      break;
1208
1209
26
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
26
      break;
1214
1215
28
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
28
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
0
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
0
    case IMAGE_FILE_MACHINE_MIPS16:
1226
0
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
0
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
0
      break;
1232
1233
6
    case IMAGE_FILE_MACHINE_SH3:
1234
26
    case IMAGE_FILE_MACHINE_SH4:
1235
26
#ifdef SH_ARCH_MAGIC_WINCE
1236
26
      magic = SH_ARCH_MAGIC_WINCE;
1237
26
#endif
1238
26
      break;
1239
1240
22
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
22
      break;
1245
1246
30
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
30
      break;
1251
1252
24
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
24
      break;
1257
1258
12
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
12
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
32
    default:
1272
32
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
32
  (_("%pB: unrecognised machine type (0x%x)"
1275
32
     " in Import Library Format archive"),
1276
32
   abfd, machine);
1277
32
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
32
      return NULL;
1280
0
      break;
1281
214
    }
1282
1283
182
  if (magic == 0)
1284
156
    {
1285
156
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
156
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
156
     " in Import Library Format archive"),
1289
156
   abfd, machine);
1290
156
      bfd_set_error (bfd_error_wrong_format);
1291
1292
156
      return NULL;
1293
156
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
26
  ptr += 4;
1298
1299
26
  size = H_GET_32 (abfd, ptr);
1300
26
  ptr += 4;
1301
1302
26
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
24
  ordinal = H_GET_16 (abfd, ptr);
1312
24
  ptr += 2;
1313
1314
24
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
24
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
24
  if (ptr == NULL)
1320
4
    return NULL;
1321
1322
20
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
20
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
20
  if (ptr[size - 1] != 0
1328
20
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
2
    {
1330
2
      _bfd_error_handler
1331
2
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
2
      bfd_set_error (bfd_error_malformed_archive);
1333
2
      bfd_release (abfd, ptr);
1334
2
      return NULL;
1335
2
    }
1336
1337
  /* Now construct the bfd.  */
1338
18
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
18
          source_dll, ordinal, types))
1340
8
    {
1341
8
      bfd_release (abfd, ptr);
1342
8
      return NULL;
1343
8
    }
1344
1345
10
  return pe_ILF_cleanup;
1346
18
}
1347
1348
static void
1349
pe_bfd_read_buildid (bfd *abfd)
1350
24.4k
{
1351
24.4k
  pe_data_type *pe = pe_data (abfd);
1352
24.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
24.4k
  asection *section;
1354
24.4k
  bfd_byte *data = 0;
1355
24.4k
  bfd_size_type dataoff;
1356
24.4k
  unsigned int i;
1357
24.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
24.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
24.4k
  if (size == 0)
1361
6.60k
    return;
1362
1363
17.8k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
441k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
434k
    {
1368
434k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
10.4k
  break;
1370
434k
    }
1371
1372
17.8k
  if (section == NULL)
1373
7.43k
    return;
1374
1375
10.4k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
2.91k
    return;
1377
1378
7.52k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
7.52k
  if (dataoff >= section->size
1384
7.52k
      || size > section->size - dataoff)
1385
3.87k
    {
1386
3.87k
      _bfd_error_handler
1387
3.87k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
3.87k
   abfd);
1389
3.87k
      return;
1390
3.87k
    }
1391
1392
  /* Read the whole section. */
1393
3.65k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.99k
    {
1395
1.99k
      free (data);
1396
1.99k
      return;
1397
1.99k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
32.2k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
31.6k
    {
1402
31.6k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
31.6k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
31.6k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
31.6k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
31.6k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
1.04k
  {
1410
1.04k
    char buffer[256 + 1];
1411
1.04k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
1.04k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
1.04k
                (file_ptr) idd.PointerToRawData,
1419
1.04k
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
1.04k
    break;
1432
1.04k
  }
1433
31.6k
    }
1434
1435
1.65k
  free (data);
1436
1.65k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1350
760
{
1351
760
  pe_data_type *pe = pe_data (abfd);
1352
760
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
760
  asection *section;
1354
760
  bfd_byte *data = 0;
1355
760
  bfd_size_type dataoff;
1356
760
  unsigned int i;
1357
760
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
760
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
760
  if (size == 0)
1361
670
    return;
1362
1363
90
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
350
  for (section = abfd->sections; section != NULL; section = section->next)
1367
316
    {
1368
316
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
56
  break;
1370
316
    }
1371
1372
90
  if (section == NULL)
1373
34
    return;
1374
1375
56
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
6
    return;
1377
1378
50
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
50
  if (dataoff >= section->size
1384
50
      || size > section->size - dataoff)
1385
6
    {
1386
6
      _bfd_error_handler
1387
6
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
6
   abfd);
1389
6
      return;
1390
6
    }
1391
1392
  /* Read the whole section. */
1393
44
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
10
    {
1395
10
      free (data);
1396
10
      return;
1397
10
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
130
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
110
    {
1402
110
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
110
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
110
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
110
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
110
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
14
  {
1410
14
    char buffer[256 + 1];
1411
14
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
14
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
14
                (file_ptr) idd.PointerToRawData,
1419
14
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
14
    break;
1432
14
  }
1433
110
    }
1434
1435
34
  free (data);
1436
34
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1350
374
{
1351
374
  pe_data_type *pe = pe_data (abfd);
1352
374
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
374
  asection *section;
1354
374
  bfd_byte *data = 0;
1355
374
  bfd_size_type dataoff;
1356
374
  unsigned int i;
1357
374
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
374
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
374
  if (size == 0)
1361
224
    return;
1362
1363
150
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
368
  for (section = abfd->sections; section != NULL; section = section->next)
1367
318
    {
1368
318
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
100
  break;
1370
318
    }
1371
1372
150
  if (section == NULL)
1373
50
    return;
1374
1375
100
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
6
    return;
1377
1378
94
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
94
  if (dataoff >= section->size
1384
94
      || size > section->size - dataoff)
1385
14
    {
1386
14
      _bfd_error_handler
1387
14
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
14
   abfd);
1389
14
      return;
1390
14
    }
1391
1392
  /* Read the whole section. */
1393
80
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
24
    {
1395
24
      free (data);
1396
24
      return;
1397
24
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
27.3k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
27.2k
    {
1402
27.2k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
27.2k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
27.2k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
27.2k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
27.2k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
22
  {
1410
22
    char buffer[256 + 1];
1411
22
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
22
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
22
                (file_ptr) idd.PointerToRawData,
1419
22
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
22
    break;
1432
22
  }
1433
27.2k
    }
1434
1435
56
  free (data);
1436
56
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
3.53k
{
1351
3.53k
  pe_data_type *pe = pe_data (abfd);
1352
3.53k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
3.53k
  asection *section;
1354
3.53k
  bfd_byte *data = 0;
1355
3.53k
  bfd_size_type dataoff;
1356
3.53k
  unsigned int i;
1357
3.53k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
3.53k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
3.53k
  if (size == 0)
1361
1.09k
    return;
1362
1363
2.44k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
3.63k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
2.64k
    {
1368
2.64k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.45k
  break;
1370
2.64k
    }
1371
1372
2.44k
  if (section == NULL)
1373
988
    return;
1374
1375
1.45k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
482
    return;
1377
1378
974
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
974
  if (dataoff >= section->size
1384
974
      || size > section->size - dataoff)
1385
486
    {
1386
486
      _bfd_error_handler
1387
486
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
486
   abfd);
1389
486
      return;
1390
486
    }
1391
1392
  /* Read the whole section. */
1393
488
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
488
    {
1395
488
      free (data);
1396
488
      return;
1397
488
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
0
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
0
    {
1402
0
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
0
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
0
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
0
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
0
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
0
  {
1410
0
    char buffer[256 + 1];
1411
0
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
0
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
0
                (file_ptr) idd.PointerToRawData,
1419
0
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
0
    break;
1432
0
  }
1433
0
    }
1434
1435
0
  free (data);
1436
0
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1350
5.08k
{
1351
5.08k
  pe_data_type *pe = pe_data (abfd);
1352
5.08k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
5.08k
  asection *section;
1354
5.08k
  bfd_byte *data = 0;
1355
5.08k
  bfd_size_type dataoff;
1356
5.08k
  unsigned int i;
1357
5.08k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
5.08k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
5.08k
  if (size == 0)
1361
1.64k
    return;
1362
1363
3.44k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
30.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
28.2k
    {
1368
28.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.48k
  break;
1370
28.2k
    }
1371
1372
3.44k
  if (section == NULL)
1373
1.96k
    return;
1374
1375
1.48k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
10
    return;
1377
1378
1.47k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
1.47k
  if (dataoff >= section->size
1384
1.47k
      || size > section->size - dataoff)
1385
958
    {
1386
958
      _bfd_error_handler
1387
958
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
958
   abfd);
1389
958
      return;
1390
958
    }
1391
1392
  /* Read the whole section. */
1393
516
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
482
    {
1395
482
      free (data);
1396
482
      return;
1397
482
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
120
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
104
    {
1402
104
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
104
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
104
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
104
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
104
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
18
  {
1410
18
    char buffer[256 + 1];
1411
18
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
18
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
18
                (file_ptr) idd.PointerToRawData,
1419
18
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
18
    break;
1432
18
  }
1433
104
    }
1434
1435
34
  free (data);
1436
34
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
180
{
1351
180
  pe_data_type *pe = pe_data (abfd);
1352
180
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
180
  asection *section;
1354
180
  bfd_byte *data = 0;
1355
180
  bfd_size_type dataoff;
1356
180
  unsigned int i;
1357
180
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
180
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
180
  if (size == 0)
1361
108
    return;
1362
1363
72
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
308
  for (section = abfd->sections; section != NULL; section = section->next)
1367
274
    {
1368
274
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
38
  break;
1370
274
    }
1371
1372
72
  if (section == NULL)
1373
34
    return;
1374
1375
38
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
6
    return;
1377
1378
32
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
32
  if (dataoff >= section->size
1384
32
      || size > section->size - dataoff)
1385
6
    {
1386
6
      _bfd_error_handler
1387
6
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
6
   abfd);
1389
6
      return;
1390
6
    }
1391
1392
  /* Read the whole section. */
1393
26
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
10
    {
1395
10
      free (data);
1396
10
      return;
1397
10
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
64
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
54
    {
1402
54
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
54
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
54
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
54
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
54
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
6
  {
1410
6
    char buffer[256 + 1];
1411
6
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
6
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
6
                (file_ptr) idd.PointerToRawData,
1419
6
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
6
    break;
1432
6
  }
1433
54
    }
1434
1435
16
  free (data);
1436
16
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1350
3.01k
{
1351
3.01k
  pe_data_type *pe = pe_data (abfd);
1352
3.01k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
3.01k
  asection *section;
1354
3.01k
  bfd_byte *data = 0;
1355
3.01k
  bfd_size_type dataoff;
1356
3.01k
  unsigned int i;
1357
3.01k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
3.01k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
3.01k
  if (size == 0)
1361
96
    return;
1362
1363
2.91k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
16.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
15.4k
    {
1368
15.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.94k
  break;
1370
15.4k
    }
1371
1372
2.91k
  if (section == NULL)
1373
968
    return;
1374
1375
1.94k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
486
    return;
1377
1378
1.46k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
1.46k
  if (dataoff >= section->size
1384
1.46k
      || size > section->size - dataoff)
1385
482
    {
1386
482
      _bfd_error_handler
1387
482
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
482
   abfd);
1389
482
      return;
1390
482
    }
1391
1392
  /* Read the whole section. */
1393
978
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
6
    {
1395
6
      free (data);
1396
6
      return;
1397
6
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
2.92k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
2.91k
    {
1402
2.91k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
2.91k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
2.91k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
2.91k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
2.91k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
960
  {
1410
960
    char buffer[256 + 1];
1411
960
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
960
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
960
                (file_ptr) idd.PointerToRawData,
1419
960
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
960
    break;
1432
960
  }
1433
2.91k
    }
1434
1435
972
  free (data);
1436
972
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1350
4.02k
{
1351
4.02k
  pe_data_type *pe = pe_data (abfd);
1352
4.02k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
4.02k
  asection *section;
1354
4.02k
  bfd_byte *data = 0;
1355
4.02k
  bfd_size_type dataoff;
1356
4.02k
  unsigned int i;
1357
4.02k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
4.02k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
4.02k
  if (size == 0)
1361
626
    return;
1362
1363
3.40k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
351k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
350k
    {
1368
350k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
2.42k
  break;
1370
350k
    }
1371
1372
3.40k
  if (section == NULL)
1373
980
    return;
1374
1375
2.42k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
956
    return;
1377
1378
1.46k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
1.46k
  if (dataoff >= section->size
1384
1.46k
      || size > section->size - dataoff)
1385
958
    {
1386
958
      _bfd_error_handler
1387
958
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
958
   abfd);
1389
958
      return;
1390
958
    }
1391
1392
  /* Read the whole section. */
1393
506
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
482
    {
1395
482
      free (data);
1396
482
      return;
1397
482
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
128
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
114
    {
1402
114
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
114
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
114
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
114
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
114
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
10
  {
1410
10
    char buffer[256 + 1];
1411
10
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
10
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
10
                (file_ptr) idd.PointerToRawData,
1419
10
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
10
    break;
1432
10
  }
1433
114
    }
1434
1435
24
  free (data);
1436
24
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1350
3.02k
{
1351
3.02k
  pe_data_type *pe = pe_data (abfd);
1352
3.02k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
3.02k
  asection *section;
1354
3.02k
  bfd_byte *data = 0;
1355
3.02k
  bfd_size_type dataoff;
1356
3.02k
  unsigned int i;
1357
3.02k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
3.02k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
3.02k
  if (size == 0)
1361
574
    return;
1362
1363
2.45k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
22.8k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
21.8k
    {
1368
21.8k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.47k
  break;
1370
21.8k
    }
1371
1372
2.45k
  if (section == NULL)
1373
978
    return;
1374
1375
1.47k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
482
    return;
1377
1378
990
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
990
  if (dataoff >= section->size
1384
990
      || size > section->size - dataoff)
1385
482
    {
1386
482
      _bfd_error_handler
1387
482
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
482
   abfd);
1389
482
      return;
1390
482
    }
1391
1392
  /* Read the whole section. */
1393
508
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
484
    {
1395
484
      free (data);
1396
484
      return;
1397
484
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
104
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
86
    {
1402
86
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
86
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
86
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
86
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
86
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
6
  {
1410
6
    char buffer[256 + 1];
1411
6
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
6
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
6
                (file_ptr) idd.PointerToRawData,
1419
6
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
6
    break;
1432
6
  }
1433
86
    }
1434
1435
24
  free (data);
1436
24
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1350
4.48k
{
1351
4.48k
  pe_data_type *pe = pe_data (abfd);
1352
4.48k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
4.48k
  asection *section;
1354
4.48k
  bfd_byte *data = 0;
1355
4.48k
  bfd_size_type dataoff;
1356
4.48k
  unsigned int i;
1357
4.48k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
4.48k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
4.48k
  if (size == 0)
1361
1.57k
    return;
1362
1363
2.91k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
16.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
15.0k
    {
1368
15.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.47k
  break;
1370
15.0k
    }
1371
1372
2.91k
  if (section == NULL)
1373
1.44k
    return;
1374
1375
1.47k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
484
    return;
1377
1378
988
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
988
  if (dataoff >= section->size
1384
988
      || size > section->size - dataoff)
1385
482
    {
1386
482
      _bfd_error_handler
1387
482
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
482
   abfd);
1389
482
      return;
1390
482
    }
1391
1392
  /* Read the whole section. */
1393
506
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
10
    {
1395
10
      free (data);
1396
10
      return;
1397
10
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
1.51k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
1.02k
    {
1402
1.02k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
1.02k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
1.02k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
1.02k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
1.02k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
4
  {
1410
4
    char buffer[256 + 1];
1411
4
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
4
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
4
                (file_ptr) idd.PointerToRawData,
1419
4
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
4
    break;
1432
4
  }
1433
1.02k
    }
1434
1435
496
  free (data);
1436
496
}
1437
1438
static bfd_cleanup
1439
pe_bfd_object_p (bfd * abfd)
1440
1.34M
{
1441
1.34M
  bfd_byte buffer[6];
1442
1.34M
  struct external_DOS_hdr dos_hdr;
1443
1.34M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.34M
  struct internal_filehdr internal_f;
1445
1.34M
  struct internal_aouthdr internal_a;
1446
1.34M
  bfd_size_type opt_hdr_size;
1447
1.34M
  file_ptr offset;
1448
1.34M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.34M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.34M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
8.77k
    {
1455
8.77k
      if (bfd_get_error () != bfd_error_system_call)
1456
6.22k
  bfd_set_error (bfd_error_wrong_format);
1457
8.77k
      return NULL;
1458
8.77k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.33M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.33M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
1.84k
    return pe_ILF_object_p (abfd);
1464
1465
1.33M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.33M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.33M
   != sizeof (dos_hdr))
1468
82.7k
    {
1469
82.7k
      if (bfd_get_error () != bfd_error_system_call)
1470
82.7k
  bfd_set_error (bfd_error_wrong_format);
1471
82.7k
      return NULL;
1472
82.7k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.25M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
572k
    {
1486
572k
      bfd_set_error (bfd_error_wrong_format);
1487
572k
      return NULL;
1488
572k
    }
1489
1490
680k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
680k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
680k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
680k
    != sizeof (image_hdr)))
1494
7.90k
    {
1495
7.90k
      if (bfd_get_error () != bfd_error_system_call)
1496
7.90k
  bfd_set_error (bfd_error_wrong_format);
1497
7.90k
      return NULL;
1498
7.90k
    }
1499
1500
672k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
8.11k
    {
1502
8.11k
      bfd_set_error (bfd_error_wrong_format);
1503
8.11k
      return NULL;
1504
8.11k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
664k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
664k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
664k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
572k
    {
1513
572k
      bfd_set_error (bfd_error_wrong_format);
1514
572k
      return NULL;
1515
572k
    }
1516
1517
91.5k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
91.5k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
91.5k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
91.5k
  if (opt_hdr_size != 0)
1524
75.9k
    {
1525
75.9k
      bfd_size_type amt = opt_hdr_size;
1526
75.9k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
75.9k
      if (amt < sizeof (PEAOUTHDR))
1530
26.9k
  amt = sizeof (PEAOUTHDR);
1531
1532
75.9k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
75.9k
      if (opthdr == NULL)
1534
2.93k
  return NULL;
1535
73.0k
      if (amt > opt_hdr_size)
1536
25.9k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
73.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
73.0k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
16.6k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
16.6k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
8.23k
#endif
1550
16.5k
  {
1551
16.5k
    bfd_set_error (bfd_error_wrong_format);
1552
16.5k
    return NULL;
1553
16.5k
  }
1554
16.6k
#endif
1555
1556
56.4k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
56.4k
    || a->SectionAlignment >= 0x80000000)
1558
29.9k
  {
1559
29.9k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
29.9k
        abfd);
1561
29.9k
    a->SectionAlignment &= -a->SectionAlignment;
1562
29.9k
    if (a->SectionAlignment >= 0x80000000)
1563
6
      a->SectionAlignment = 0x40000000;
1564
29.9k
  }
1565
1566
56.4k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
56.4k
    || a->FileAlignment > a->SectionAlignment)
1568
28.5k
  {
1569
28.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
28.5k
            abfd);
1571
28.5k
    a->FileAlignment &= -a->FileAlignment;
1572
28.5k
    if (a->FileAlignment > a->SectionAlignment)
1573
12.7k
      a->FileAlignment = a->SectionAlignment;
1574
28.5k
  }
1575
1576
56.4k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
41.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
16.6k
    }
1579
1580
72.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
72.0k
             (opt_hdr_size != 0
1582
72.0k
        ? &internal_a
1583
72.0k
        : (struct internal_aouthdr *) NULL));
1584
1585
72.0k
  if (result)
1586
24.4k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
24.4k
      pe_bfd_read_buildid(abfd);
1589
24.4k
    }
1590
1591
72.0k
  return result;
1592
91.5k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1440
115k
{
1441
115k
  bfd_byte buffer[6];
1442
115k
  struct external_DOS_hdr dos_hdr;
1443
115k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
115k
  struct internal_filehdr internal_f;
1445
115k
  struct internal_aouthdr internal_a;
1446
115k
  bfd_size_type opt_hdr_size;
1447
115k
  file_ptr offset;
1448
115k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
115k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
115k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
798
    {
1455
798
      if (bfd_get_error () != bfd_error_system_call)
1456
566
  bfd_set_error (bfd_error_wrong_format);
1457
798
      return NULL;
1458
798
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
115k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
115k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
220
    return pe_ILF_object_p (abfd);
1464
1465
114k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
114k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
114k
   != sizeof (dos_hdr))
1468
7.48k
    {
1469
7.48k
      if (bfd_get_error () != bfd_error_system_call)
1470
7.48k
  bfd_set_error (bfd_error_wrong_format);
1471
7.48k
      return NULL;
1472
7.48k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
107k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
31.3k
    {
1486
31.3k
      bfd_set_error (bfd_error_wrong_format);
1487
31.3k
      return NULL;
1488
31.3k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
68.8k
    {
1513
68.8k
      bfd_set_error (bfd_error_wrong_format);
1514
68.8k
      return NULL;
1515
68.8k
    }
1516
1517
5.20k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
5.20k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
5.20k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
5.20k
  if (opt_hdr_size != 0)
1524
2.52k
    {
1525
2.52k
      bfd_size_type amt = opt_hdr_size;
1526
2.52k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
2.52k
      if (amt < sizeof (PEAOUTHDR))
1530
2.51k
  amt = sizeof (PEAOUTHDR);
1531
1532
2.52k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
2.52k
      if (opthdr == NULL)
1534
6
  return NULL;
1535
2.52k
      if (amt > opt_hdr_size)
1536
2.51k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
2.52k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
2.52k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
2.52k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
2.52k
    || a->SectionAlignment >= 0x80000000)
1558
500
  {
1559
500
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
500
        abfd);
1561
500
    a->SectionAlignment &= -a->SectionAlignment;
1562
500
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
500
  }
1565
1566
2.52k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
2.52k
    || a->FileAlignment > a->SectionAlignment)
1568
1.46k
  {
1569
1.46k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
1.46k
            abfd);
1571
1.46k
    a->FileAlignment &= -a->FileAlignment;
1572
1.46k
    if (a->FileAlignment > a->SectionAlignment)
1573
968
      a->FileAlignment = a->SectionAlignment;
1574
1.46k
  }
1575
1576
2.52k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
586
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
2.52k
    }
1579
1580
5.20k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
5.20k
             (opt_hdr_size != 0
1582
5.20k
        ? &internal_a
1583
5.20k
        : (struct internal_aouthdr *) NULL));
1584
1585
5.20k
  if (result)
1586
760
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
760
      pe_bfd_read_buildid(abfd);
1589
760
    }
1590
1591
5.20k
  return result;
1592
5.20k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1440
115k
{
1441
115k
  bfd_byte buffer[6];
1442
115k
  struct external_DOS_hdr dos_hdr;
1443
115k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
115k
  struct internal_filehdr internal_f;
1445
115k
  struct internal_aouthdr internal_a;
1446
115k
  bfd_size_type opt_hdr_size;
1447
115k
  file_ptr offset;
1448
115k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
115k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
115k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
798
    {
1455
798
      if (bfd_get_error () != bfd_error_system_call)
1456
566
  bfd_set_error (bfd_error_wrong_format);
1457
798
      return NULL;
1458
798
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
115k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
115k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
220
    return pe_ILF_object_p (abfd);
1464
1465
114k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
114k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
114k
   != sizeof (dos_hdr))
1468
7.48k
    {
1469
7.48k
      if (bfd_get_error () != bfd_error_system_call)
1470
7.48k
  bfd_set_error (bfd_error_wrong_format);
1471
7.48k
      return NULL;
1472
7.48k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
107k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
31.3k
    {
1486
31.3k
      bfd_set_error (bfd_error_wrong_format);
1487
31.3k
      return NULL;
1488
31.3k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
73.5k
    {
1513
73.5k
      bfd_set_error (bfd_error_wrong_format);
1514
73.5k
      return NULL;
1515
73.5k
    }
1516
1517
532
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
532
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
532
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
532
  if (opt_hdr_size != 0)
1524
228
    {
1525
228
      bfd_size_type amt = opt_hdr_size;
1526
228
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
228
      if (amt < sizeof (PEAOUTHDR))
1530
14
  amt = sizeof (PEAOUTHDR);
1531
1532
228
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
228
      if (opthdr == NULL)
1534
4
  return NULL;
1535
224
      if (amt > opt_hdr_size)
1536
12
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
224
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
224
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
224
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
224
    || a->SectionAlignment >= 0x80000000)
1558
186
  {
1559
186
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
186
        abfd);
1561
186
    a->SectionAlignment &= -a->SectionAlignment;
1562
186
    if (a->SectionAlignment >= 0x80000000)
1563
6
      a->SectionAlignment = 0x40000000;
1564
186
  }
1565
1566
224
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
224
    || a->FileAlignment > a->SectionAlignment)
1568
202
  {
1569
202
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
202
            abfd);
1571
202
    a->FileAlignment &= -a->FileAlignment;
1572
202
    if (a->FileAlignment > a->SectionAlignment)
1573
78
      a->FileAlignment = a->SectionAlignment;
1574
202
  }
1575
1576
224
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
158
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
224
    }
1579
1580
528
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
528
             (opt_hdr_size != 0
1582
528
        ? &internal_a
1583
528
        : (struct internal_aouthdr *) NULL));
1584
1585
528
  if (result)
1586
374
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
374
      pe_bfd_read_buildid(abfd);
1589
374
    }
1590
1591
528
  return result;
1592
532
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1440
115k
{
1441
115k
  bfd_byte buffer[6];
1442
115k
  struct external_DOS_hdr dos_hdr;
1443
115k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
115k
  struct internal_filehdr internal_f;
1445
115k
  struct internal_aouthdr internal_a;
1446
115k
  bfd_size_type opt_hdr_size;
1447
115k
  file_ptr offset;
1448
115k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
115k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
115k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
798
    {
1455
798
      if (bfd_get_error () != bfd_error_system_call)
1456
566
  bfd_set_error (bfd_error_wrong_format);
1457
798
      return NULL;
1458
798
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
115k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
115k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
220
    return pe_ILF_object_p (abfd);
1464
1465
114k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
114k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
114k
   != sizeof (dos_hdr))
1468
7.48k
    {
1469
7.48k
      if (bfd_get_error () != bfd_error_system_call)
1470
7.48k
  bfd_set_error (bfd_error_wrong_format);
1471
7.48k
      return NULL;
1472
7.48k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
107k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
31.3k
    {
1486
31.3k
      bfd_set_error (bfd_error_wrong_format);
1487
31.3k
      return NULL;
1488
31.3k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
67.8k
    {
1513
67.8k
      bfd_set_error (bfd_error_wrong_format);
1514
67.8k
      return NULL;
1515
67.8k
    }
1516
1517
6.12k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
6.12k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
6.12k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
6.12k
  if (opt_hdr_size != 0)
1524
5.39k
    {
1525
5.39k
      bfd_size_type amt = opt_hdr_size;
1526
5.39k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
5.39k
      if (amt < sizeof (PEAOUTHDR))
1530
4.37k
  amt = sizeof (PEAOUTHDR);
1531
1532
5.39k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
5.39k
      if (opthdr == NULL)
1534
8
  return NULL;
1535
5.38k
      if (amt > opt_hdr_size)
1536
4.37k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
5.38k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
5.38k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
5.38k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
5.38k
    || a->SectionAlignment >= 0x80000000)
1558
4.39k
  {
1559
4.39k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
4.39k
        abfd);
1561
4.39k
    a->SectionAlignment &= -a->SectionAlignment;
1562
4.39k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
4.39k
  }
1565
1566
5.38k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
5.38k
    || a->FileAlignment > a->SectionAlignment)
1568
2.00k
  {
1569
2.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
2.00k
            abfd);
1571
2.00k
    a->FileAlignment &= -a->FileAlignment;
1572
2.00k
    if (a->FileAlignment > a->SectionAlignment)
1573
1.02k
      a->FileAlignment = a->SectionAlignment;
1574
2.00k
  }
1575
1576
5.38k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
4.83k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
5.38k
    }
1579
1580
6.11k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
6.11k
             (opt_hdr_size != 0
1582
6.11k
        ? &internal_a
1583
6.11k
        : (struct internal_aouthdr *) NULL));
1584
1585
6.11k
  if (result)
1586
3.53k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
3.53k
      pe_bfd_read_buildid(abfd);
1589
3.53k
    }
1590
1591
6.11k
  return result;
1592
6.12k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1440
71.9k
{
1441
71.9k
  bfd_byte buffer[6];
1442
71.9k
  struct external_DOS_hdr dos_hdr;
1443
71.9k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
71.9k
  struct internal_filehdr internal_f;
1445
71.9k
  struct internal_aouthdr internal_a;
1446
71.9k
  bfd_size_type opt_hdr_size;
1447
71.9k
  file_ptr offset;
1448
71.9k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
71.9k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
71.9k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
0
    {
1455
0
      if (bfd_get_error () != bfd_error_system_call)
1456
0
  bfd_set_error (bfd_error_wrong_format);
1457
0
      return NULL;
1458
0
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
71.9k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
71.9k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
0
    return pe_ILF_object_p (abfd);
1464
1465
71.9k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
71.9k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
71.9k
   != sizeof (dos_hdr))
1468
0
    {
1469
0
      if (bfd_get_error () != bfd_error_system_call)
1470
0
  bfd_set_error (bfd_error_wrong_format);
1471
0
      return NULL;
1472
0
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
71.9k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
0
    {
1486
0
      bfd_set_error (bfd_error_wrong_format);
1487
0
      return NULL;
1488
0
    }
1489
1490
71.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
71.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
71.9k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
71.9k
    != sizeof (image_hdr)))
1494
0
    {
1495
0
      if (bfd_get_error () != bfd_error_system_call)
1496
0
  bfd_set_error (bfd_error_wrong_format);
1497
0
      return NULL;
1498
0
    }
1499
1500
71.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
0
    {
1502
0
      bfd_set_error (bfd_error_wrong_format);
1503
0
      return NULL;
1504
0
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
71.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
71.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
71.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
55.7k
    {
1513
55.7k
      bfd_set_error (bfd_error_wrong_format);
1514
55.7k
      return NULL;
1515
55.7k
    }
1516
1517
16.2k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
16.2k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
16.2k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
16.2k
  if (opt_hdr_size != 0)
1524
14.0k
    {
1525
14.0k
      bfd_size_type amt = opt_hdr_size;
1526
14.0k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
14.0k
      if (amt < sizeof (PEAOUTHDR))
1530
13.5k
  amt = sizeof (PEAOUTHDR);
1531
1532
14.0k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
14.0k
      if (opthdr == NULL)
1534
486
  return NULL;
1535
13.5k
      if (amt > opt_hdr_size)
1536
13.0k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
13.5k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
13.5k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
13.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
13.5k
    || a->SectionAlignment >= 0x80000000)
1558
6.76k
  {
1559
6.76k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
6.76k
        abfd);
1561
6.76k
    a->SectionAlignment &= -a->SectionAlignment;
1562
6.76k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
6.76k
  }
1565
1566
13.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
13.5k
    || a->FileAlignment > a->SectionAlignment)
1568
7.71k
  {
1569
7.71k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
7.71k
            abfd);
1571
7.71k
    a->FileAlignment &= -a->FileAlignment;
1572
7.71k
    if (a->FileAlignment > a->SectionAlignment)
1573
2.89k
      a->FileAlignment = a->SectionAlignment;
1574
7.71k
  }
1575
1576
13.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
11.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
13.5k
    }
1579
1580
15.7k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
15.7k
             (opt_hdr_size != 0
1582
15.7k
        ? &internal_a
1583
15.7k
        : (struct internal_aouthdr *) NULL));
1584
1585
15.7k
  if (result)
1586
5.08k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
5.08k
      pe_bfd_read_buildid(abfd);
1589
5.08k
    }
1590
1591
15.7k
  return result;
1592
16.2k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1440
115k
{
1441
115k
  bfd_byte buffer[6];
1442
115k
  struct external_DOS_hdr dos_hdr;
1443
115k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
115k
  struct internal_filehdr internal_f;
1445
115k
  struct internal_aouthdr internal_a;
1446
115k
  bfd_size_type opt_hdr_size;
1447
115k
  file_ptr offset;
1448
115k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
115k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
115k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
798
    {
1455
798
      if (bfd_get_error () != bfd_error_system_call)
1456
566
  bfd_set_error (bfd_error_wrong_format);
1457
798
      return NULL;
1458
798
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
115k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
115k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
220
    return pe_ILF_object_p (abfd);
1464
1465
114k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
114k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
114k
   != sizeof (dos_hdr))
1468
7.48k
    {
1469
7.48k
      if (bfd_get_error () != bfd_error_system_call)
1470
7.48k
  bfd_set_error (bfd_error_wrong_format);
1471
7.48k
      return NULL;
1472
7.48k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
107k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
31.3k
    {
1486
31.3k
      bfd_set_error (bfd_error_wrong_format);
1487
31.3k
      return NULL;
1488
31.3k
    }
1489
1490
75.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
75.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
75.9k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
75.9k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
74.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
73.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
73.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
73.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
73.6k
    {
1513
73.6k
      bfd_set_error (bfd_error_wrong_format);
1514
73.6k
      return NULL;
1515
73.6k
    }
1516
1517
380
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
380
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
380
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
380
  if (opt_hdr_size != 0)
1524
164
    {
1525
164
      bfd_size_type amt = opt_hdr_size;
1526
164
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
164
      if (amt < sizeof (PEAOUTHDR))
1530
58
  amt = sizeof (PEAOUTHDR);
1531
1532
164
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
164
      if (opthdr == NULL)
1534
6
  return NULL;
1535
158
      if (amt > opt_hdr_size)
1536
56
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
158
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
158
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
158
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
158
    || a->SectionAlignment >= 0x80000000)
1558
112
  {
1559
112
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
112
        abfd);
1561
112
    a->SectionAlignment &= -a->SectionAlignment;
1562
112
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
112
  }
1565
1566
158
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
158
    || a->FileAlignment > a->SectionAlignment)
1568
92
  {
1569
92
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
92
            abfd);
1571
92
    a->FileAlignment &= -a->FileAlignment;
1572
92
    if (a->FileAlignment > a->SectionAlignment)
1573
30
      a->FileAlignment = a->SectionAlignment;
1574
92
  }
1575
1576
158
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
98
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
158
    }
1579
1580
374
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
374
             (opt_hdr_size != 0
1582
374
        ? &internal_a
1583
374
        : (struct internal_aouthdr *) NULL));
1584
1585
374
  if (result)
1586
180
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
180
      pe_bfd_read_buildid(abfd);
1589
180
    }
1590
1591
374
  return result;
1592
380
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1440
231k
{
1441
231k
  bfd_byte buffer[6];
1442
231k
  struct external_DOS_hdr dos_hdr;
1443
231k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
231k
  struct internal_filehdr internal_f;
1445
231k
  struct internal_aouthdr internal_a;
1446
231k
  bfd_size_type opt_hdr_size;
1447
231k
  file_ptr offset;
1448
231k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
231k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
231k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.59k
    {
1455
1.59k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.13k
  bfd_set_error (bfd_error_wrong_format);
1457
1.59k
      return NULL;
1458
1.59k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
230k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
230k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
248
    return pe_ILF_object_p (abfd);
1464
1465
229k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
229k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
229k
   != sizeof (dos_hdr))
1468
15.1k
    {
1469
15.1k
      if (bfd_get_error () != bfd_error_system_call)
1470
15.1k
  bfd_set_error (bfd_error_wrong_format);
1471
15.1k
      return NULL;
1472
15.1k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
214k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
138k
    {
1486
138k
      bfd_set_error (bfd_error_wrong_format);
1487
138k
      return NULL;
1488
138k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
53.8k
    {
1513
53.8k
      bfd_set_error (bfd_error_wrong_format);
1514
53.8k
      return NULL;
1515
53.8k
    }
1516
1517
20.1k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
20.1k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
20.1k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
20.1k
  if (opt_hdr_size != 0)
1524
17.1k
    {
1525
17.1k
      bfd_size_type amt = opt_hdr_size;
1526
17.1k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
17.1k
      if (amt < sizeof (PEAOUTHDR))
1530
1.69k
  amt = sizeof (PEAOUTHDR);
1531
1532
17.1k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
17.1k
      if (opthdr == NULL)
1534
486
  return NULL;
1535
16.6k
      if (amt > opt_hdr_size)
1536
1.68k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
16.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
16.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
16.6k
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
16.6k
#ifdef WINCE
1546
16.6k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
8.36k
  {
1551
8.36k
    bfd_set_error (bfd_error_wrong_format);
1552
8.36k
    return NULL;
1553
8.36k
  }
1554
8.25k
#endif
1555
1556
8.25k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
8.25k
    || a->SectionAlignment >= 0x80000000)
1558
7.26k
  {
1559
7.26k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
7.26k
        abfd);
1561
7.26k
    a->SectionAlignment &= -a->SectionAlignment;
1562
7.26k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
7.26k
  }
1565
1566
8.25k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
8.25k
    || a->FileAlignment > a->SectionAlignment)
1568
3.91k
  {
1569
3.91k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
3.91k
            abfd);
1571
3.91k
    a->FileAlignment &= -a->FileAlignment;
1572
3.91k
    if (a->FileAlignment > a->SectionAlignment)
1573
1.46k
      a->FileAlignment = a->SectionAlignment;
1574
3.91k
  }
1575
1576
8.25k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
5.80k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
8.25k
    }
1579
1580
11.3k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
11.3k
             (opt_hdr_size != 0
1582
11.3k
        ? &internal_a
1583
11.3k
        : (struct internal_aouthdr *) NULL));
1584
1585
11.3k
  if (result)
1586
3.01k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
3.01k
      pe_bfd_read_buildid(abfd);
1589
3.01k
    }
1590
1591
11.3k
  return result;
1592
20.1k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1440
231k
{
1441
231k
  bfd_byte buffer[6];
1442
231k
  struct external_DOS_hdr dos_hdr;
1443
231k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
231k
  struct internal_filehdr internal_f;
1445
231k
  struct internal_aouthdr internal_a;
1446
231k
  bfd_size_type opt_hdr_size;
1447
231k
  file_ptr offset;
1448
231k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
231k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
231k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.59k
    {
1455
1.59k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.13k
  bfd_set_error (bfd_error_wrong_format);
1457
1.59k
      return NULL;
1458
1.59k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
230k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
230k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
248
    return pe_ILF_object_p (abfd);
1464
1465
229k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
229k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
229k
   != sizeof (dos_hdr))
1468
15.1k
    {
1469
15.1k
      if (bfd_get_error () != bfd_error_system_call)
1470
15.1k
  bfd_set_error (bfd_error_wrong_format);
1471
15.1k
      return NULL;
1472
15.1k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
214k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
138k
    {
1486
138k
      bfd_set_error (bfd_error_wrong_format);
1487
138k
      return NULL;
1488
138k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
53.8k
    {
1513
53.8k
      bfd_set_error (bfd_error_wrong_format);
1514
53.8k
      return NULL;
1515
53.8k
    }
1516
1517
20.1k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
20.1k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
20.1k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
20.1k
  if (opt_hdr_size != 0)
1524
17.1k
    {
1525
17.1k
      bfd_size_type amt = opt_hdr_size;
1526
17.1k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
17.1k
      if (amt < sizeof (PEAOUTHDR))
1530
1.69k
  amt = sizeof (PEAOUTHDR);
1531
1532
17.1k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
17.1k
      if (opthdr == NULL)
1534
486
  return NULL;
1535
16.6k
      if (amt > opt_hdr_size)
1536
1.69k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
16.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
16.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
16.6k
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
16.6k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
8.23k
#endif
1550
8.23k
  {
1551
8.23k
    bfd_set_error (bfd_error_wrong_format);
1552
8.23k
    return NULL;
1553
8.23k
  }
1554
8.38k
#endif
1555
1556
8.38k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
8.38k
    || a->SectionAlignment >= 0x80000000)
1558
5.84k
  {
1559
5.84k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
5.84k
        abfd);
1561
5.84k
    a->SectionAlignment &= -a->SectionAlignment;
1562
5.84k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
5.84k
  }
1565
1566
8.38k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
8.38k
    || a->FileAlignment > a->SectionAlignment)
1568
2.97k
  {
1569
2.97k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
2.97k
            abfd);
1571
2.97k
    a->FileAlignment &= -a->FileAlignment;
1572
2.97k
    if (a->FileAlignment > a->SectionAlignment)
1573
1.46k
      a->FileAlignment = a->SectionAlignment;
1574
2.97k
  }
1575
1576
8.38k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
4.84k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
8.38k
    }
1579
1580
11.4k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
11.4k
             (opt_hdr_size != 0
1582
11.4k
        ? &internal_a
1583
11.4k
        : (struct internal_aouthdr *) NULL));
1584
1585
11.4k
  if (result)
1586
4.02k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
4.02k
      pe_bfd_read_buildid(abfd);
1589
4.02k
    }
1590
1591
11.4k
  return result;
1592
20.1k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1440
231k
{
1441
231k
  bfd_byte buffer[6];
1442
231k
  struct external_DOS_hdr dos_hdr;
1443
231k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
231k
  struct internal_filehdr internal_f;
1445
231k
  struct internal_aouthdr internal_a;
1446
231k
  bfd_size_type opt_hdr_size;
1447
231k
  file_ptr offset;
1448
231k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
231k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
231k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.59k
    {
1455
1.59k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.13k
  bfd_set_error (bfd_error_wrong_format);
1457
1.59k
      return NULL;
1458
1.59k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
230k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
230k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
248
    return pe_ILF_object_p (abfd);
1464
1465
229k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
229k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
229k
   != sizeof (dos_hdr))
1468
15.1k
    {
1469
15.1k
      if (bfd_get_error () != bfd_error_system_call)
1470
15.1k
  bfd_set_error (bfd_error_wrong_format);
1471
15.1k
      return NULL;
1472
15.1k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
214k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
138k
    {
1486
138k
      bfd_set_error (bfd_error_wrong_format);
1487
138k
      return NULL;
1488
138k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
62.1k
    {
1513
62.1k
      bfd_set_error (bfd_error_wrong_format);
1514
62.1k
      return NULL;
1515
62.1k
    }
1516
1517
11.8k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
11.8k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
11.8k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
11.8k
  if (opt_hdr_size != 0)
1524
10.2k
    {
1525
10.2k
      bfd_size_type amt = opt_hdr_size;
1526
10.2k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
10.2k
      if (amt < sizeof (PEAOUTHDR))
1530
1.04k
  amt = sizeof (PEAOUTHDR);
1531
1532
10.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
10.2k
      if (opthdr == NULL)
1534
964
  return NULL;
1535
9.24k
      if (amt > opt_hdr_size)
1536
562
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
9.24k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
9.24k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
9.24k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
9.24k
    || a->SectionAlignment >= 0x80000000)
1558
3.39k
  {
1559
3.39k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
3.39k
        abfd);
1561
3.39k
    a->SectionAlignment &= -a->SectionAlignment;
1562
3.39k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
3.39k
  }
1565
1566
9.24k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
9.24k
    || a->FileAlignment > a->SectionAlignment)
1568
5.32k
  {
1569
5.32k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
5.32k
            abfd);
1571
5.32k
    a->FileAlignment &= -a->FileAlignment;
1572
5.32k
    if (a->FileAlignment > a->SectionAlignment)
1573
990
      a->FileAlignment = a->SectionAlignment;
1574
5.32k
  }
1575
1576
9.24k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
8.67k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
9.24k
    }
1579
1580
10.8k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
10.8k
             (opt_hdr_size != 0
1582
10.8k
        ? &internal_a
1583
10.8k
        : (struct internal_aouthdr *) NULL));
1584
1585
10.8k
  if (result)
1586
3.02k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
3.02k
      pe_bfd_read_buildid(abfd);
1589
3.02k
    }
1590
1591
10.8k
  return result;
1592
11.8k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1440
115k
{
1441
115k
  bfd_byte buffer[6];
1442
115k
  struct external_DOS_hdr dos_hdr;
1443
115k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
115k
  struct internal_filehdr internal_f;
1445
115k
  struct internal_aouthdr internal_a;
1446
115k
  bfd_size_type opt_hdr_size;
1447
115k
  file_ptr offset;
1448
115k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
115k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
115k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
798
    {
1455
798
      if (bfd_get_error () != bfd_error_system_call)
1456
566
  bfd_set_error (bfd_error_wrong_format);
1457
798
      return NULL;
1458
798
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
115k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
115k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
220
    return pe_ILF_object_p (abfd);
1464
1465
114k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
114k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
114k
   != sizeof (dos_hdr))
1468
7.48k
    {
1469
7.48k
      if (bfd_get_error () != bfd_error_system_call)
1470
7.48k
  bfd_set_error (bfd_error_wrong_format);
1471
7.48k
      return NULL;
1472
7.48k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
107k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
31.3k
    {
1486
31.3k
      bfd_set_error (bfd_error_wrong_format);
1487
31.3k
      return NULL;
1488
31.3k
    }
1489
1490
76.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
76.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
76.0k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
76.0k
    != sizeof (image_hdr)))
1494
988
    {
1495
988
      if (bfd_get_error () != bfd_error_system_call)
1496
988
  bfd_set_error (bfd_error_wrong_format);
1497
988
      return NULL;
1498
988
    }
1499
1500
75.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
1.01k
    {
1502
1.01k
      bfd_set_error (bfd_error_wrong_format);
1503
1.01k
      return NULL;
1504
1.01k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
74.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
74.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
74.0k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
63.1k
    {
1513
63.1k
      bfd_set_error (bfd_error_wrong_format);
1514
63.1k
      return NULL;
1515
63.1k
    }
1516
1517
10.8k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
10.8k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
10.8k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
10.8k
  if (opt_hdr_size != 0)
1524
9.19k
    {
1525
9.19k
      bfd_size_type amt = opt_hdr_size;
1526
9.19k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
9.19k
      if (amt < sizeof (PEAOUTHDR))
1530
1.96k
  amt = sizeof (PEAOUTHDR);
1531
1532
9.19k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
9.19k
      if (opthdr == NULL)
1534
486
  return NULL;
1535
8.71k
      if (amt > opt_hdr_size)
1536
1.96k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
8.71k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
8.71k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
8.71k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
8.71k
    || a->SectionAlignment >= 0x80000000)
1558
1.46k
  {
1559
1.46k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
1.46k
        abfd);
1561
1.46k
    a->SectionAlignment &= -a->SectionAlignment;
1562
1.46k
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
1.46k
  }
1565
1566
8.71k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
8.71k
    || a->FileAlignment > a->SectionAlignment)
1568
4.81k
  {
1569
4.81k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
4.81k
            abfd);
1571
4.81k
    a->FileAlignment &= -a->FileAlignment;
1572
4.81k
    if (a->FileAlignment > a->SectionAlignment)
1573
3.84k
      a->FileAlignment = a->SectionAlignment;
1574
4.81k
  }
1575
1576
8.71k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
5.78k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
8.71k
    }
1579
1580
10.3k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
10.3k
             (opt_hdr_size != 0
1582
10.3k
        ? &internal_a
1583
10.3k
        : (struct internal_aouthdr *) NULL));
1584
1585
10.3k
  if (result)
1586
4.48k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
4.48k
      pe_bfd_read_buildid(abfd);
1589
4.48k
    }
1590
1591
10.3k
  return result;
1592
10.8k
}
1593
1594
71.9k
#define coff_object_p pe_bfd_object_p
1595
#endif /* COFF_IMAGE_WITH_PE */