Coverage Report

Created: 2023-08-28 06:23

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